Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

This java PoD expands on Mondays Car class to include two new methods: speedUp and slowDown. speedUp (int) is a void method that increases the

This java PoD expands on Mondays Car class to include two new methods: speedUp and slowDown. speedUp (int) is a void method that increases the currentSpeed by the passed in integer but cant go more than its topSpeed. If speedUp goes more than the topSpeed, set currentSpeed to topSpeed. slowDown(int) is a void method that decreases the currentSpeed by the passed in integer. If car slowsDown less than 0, set the currentSpeed to 0.

Updated Car class:

Attributes: make (String) //one word only topSpeed (int) // how fast the car can go max speed km/hour currentSpeed(int) //how fast the car is currently going

Methods: Constructor (that sets the make, topSpeed from defined values) and sets currentSpeed to 0. Get and set methods. toString method returns the make and top speed of the car faster (Car) method that returns a boolean if this car is currently going faster than the passed in car equals (Car) method returns true (a boolean) if this car has the same make, topSpeed and currentSpeed as the passed in car object. speedUp (int) is a void method that increases the currentSpeed by the passed in integer. The currentSpeed cant go higher than its topSpeed. slowDown(int) is a void method that decreases the currentSpeed by the passed in integer. The car cant go slower than 0.

Then create a CarDemo class to create and use Car objects. Use a Scanner object to create two Car objects by reading in: The make and topSpeed for car1 and the make and topSpeed for car 2.

Print both cars. Increase car1s speed by 50 km and increase car2s speed by 70km. Print the current speed of both cars (car1 first). Print the result if car1 is going faster than car2.

Increase car1s speed by 150 km and decrease car2s speed by 10. Print the current speed of both cars (car1 first). Print the result if car1 is going faster than car2.

Details

Input

The make, model and model for 2 different cars: {make of car1} {top speed of car1} {make of car2}

Example Input: BMW 170 Audi 200

Output

Print the toString methods for both cars, followed by the speed of each car. Whether car1 is faster than car2 or not. Speed of each car after speeding up car1 (+150) and slowing down car2 (-10). Whether car1 is fasther than car2 or not.

Example Output: BMW Top Speed: 170 Audi Top Speed: 200 BMW is going 50 km\hr Audi is going 70 km\hr BMW is faster than Audi is false BMW is going 170 km\hr Audi is going 60 km\hr BMW is faster than Audi is true

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions