Warm-up

 

Identify each of the numbered components in the following code:

 

public class Vehicle { 1. What is this?

// 2. What are these two items?
private String make;
private int milesPerGallon;

// 3. The following is?
public Vehicle() {

}

// 4. What is the purpose of this method? What do you call a method like this?
public void setMake(String m){
make = m;
}

public void setMilesPerGallon(int mpg){
milesPerGallon = mpg;
}

// 5. What is the purpose of this method and what do you call a method like this?

public String getMake(){
return make;
}

public int getMilesPerGallon(){
return milesPerGallon;
}

6. What is the purpose of this method since java already has a toString() method?

public String toString() {
String output;
output = "The make of this vehicle is: " + make + ". \n";
output = output + "This vehicle gets " + milesPerGallon + " miles per gallon.";
return output;
}

}

7. Is this an object class or a driver class? How can you tell?