Computer Science, asked by 177r1a05p1, 10 months ago

Car building program in java

Answers

Answered by NirmalPandya
0

•The car building program in java goes likewise-

•class Car{

int year;

String make;

double speed;

public Car(int y,String m,double s){

this.year = y;

this.make = m;

this.speed = s;

}

public double getSpeed(){

return this.speed;

}

public String getMake(){

return this.make;

}

public int getYear(){

return this.year;

}

public void accelerate(){

this.speed+=1;

}

}

class RaceTrack{

public static void main(String[] args) {

Car c = new Car(2014,"Audi",190.0);

System.out.println("Car year: "+c.getYear());

System.out.println("Car make: "+c.getMake());

System.out.println("Car speed: "+c.getSpeed());

c.accelerate();

c.accelerate();

System.out.println("Car year: "+c.getYear());

System.out.println("Car make: "+c.getMake());

System.out.println("Car speed: "+c.getSpeed());

}

}

Similar questions