抽象クラスの問題を解く


自動車オプションの表示
条件:抽象等級を確立し、排気量税が異なる.定数を使用するクラスを作成し、呼び出しクラスを作成し、定数値を呼び出します.
package sutdy.java.ex14_extend_abstract_ex_StarCar;

public abstract class StarCar {

	public String color;
	public String tire;
	public int displacement;
	public String handle;
	public int tax = 1000;
	
	public StarCar(String color, String tire, int displacement, String handle) {
		this.color = color;
		this.tire = tire;
		this.displacement = displacement;
		this.handle = handle;
	}
	
	public abstract void getSpec();
	
}
package sutdy.java.ex14_extend_abstract_ex_StarCar;

public class StarCarHighGrade extends StarCar{

	public StarCarHighGrade(String color, String tire, int displacement, String handle) {
		super(color, tire, displacement, handle);
	}

	@Override
	public void getSpec() {
		System.out.println("***************************");
		System.out.println("자동차의 색상은 " + color);
		System.out.println("자동차의 타이어은 " + tire);
		System.out.println("자동차의 배기량은 " + displacement);
		System.out.println("자동차의 핸들은 " + handle);
		
		if (displacement > 2000) {
			tax = 4500;
		}
		System.out.println("세금은 : " + tax + " 입니다.");
		
	}
	
}
package sutdy.java.ex14_extend_abstract_ex_StarCar;

public class StarCarLowGrade extends StarCar{
	public StarCarLowGrade(String color, String tire, int displacement, String handle) {
		super(color, tire, displacement, handle);
	}

	@Override
	public void getSpec() {
		System.out.println("***************************");
		System.out.println("자동차의 색상은 " + color);
		System.out.println("자동차의 타이어은 " + tire);
		System.out.println("자동차의 배기량은 " + displacement);
		System.out.println("자동차의 핸들은 " + handle);
		
		if (displacement > 2000) {
			tax = 4500;
		}
		System.out.println("세금은 : " + tax + " 입니다.");
		
	}
}
package sutdy.java.ex14_extend_abstract_ex_StarCar;

public class CarSpecs {

	public static final String CAR_BLUE = "블루";
	public static final String CAR_RED = "레드";
	
	public static final String H_TIRE = "광폭 타이어";
	public static final String L_TIRE = "일반 타이어";
	
	public static final int DISPLACEMENT_2000 = 3000;
	public static final int DISPLACEMENT_1000 = 1000;
	
	public static final String HANDLE = "일반 핸들";
	public static final String O_HANDLE = "원형핸들";
	
}
package sutdy.java.ex14_extend_abstract_ex_StarCar;

public class MainClass {

	public static void main(String[] args) {
		
		StarCar schg = new StarCarHighGrade(CarSpecs.CAR_BLUE, CarSpecs.H_TIRE, CarSpecs.DISPLACEMENT_2000, CarSpecs.O_HANDLE);
		StarCar sclg = new StarCarLowGrade(CarSpecs.CAR_RED, CarSpecs.L_TIRE, CarSpecs.DISPLACEMENT_1000, CarSpecs.HANDLE);
		
		schg.getSpec();
		sclg.getSpec();
	}
}