這樣行嗎?
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("請輸入租車數(shù)量:");
?? ??? ?Scanner input2 = new Scanner(System.in);
?? ??? ?int number2 = input2.nextInt();
?? ??? ?
?? ??? ?System.out.println("請輸入租車天數(shù):");
?? ??? ?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("對不起,輸入錯(cuò)誤,請重新輸入有效信息!");
?? ??? ?}
?? ?}
}
抽象類? 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'+"數(shù)量:"+quantity+'\n'+"天數(shù):"+day+'\n'+"單價(jià):500"+'\n'+"總金額:"+price);
?? ?}
?? ?
}
奔馳類 public class bC extends Coures {
?? ?public void zC(int quantity ,int day) {
?? ??? ?float price = (quantity*600)*day;
?? ??? ?System.out.println("車型:奔馳"+'\n'+"數(shù)量:"+quantity+'\n'+"天數(shù):"+day+'\n'+"單價(jià):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'+"數(shù)量:"+quantity+'\n'+"天數(shù):"+day+'\n'+"單價(jià):700"+'\n'+"總金額:"+price);
?? ?}
}
2019-05-26
沙發(fā)沙發(fā)沙發(fā)