Question: public class Car { private String make; private int year; private int speed; private final int MINIMUN_SPEED = 0; private final int MAXIMUN_SPEED = 120;

 public class Car { private String make; private int year; privateint speed; private final int MINIMUN_SPEED = 0; private final int MAXIMUN_SPEED

public class Car {

private String make;

private int year;

private int speed;

private final int MINIMUN_SPEED = 0;

private final int MAXIMUN_SPEED = 120;

public Car(String make, int year) {

this.make = make;

this.year = year;

this.speed = 0;

}

public String getMake() {

return make;

}

public void setMake(String make) {

this.make = make;

}

public int getYear() {

return year;

}

public void setYear(int year) {

this.year = year;

}

public int getSpeed() {

return speed;

}

public void setSpeed(int speed) {

this.speed = speed;

}

public void increeseSpeed(int value) {

int _speed = speed + value;

if (_speed > MAXIMUN_SPEED) {

this.speed = MAXIMUN_SPEED;

} else {

this.speed = _speed;

}

}

public void decreaseSpeed(int value) {

int _speed = speed - value;

if (_speed

this.speed = MINIMUN_SPEED;

} else {

this.speed = _speed;

}

}

public String toString() {

return "Car: " + this.getYear() + " " + this.getMake();

}

}

-----------------------------------------------------------------------------------------------------------------------------------

import java.util.Scanner;

public class CarDemo {

public static void main(String[] args) {

Scanner input = new Scanner(System.in);

String _input = input.nextLine();

String[] elements = _input.split(" ");

String made = elements[0];

int year = Integer.parseInt(elements[1]);

int increase = Integer.parseInt(elements[2]);

int decrease = Integer.parseInt(elements[3]);

Car car = new Car(made, year);

int speed0 = car.getSpeed();

car.increeseSpeed(increase);

int speed1 = car.getSpeed();

car.decreaseSpeed(decrease);

int speed2 = car.getSpeed();

System.out.println(car.toString());

System.out.println(speed0 + " Km\\hr");

System.out.println(speed1 + " Km\\hr");

System.out.println(speed2 + " Km\\hr ");

}

}

Question This program will build off the Car class that you wrote Thursday. You can cut and paste it into this question and add to it. Implement a Car class that has the following private attributes . make (String) year (int) speed (int) and the following methods Constructor (that sets the make and year from defined values) and sets speed to . Get and set methods. toString method returns the year and make of the car increase speed (int). This method increases the speed by the integer passed in Note, the maximum speed the car can go is 120 kmlhr. The method makes sure that the added speed won't go beyond the 120 (i.e., if it is at 110 and the method is called and 20 is passed in, the method will set the speed to 120) decrease speed (int) - this will decrease the speed by the amount passed in but the lowest it can go is O equals(Car)- this method will see if this car is the same as the passed in Car object. It will compare the make, year and speed. And if all three are the same it will return true; otherwise false isFaster(Car) this method will compare the speed of this car with the passed in Car object. If this car is going faster, then it returns true; otherwise it returns false Then create a CarDemo class to create and use Car objects. The CarDemo class contains the main method. Use a Scanner object to read the attributes for the first Car object and a value to represent how much to increase its speed. Use a Scanner object to read the attributes for the second Car object and a value to represent how much to increase its speed 1. Print both car objects (using the toString method) 2. Print out if the cars are equal (note, the first car calls the method) 3. Print out if the first car is going faster than the second call (note, the first car calls the method)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!