Main方法=========================================
public class Test {
public static void main(String[] args) {
Bus a=new Bus();
Car b=new Car();
Scanner sm=new Scanner(System.in);
System.out.println("请输入你要租车的天数");
int sr=sm.nextInt();
System.out.println("请输入你要租的气车(1。轿车/2.客车)");
String sr1=sm.next();
if(sr1.equals("1")){
System.out.println("请输入你要租的车的牌子(1.宝马/2.别克)");
String sr2=sm.next();
b.setXh(sr2);
b.print();
if(sr2.equals("2")){
System.out.println("请输入轿车的型号 1.商务舱 2.林大道");
String sr3=sm.next();
b.setXh(sr3);
b.CalcRent("湘A.618c2", sr);
b.print();
}
}else {
System.out.println("请输入你的客车品牌(1.金龙2.金杯)");
String srr=sm.next();
System.out.println("请输入客车座位号");
int srr1=sm.nextInt();
a.setSeaCount(srr1);
a.CalcRent("湘A.618c2",sr);
a.print();
}
}
//=-----------卡车父类
public abstract class MotoVehiscle {
// 车牌号
private String No;
//品牌
private String Brand;
//颜色
private String Color;
//里程
private String Mileage;
public String getNo() {
return No;
}
public void setNo(String no) {
No = no;
}
public String getBrand() {
return Brand;
}
public void setBrand(String brand) {
Brand = brand;
}
public String getColor() {
return Color;
}
public void setColor(String color) {
Color = color;
}
public String getMileage() {
return Mileage;
}
public void setMileage(String mileage) {
Mileage = mileage;
}
public MotoVehiscle(){
}
public MotoVehiscle(String no,String brand,String color,String mileage){
this.No =no;
this.Brand =brand;
this.Color =color;
this.Mileage=mileage;
}
public abstract int CalcRent(String no,int days);
}
//====================子类公车
public final class Bus extends MotoVehiscle {
private int SeaCount;
int qian = 0;
public int getSeaCount() {
return SeaCount;
}
public void setSeaCount(int seaCount) {
SeaCount = seaCount;
}
public int CalcRent(String no, int days) {
// TODO Auto-generated method stub
if (this.SeaCount > 16) {
qian = 1500 * days;
} else {
qian = 800 * days;
}
return qian;
}
public Bus() {
System.out.println("");
}
public Bus(String no, String brand, String color, String mileage) {
super(no, brand, color, mileage);
}
public void print() {
System.out.println("你总共消费" + this.qian);
}
}
===子类小轿车
public final class Car extends MotoVehiscle {
private String Type;
int qiang=0;
public String getXh() {
return Type;
}
public void setXh(String xh) {
Type = xh;
}
public int CalcRent(String no,int days) {
if("1".equals(Type)){
qiang=500*days;
}else if("2".equals(Type)){
qiang=600*days;
}
qiang=300*days;
return qiang ;
}
public Car (String no,String brand,String color,String mileage){
super(no, brand, color, mileage);
}
public Car(){
}
public void print(){
System.out.println("你好,你要付的钱是:"+this.qiang);
}
}