In Python For problems A, B, and C you will be writing two different classes to simulate a Boat race. Problem A is to write the first class Boat. A Boat object must hold the following information boat_name: string top_speed: int current_progress: int Write a constructor that allows the programmer to create an object of type Boat with the arguments boat_name and top_speed.   The boat_name should be set to the value of the corresponding argument - this argument is required. The top_speed should default to the value 3 if no value is passed in for the argument. The value for current_progress should always be set to 0. Implement Boat class with setter and getter methods: Provide setters for the following instance variables: set_top_speed takes in an int and updates the top_speed set_boat_name takes in a string and updates the boat_name set_current_progress takes in a int and updates the current_progress Provide getters for the following instance variables with no input parameters passed in: get_boat_name returns the boat_name get_top_speed returns the top_speed get_current_progress returns the current_progress Overload the __str__ method so that it returns a string containing the boat_name and current_progress.  The string should look like the following example.  Please note there is only 1 space after the colon. Whirlwind: 0 A method named move which takes no arguments (other than self) and returns an int. The move method should select a random integer between 0 and top_speed (inclusive on both sides), then increment current_progress by that random value, and finally return that random value.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

In Python

For problems A, B, and C you will be writing two different classes to simulate a Boat race. Problem A is to write the first class Boat. A Boat object must hold the following information

  1. boat_name: string
  2. top_speed: int
  3. current_progress: int
  • Write a constructor that allows the programmer to create an object of type Boat with the arguments boat_name and top_speed.  
    • The boat_name should be set to the value of the corresponding argument - this argument is required.
    • The top_speed should default to the value 3 if no value is passed in for the argument.
    • The value for current_progress should always be set to 0.
  • Implement Boat class with setter and getter methods:
  • Provide setters for the following instance variables:
    • set_top_speed takes in an int and updates the top_speed
    • set_boat_name takes in a string and updates the boat_name
    • set_current_progress takes in a int and updates the current_progress
  • Provide getters for the following instance variables with no input parameters passed in:
    • get_boat_name returns the boat_name
    • get_top_speed returns the top_speed
    • get_current_progress returns the current_progress
  • Overload the __str__ method so that it returns a string containing the boat_name and current_progress.  The string should look like the following example.  Please note there is only 1 space after the colon.

Whirlwind: 0

  • A method named move which takes no arguments (other than self) and returns an int. The move method should select a random integer between 0 and top_speed (inclusive on both sides), then increment current_progress by that random value, and finally return that random value. 

Examples:

Copy the following if __name__ == "__main__" block into your hw11.py file, and comment out tests for parts of the class you haven’t implemented yet.  The lines that have output include the expected value next to them as a comment (note that some lines are random and your output will not match exactly).

 

if __name__ == '__main__':

    my_boat = Boat("The Fire Ball", 12)

    other_boat = Boat("The Leaf", 100)

    print(type(my_boat)) #<class '__main__.Boat'>

    print(str(my_boat)) #The Fire Ball: 0

    print(my_boat.get_boat_name()) #The Fire Ball

    print(my_boat.get_top_speed()) #12

    print(my_boat.get_current_progress()) #0

    print(my_boat.move()) #Some number between 0 and 12

    print(my_boat.get_current_progress()) #Same num as prev line

    print(my_boat.move()) #Another number between 0 and 12

    print(my_boat.get_current_progress()) #Sum of prev 2 lines

    my_boat.set_top_speed(100)

    my_boat.set_boat_name("The Sam")

    my_boat.set_current_progress(1000)

    print(my_boat) #The Sam: 1000

    print(my_boat.get_current_progress()) #1000

    for i in range(9980):

        my_boat.move()

    print(my_boat.get_current_progress()) #Should be about 500000

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Data members
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-engineering and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY