Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need to be answered correctly. You must: Comment and Format and Must make sure about indenting. If you don't follow these steps, it will be

Need to be answered correctly. You must: Comment and Format and Must make sure about indenting. If you don't follow these steps, it will be flagged for review. MUST BE IN JAVA FORMAT. IT IS A MUST. Please also check the output very carefully. Must not provide the answer on a page. Use the Java compiler. Please provide the code in such a way so that it can be copied and checked in the Java compiler. Must provide the coding as (.......).java and (........)Demo.java (Public class must be based on the question for both MotorBoat.java and MotorBoatDemo.java ) DON'T FORGET ABOUT COMMENTING AND FOLLOW EXACTLY WHAT HAS BEEN ASKED IN THE QUESTION. The output must match with the output provided.

image text in transcribed

image text in transcribed

Need to be answered correctly. You must: Comment and Format and Must make sure about indenting. If you don't follow these steps, it will be flagged for review. MUST BE IN JAVA FORMAT. IT IS A MUST. Please also check the output very carefully. Must not provide the answer on a page. Use the Java compiler. Please provide the code in such a way so that it can be copied and checked in the Java compiler. Must provide the coding as (.......).java and (........)Demo.java (Public class must be based on the question for both MotorBoat.java and MotorBoatDemo.java ) DON'T FORGET ABOUT COMMENTING AND FOLLOW EXACTLY WHAT HAS BEEN ASKED IN THE QUESTION. The output must match with the output provided.

Exercise 2: You want to simulate different MotorBoats. Write a class MotorBoat that represents motorboats. A MotorBoat has the following private attributes: . The name of the MotorBoat (String) . The capacity of the fuel tank (liters) . The current amount of fuel in the tank (liters) . The maximum speed of the boat (kmph) . The current speed of the boat (kmph) . The rate of fuel consumption (liters/km) . The distance traveled (km) and the following methods Constructor that sets the name, capacity, fuel in the tank, max speed and fuel consumption to the given values and current speed to zero Get and set methods . Method called changeSpeed to change the speed of the boat (the method should accept the change which is a positive or negative number and change the current speed. If the change is greater than its max speed, it should set the current speed to max speed) Method called cruise that will operate the boat for an amount of time in minutes at the current speed (this method should set the distance traveled and reduce the amount of fuel in the tank by the appropriate amount). . . . Method called increaseFuel that will refuel the boat with some amount of fuel (if the total amount of fuel is greater than the capacity, set it to the capacity). Method called fasterBoat which will compare this MotorBoat with another MotorBoat and return true if this MotorBoat has a higher max speed. Method called equals which will compare this MotorBoat with another MotorBoat to see if it the same type of boat in terms of its max speed, capacity of fuel tank, and the rate of fuel consumption. If these attributes are the same, then the method will return true . . . A taString method that prints out the attributes of the motorboat: name, current speed, distance traveled so far and the amount of fuel left in the tank. Note: If the rate of fuel consumption is r and the distance traveled is d, then the amount of fuel remaining in the tank- fuel in tank-r*d Write a tester program that creates two motorboat objects and test them using various methods. For example here is one test case: create a motorboat named Speedy with capacity 100 liters, fuel in tank 50 liters, max. speed 100 kmph, rate of fuel consumption 1. Set its speed to 25 kmph and operate it for 30 minutes. Print the boat's current speed, distance driven and the fuel remaining in the tank (toString). Then increase the speed by 25, and operate it for 30 minutes. Print the boat. Then create another motorboat called Flippy with capacity 90 liters, fuel in tank 45 liters, max speed of 120 kmph, rate of feul consumption .75. Set speed to 45kmph and operate it for 20 minutes. Print the boat. Refuel with 50 liters, increase speed by 15 kmph and operate for 30 minutes. Print the boat. Exercise 2: You want to simulate different MotorBoats. Write a class MotorBoat that represents motorboats. A MotorBoat has the following private attributes: . The name of the MotorBoat (String) . The capacity of the fuel tank (liters) . The current amount of fuel in the tank (liters) . The maximum speed of the boat (kmph) . The current speed of the boat (kmph) . The rate of fuel consumption (liters/km) . The distance traveled (km) and the following methods Constructor that sets the name, capacity, fuel in the tank, max speed and fuel consumption to the given values and current speed to zero Get and set methods . Method called changeSpeed to change the speed of the boat (the method should accept the change which is a positive or negative number and change the current speed. If the change is greater than its max speed, it should set the current speed to max speed) Method called cruise that will operate the boat for an amount of time in minutes at the current speed (this method should set the distance traveled and reduce the amount of fuel in the tank by the appropriate amount). . . . Method called increaseFuel that will refuel the boat with some amount of fuel (if the total amount of fuel is greater than the capacity, set it to the capacity). Method called fasterBoat which will compare this MotorBoat with another MotorBoat and return true if this MotorBoat has a higher max speed. Method called equals which will compare this MotorBoat with another MotorBoat to see if it the same type of boat in terms of its max speed, capacity of fuel tank, and the rate of fuel consumption. If these attributes are the same, then the method will return true . . . A taString method that prints out the attributes of the motorboat: name, current speed, distance traveled so far and the amount of fuel left in the tank. Note: If the rate of fuel consumption is r and the distance traveled is d, then the amount of fuel remaining in the tank- fuel in tank-r*d Write a tester program that creates two motorboat objects and test them using various methods. For example here is one test case: create a motorboat named Speedy with capacity 100 liters, fuel in tank 50 liters, max. speed 100 kmph, rate of fuel consumption 1. Set its speed to 25 kmph and operate it for 30 minutes. Print the boat's current speed, distance driven and the fuel remaining in the tank (toString). Then increase the speed by 25, and operate it for 30 minutes. Print the boat. Then create another motorboat called Flippy with capacity 90 liters, fuel in tank 45 liters, max speed of 120 kmph, rate of feul consumption .75. Set speed to 45kmph and operate it for 20 minutes. Print the boat. Refuel with 50 liters, increase speed by 15 kmph and operate for 30 minutes. Print the boat

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Essentials of Database Management

Authors: Jeffrey A. Hoffer, Heikki Topi, Ramesh Venkataraman

1st edition

133405680, 9780133547702 , 978-0133405682

More Books

Students also viewed these Databases questions