The objectives of this lab are to reinforce and help teach:
In this lab, you will develop a class that is the OOP representation of a car.
You will not write a program but instead only the Car class and that will be developed in a Car.java file. The main program is give here and should be copied into your Lab10 project as Lab10.java
Again, you will have to create your own Car.java class according to the specification below.
Develop your Car class as follows
private String make;
private String model;
private int year;
private double mpg;
private double zeroToSixty;
private double speed;
this.make = "undefined";
this.model = "undefined";
this.year = 1900;
this.mpg = 0.0;
this.zeroToSixty = 0.0;
this.speed = 0;
/*
* toString - returns a string representation of the Car
*/
public String toString() {
return String.format("Make=%s, Model=%s, Year=%d, MPG=%.2f, Zero to Sixty in %.2f seconds, Current Speed=%.2f mph.",
this.make,
this.model,
this.year,
this.mpg,
this.zeroToSixty,
this.speed);
}
/*
* accelerate - accelerates the car for a supplied number of seconds
*/
public void accelerate(int seconds) {
System.out.printf("\tAccelarating %s %s for %d seconds.\n", this.make, this.model, seconds);
this.speed += /* put your code here */;
}
/*
* brakes - brakes (decelerates) the car for a supplied number of seconds limiting the
* lowest speed to be 0.00 mph.
*/
public void brake(int seconds) {
System.out.printf("\tBraking %s %s for %d seconds.\n", this.make, this.model, seconds);
this.speed = /* put your code here */;
}
Following are the instructions and you should follow them carefully:
Following is the desired output:
Car c1: Make=undefined, Model=undefined, Year=1900, MPG=0.00, Zero to Sixty in 0.00 seconds, Current Speed=0.00 mph.
Car c2: Make=Chevrolet, Model=Corvette, Year=1953, MPG=13.70, Zero to Sixty in 11.20 seconds, Current Speed=0.00 mph.
Car c3: Make=Ford, Model=Mustang, Year=1967, MPG=13.90, Zero to Sixty in 7.50 seconds, Current Speed=0.00 mph.
Accelarating Ford Mustang for 10 seconds.
Car c3: Make=Ford, Model=Mustang, Year=1967, MPG=13.90, Zero to Sixty in 7.50 seconds, Current Speed=80.00 mph.
Braking Ford Mustang for 5 seconds.
Car c3: Make=Ford, Model=Mustang, Year=1967, MPG=13.90, Zero to Sixty in 7.50 seconds, Current Speed=40.00 mph.
Braking Ford Mustang for 6 seconds.
Car c3: Make=Ford, Model=Mustang, Year=1967, MPG=13.90, Zero to Sixty in 7.50 seconds, Current Speed=0.00 mph.
This lab must be AutoLab submitted to the instructor by 11:59pm on the Monday a week after it was assigned. Check AutoLab for the specific due date.