- Engineering
- Computer Science
- for todays lab we will be using the car object...
Question: for todays lab we will be using the car object...
Question details
For today's lab we will be using the Car Object Class which we built in Lab 1. I have attached my solution if you would prefer to use my solution instead of your own solution.
We will working on remembering how to build sub-classes and user interfaces. So we will be creating new Java files for:
- An Interface called GreenHouseGasser
- Requires a method called CO2() which returns how much carbon dioxide the Object produces.
- Make sure to update Car so that Car implements GreenHouseGasser. Cars should produce 1.5 units of CO2 for every mph the car is traveling.
- A Car sub-class called SportsCar:
- Overrides the accelerate() method. SportsCars accelerate twice as fast as regular Cars
- Overrides the CO2() method. SportsCars should be using a factor of 3.25 units of CO2 for every mph
- A Car sub-class called EcoCar
- Overrides the accelerate() method. EcoCars accelerate 25% as fast as regular Cars
- Overrides the CO2() method. EcoCars should be using a factor of .33 units of CO2 for every mph
As your are building/updating your objects, remember to test. You'll need update the Driver to test your new methods and Objects!
Submit all of your .java files in one jar or zip file.
Grading Breakdown:
- Driver tests all new methods and objects -- 25%
- Interface created correctly and Car updated to implement the Interface -- 25%
- SportsCar correctly created -- 20%
- EcoCar correctly created -- 20%
- JavaDoc comments! -- 10%
Here is the Car Object pre-made:
public class Car
{
private String name;
private int currentSpeed;
public Car(String inName)
{
name = inName;
}
public void accelerate()
{
currentSpeed += 10;
}
public void park()
{
currentSpeed = 0;
}
public void printCurrentSpeed()
{
System.out.println("Current Speed is: " + currentSpeed);
}
}
Here is the driver that is supposed to be used:
public class Driver {
public static void main(String[] args) {
// create new Audi car
Car audi = new Car("Audi");
// create new Nissan car
Car nissan = new
Car("Nissan");
// print current speed of Audi - it
is 0
audi.printCurrentSpeed();
// call the accelerate method twice
on Audi
audi.accelerate();
audi.accelerate();
// call the accelerate method once
on Nissan
nissan.accelerate();
// print current speed of Audi - it
is now 20 mpH
audi.printCurrentSpeed();
// print current speed of Nissan -
it is 10 mpH
nissan.printCurrentSpeed();
// now park the Audi car
audi.park();
// print current speed of Audi - it
is now 0, because the car is parked
audi.printCurrentSpeed();
}
}
Solution by an expert tutor
