Biblioteca Java - Rev 32
Subversion Repositories:
(root)/Courses and labs samples/ISP/Exemple_ISP_Cluj_2015/ExempleReflexie/src/exemple/reflexie/app/Car.java @ 34
package exemple.reflexie.app;
/**
*
* @author Mihai Hulea mihai.hulea@aut.utcluj.ro
*/
public class Car {
private int maxSpeed = 0;
private int crtSpeed = 0;
public Car(){
maxSpeed = 180;
}
public void accelerate(){
if(crtSpeed<maxSpeed){
crtSpeed++;
System.out.println("Car accelerate to "+crtSpeed+" km/h");
}else
System.out.println("Car top speed "+crtSpeed+".Speed limit reached km/h");
}
private void setSpeedLimit(Integer x){
maxSpeed = x;
}
public int getCarMaxSpeed(){
return maxSpeed;
}
public String toString(){
return "[Car max speed="+maxSpeed+"]";
}
}