Skip to content

Instantly share code, notes, and snippets.

@brijeshb42
Created March 22, 2014 11:58
Show Gist options
  • Save brijeshb42/9706089 to your computer and use it in GitHub Desktop.
Save brijeshb42/9706089 to your computer and use it in GitHub Desktop.
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());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment