agrogan agrogan - 2 months ago 7
Java Question

Method that Returns a Boolean?

How do I make a method for my Car class called isAntique that returns a Boolean indicating if the cars is more than 45 years old?

Here is the code that I already have:

package Ch4PP5;

public class Car {
private String make, model;
private int year;

public Car(String userMake, String userModel, int userYear) {
make = userMake;
model = userModel;
year = userYear;
}

public String setMake(String newMake) {
make = newMake;
return make;
}

public String getMake() {
return make;
}

public String setModel(String newModel) {
model = newModel;
return model;
}

public String getModel() {
return model;
}

public int setYear(int newYear) {
year = newYear;
return year;
}

public int getYear() {
return year;
}

}

Answer

something like this?

public Boolean isAntique(){
   int year = Calendar.getInstance().get(Calendar.YEAR);

   if(year - this.year >= 45) {
       return true;
   } else {
       return false;
   }
}