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 (.......).java and (........)Demo.java )

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 (.......).java and (........)Demo.java ) DON'T FORGET ABOUT COMMENTING AND FOLLOW EXACTLY WHAT HAS BEEN ASKED IN THE QUESTION.

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

Modern Datalog Engines In Databases

Authors: Bas Ketsman ,Paraschos Koutris

1st Edition

1638280428, 978-1638280422

More Books

Students also viewed these Databases questions

Question

slope of a perpndicular line through (4,-4), parallel to y=3

Answered: 1 week ago