Created
March 22, 2014 11:58
-
-
Save brijeshb42/9706089 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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