这样行吗?
public class HelloWorld{
public static void main(String[] args) {
System.out.println("-----请输入您所要查询的车型----");
System.out.println("1.宝马 ,2.奔驰,3.奥迪");
Scanner input = new Scanner(System.in);
int number = input.nextInt();
System.out.println("请输入租车数量:");
Scanner input2 = new Scanner(System.in);
int number2 = input2.nextInt();
System.out.println("请输入租车天数:");
Scanner input3 = new Scanner(System.in);
int number3 = input3.nextInt();
Coures bm = new bM();
Coures bc = new bC();
Coures ad = new aD();
switch(number) {
case 1:
bm.zC(number2,number3);
break;
case 2:
bm.zC(number2,number3);
break;
case 3:
bm.zC(number2,number3);
break;
default:
System.out.println("对不起,输入错误,请重新输入有效信息!");
}
}
}
抽象类 public abstract class Coures{
public abstract void zC(int quantity,int day);
}
宝马类 public void zC(int quantity,int day) {
float price = (quantity*500)*day;
System.out.println("车型:宝马"+'\n'+"数量:"+quantity+'\n'+"天数:"+day+'\n'+"单价:500"+'\n'+"总金额:"+price);
}
}
奔驰类 public class bC extends Coures {
public void zC(int quantity ,int day) {
float price = (quantity*600)*day;
System.out.println("车型:奔驰"+'\n'+"数量:"+quantity+'\n'+"天数:"+day+'\n'+"单价:600"+'\n'+'\n'+"总金额:"+price);
}
}
奥迪类 public class aD extends Coures{
public void zC(int quantity,int day) {
float price = (quantity*700)*day;
System.out.println("车型:奥迪"+'\n'+"数量:"+quantity+'\n'+"天数:"+day+'\n'+"单价:700"+'\n'+"总金额:"+price);
}
}