package com.trans;
public class Transport {
protected String name;
protected int speed;
protected int energy;
//protected boolean swim;
public String getName(){
return name;
}
public int getSpeed(){
return speed;
}
public int getEnergy(){
return energy;
}
public void consumGas(){
energy -= 10;
}
}
package com.trans;
public class TransportMain {
public static void main(String[] args){
Ship s = new Ship("배",25,50,true);
s.consumGas();
Air a = new Air("비행기",50,100,true);
a.consumGas();
System.out.println("==================================");
System.out.println("이름\t속도\t연료\t비고");
System.out.println("==================================");
System.out.print(s.getName()+"\t");
System.out.print(s.getSpeed()+"\t");
System.out.print(s.getEnergy()+"\t");
System.out.print((s.getSwim()?"항해" : "정박")+"\n");
System.out.print(a.getName()+"\t");
System.out.print(a.getSpeed()+"\t");
System.out.print(a.getEnergy()+"\t");
System.out.print((a.getFly()?"비행" : "착륙")+"\n");
}
}
package com.trans;
class Ship extends Transport{
private boolean swim=true;
public void consumGas(){//메소드 오버라이딩으로 재정의
energy -= 25;
}
public Ship(String name,int speed,int energy,boolean swim){
this.name=name;
this.speed=speed;
this.energy=energy;
}
public boolean getSwim(){
return swim;
}
}
package com.trans;
class Air extends Transport{
public void consumGas(){
energy -= 50;
}
private boolean fly=true;
public Air(String name,int speed,int energy, boolean fly){
this.name=name;
this.speed=speed;
this.energy=energy;
}
public boolean getFly(){
return fly;
}
}