b

b

Tuesday, February 23, 2016

Car.java & CarTest.java

Car.java & CarTest.java



//*********************************************************************
// Car.java
//*********************************************************************
public class Car {
   

    private String model;
    private int yearOfthecar;
    private String make;
    private final int DELTA = 45;
    public Car (String make, String model, int yearOfthecar)
    {
    this.make = make;
    this.model = model;
    this.yearOfthecar = yearOfthecar;
    }
   
   
    public String getMake()
    {
        return make;
    }
   
    public void setMake(String make)
    {
    this.make = make;
    }
   
    public String getModel()
    {
        return model;
    }
   
    public void setModel(String model)
    {
        this.model = model;
    }
   

    public int getYearOfthecar()
    {
        return yearOfthecar;
    }

    public void setYearOfthecar(int yearOfthecar)
    {
       
        this.yearOfthecar = yearOfthecar;
    }
   
   
    public String toString()
    {
        return ("This car is a " + yearOfthecar + " "+ make + " "+model);
    }
   
    public void isAntique ()
    {
        while (2015 - yearOfthecar > DELTA)
            {
            System.out.println("This car is more than 45 years old and it is an antique car!");
            }
       
    }
}

//****************************************************************************************
// CarTest.java
//****************************************************************************************

public class CarTest {

    public static void main(String[] args) {
       
        int DELTA = 45;
        Car car = new Car ("Oodi ", "A4",2000);
       
        System.out.println("The make is "+car.getMake());
        System.out.println("The model is "+car.getModel());
        System.out.println("The year of car is "+car.getYearOfthecar());
       
        car.setYearOfthecar(1700);
        System.out.println("The year of car is "+car.getYearOfthecar());

        if (2015 - car.getYearOfthecar()> DELTA)
       
        System.out.println("This car is more than 45 years old and it is an antique car!");
       
    }

}


No comments:

Post a Comment