Question

Create the Python code for a program that will simulate a basic car radio with 3...

Create the Python code for a program that will simulate a basic car radio with 3 presets and 5 stations to

tune in.

You will create methods (class functions) for the following:

__init__ AND __str__

seekNext

longPressPreset1 through 3

shortPressPreset1 through 3

displayLCD

You will create program functions for the following:

main

displayMenuGetOption

Additional notes:

You MUST use the program template.

Your messages and prompts should look EXACTLY like those in the sample. Duplicating all blank

lines and spacing.

You can extrapolate WHAT MUST BE DONE for each method using the attached sample run.

You may use either Public or Private instance variables, but be consistent in your use.

Assume that the radio is in an “ON” state upon instantiation of your radio instance.

The five available stations are: "STATIC", "97.2", "99.6", "101.7", "105.3", "108.5" with the radio’s

initial state having all presets set to “STATIC” and the currently tuned in station as “STATIC”.

Ignore the user selection if a user types in a value that does not exist in the menu.

You do not need to document your variables for this program.

Pay attention to spelling and all other things visual -- you will be graded on this.

Staple multi-page outputs.

Use appropriate white-space and line-continuations in your source code.

Upload ONLY your Python program to Canvas in the designated area

SAMPLE RUN:

Currently Tuned: STATIC

1 = Display tuned in station

2 = Program preset station 1

3 = Program preset station 2

4 = Program preset station 3

5 = Seek next station

6 = Tune preset station 1

7 = Tune preset station 2

8 = Tune preset station 3

9 = Dump Programming

10 = Turn off radio

Enter option: 9

Preset 1: STATIC

Preset 2: STATIC

Preset 3: STATIC

Currently tuned: STATIC

1 = Display tuned in station

2 = Program preset station 1

3 = Program preset station 2

4 = Program preset station 3

5 = Seek next station

6 = Tune preset station 1

7 = Tune preset station 2

8 = Tune preset station 3

9 = Dump Programming

10 = Turn off radio

Enter option: 5

Currently Tuned: 97.2

Preset 1: 99.6

Preset 2: STATIC

Preset 3: 101.7

Currently tuned: 99.6

1 = Display tuned in station

2 = Program preset station 1

3 = Program preset station 2

4 = Program preset station 3

5 = Seek next station

6 = Tune preset station 1

7 = Tune preset station 2

8 = Tune preset station 3

9 = Dump Programming

10 = Turn off radio

Enter option: 10

Run complete. Press the Enter key to exit.

>>>

0 0
Add a comment Improve this question Transcribed image text
Answer #1


#-----------------------------------------------------------------------
# CLASS DEFINITIONS

class Radio:
  
    STATIONS = {0:"STATIC", 1:"97.2", 2:"99.6", 3:"101.7", 4:"105.3", 5:"108.5"}

    def __init__(self):
        self.preset1 = 0
        self.preset2 = 0
        self.preset3 = 0
        self.currentlyTuned = 0

    def seekNext(self):
        self.currentlyTuned += 1

    def longPressPreset1(self, key):
        self.preset1 = key

    def longPressPreset2(self, key):
        self.preset2 = key

    def longPressPreset3(self, key):
        self.preset3 = key

    def shortPressPreset1(self, key):
        self.currentlyTuned = key

    def shortPressPreset2(self, key):
        self.currentlyTuned = key

    def shortPressPreset3(self, key):
        self.currentlyTuned = key

    def displayLCD(self):
        try:
            print("Currently tuned:", Radio.STATIONS[self.currentlyTuned])

        except KeyError:
            self.currentlyTuned = 1
            print("Currently tuned:", Radio.STATIONS[self.currentlyTuned])
          
    def __str__(self):
        return "Preset 1: " + Radio.STATIONS[self.preset1] + "\nPreset 2: " \
               + Radio.STATIONS[self.preset2] + "\nPreset 3: " + Radio.STATIONS[self.preset3]
      

#-----------------------------------------------------------------------
# FUNCTION DEFINITIONS

def main():
  
    myRadio = Radio()
    myRadio.displayLCD()
    option = displayMenuGetOption()

    while option != "10":
      
        if option == "1":
            myRadio.displayLCD()
          
        elif option == "2":
            myRadio.longPressPreset1(myRadio.currentlyTuned)
          
        elif option == "3":
            myRadio.longPressPreset2(myRadio.currentlyTuned)
          
        elif option == "4":
            myRadio.longPressPreset3(myRadio.currentlyTuned)
          
        elif option == "5":
            myRadio.seekNext()
          
        elif option == "6":
            myRadio.shortPressPreset1(myRadio.currentlyTuned)
          
        elif option == "7":
            myRadio.shortPressPreset2(myRadio.currentlyTuned)
          
        elif option == "8":
            myRadio.shortPressPreset3(myRadio.currentlyTuned)
          
        elif option == "9":
            print(myRadio)
          
        else:
            myRadio.displayLCD()
            option = displayMenuGetOption()
      
        myRadio.displayLCD()
        option = displayMenuGetOption()
          
    if option == "10":
        input("Run complete. Press the Enter key to exit.")


def displayMenuGetOption():

    print("\n1 = Display tuned in station")
    print("2 = Program preset station 1")
    print("3 = Program preset station 2")
    print("4 = Program preset station 3")
    print("5 = Seek next staion")
    print("6 = Tune preset station 1")
    print("7 = Tune preset station 2")
    print("8 = Tune preset station 3")
    print("9 = Dump programming")
    print("10 = Turn off radio\n")

    selection = input("Enter option: ")
    print("")
    return selection
  
  
#-----------------------------------------------------------------------
# PROGRAM'S MAIN LOGIC
#

main()

Add a comment
Know the answer?
Add Answer to:
Create the Python code for a program that will simulate a basic car radio with 3...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Create the Python code for a program that will simulate a basic car radio with 3 presets and 5 st...

    Create the Python code for a program that will simulate a basic car radio with 3 presets and 5 stations to tune in. You will create methods (class functions) for the following: __init__ AND __str__ seekNext longPressPreset1 through 3 shortPressPreset1 through 3 displayLCD You will create program functions for the following: main displayMenuGetOption Additional notes: You MUST use the program template. Your messages and prompts should look EXACTLY like those in the sample. Duplicating all blank lines and spacing. You...

  • SOLVE IN PYTHON: Exercise #2: Design and implement class Radio to represent a radio object. The c...

    SOLVE IN PYTHON: Exercise #2: Design and implement class Radio to represent a radio object. The class defines the following attributes (variables) and methods: Assume that the station and volume settings range from 1 to 10. A private variable of type int named station to represent a station number. Set to 1. A private variable of type int named volume to represent the volume setting. Set to 1. A private variable of type boolean named on to represent the radio...

  • PYTHON Exercise #2: Design and implement class Radio to represent a radio object. The class defines...

    PYTHON Exercise #2: Design and implement class Radio to represent a radio object. The class defines the following attributes (variables) and methods: Assume that the station and volume settings range from 1 to 10. 1. A private variable of type int named station to represent a station number. Set to 1. 2. A private variable of type int named volume to represent the volume setting. Set to 1. 3. A private variable of type boolean named on to represent the...

  • ** IN JAVA **: Design and implement class Radio to represent a radio object. The class defines th...

    ** IN JAVA **: Design and implement class Radio to represent a radio object. The class defines the following attributes (variables) and methods:Assume that the station and volume settings range from 1 to 10.A private variable of type int named station to represent a station number. Set toA private variable of type int named volume to represent the volume setting. Set to 1.A private variable of type boolean named on to represent the radio on or off. Set to false.A...

  • Note: According to the question, please write source code in java only using the class method....

    Note: According to the question, please write source code in java only using the class method. Sample Run (output) should be the same as displayed in the question below. Make sure the source code is working properly and no errors.​ Exercise #2: Design and implement class Radio to represent a radio object. The class defines the following attributes (variables) and methods Assume that the station and volume settings range from 1 to 10 1. A private variable of type int...

  • Please post the code in c++! Computer Labs Write a Computer Labs program to store the...

    Please post the code in c++! Computer Labs Write a Computer Labs program to store the list of user IDs for each computer station using a linked list. Problem Description: You run four computer labs. Each lab contains computer stations that are numbered as shown in the table below: Lab Number Computer station Numbers 1-5 2 1-6 1-4 4 1-3 Each user has a unique five-digit ID number. Whenever a user logs on, the User's ID, labnumber, and the computer...

  • 3. WCS111 FM. Suppose you work at WCS111 FM, a radio station by computer scientists for...

    3. WCS111 FM. Suppose you work at WCS111 FM, a radio station by computer scientists for computer scientists. The station runs a contest where listeners win prizes based on how many hours they spend programming in Java. When a listener calls in to the radio station, the listener will state how many hours (whole number) a month he/she spends programming in Java. Based on the number of hours spent programming, display the listener prize according to the following rules: 1....

  • Write the following program in C++ You run four computer labs, Each lab contains computer stations...

    Write the following program in C++ You run four computer labs, Each lab contains computer stations that are numbered as shown in the table below: Lab Number Computer Station Numbers 1 1 - 5 2 1 - 6 3 1 - 4 4 1 - 3 Each user has a unique five-digit ID number. Whenever a user logs on, the user’s ID, lab number, and the computer station number are transmitted to your system. For example, if user 49193 logs...

  • C++ program that could be used to track, by lab, who is logged into which computer

    C++ program that could be used to track, by lab, who is logged into which computer 1. |15 points| Suppose you run four computer labs. Each lab contains computer stations that are numbered as shown in the table below Lab Number |Computer Station Numbers 1-5 2 1-4 1-3 Each user has a unique five-digit ID number. Whenever a user logs on, the user's ID, lab number, and the computer station number are transmitted to your system. For instance, if user...

  • PYTHON PROGRAMMING - CODE THE PROGRAM BASED ON THE INSTRUCTIONS AND ALGORITHM PROVIDED home / study...

    PYTHON PROGRAMMING - CODE THE PROGRAM BASED ON THE INSTRUCTIONS AND ALGORITHM PROVIDED home / study / engineering / computer science / questions and answers / python programming - code the program based on ... Your question has been answered! Rate it below. Let us know if you got a helpful answer. Question: PYTHON PROGRAMMING - CODE THE PROGRAM BASED ON THE... Bookmark PYTHON PROGRAMMING - CODE THE PROGRAM BASED ON THE INSTRUCTIONS AND ALGORITHM PROVIDED Rainfall Algorithm Declare and...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT