父级(这个其实没必要写的)
package com.car;
public class First {
public int number=1;
public String name;
public int money;
public float person;
public float heavy;
}
子级1
package com.car;
public class Num1 extends First {
public int number=1;
public String name="奥迪A4";
public int money=500;
public float person=4f;
public float heavy=0f;
}
子级2
package com.car;
public class Num2 extends First {
public int number=2;
public String name="马自达6";
public int money=400;
public float person=4f;
public float heavy=0f;
};
类推,很简单吧
重要的来了!!!
输出代码
package com.car;
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input=new Scanner(System.in);
System.out.println("***欢迎使用滴滴租车系统***:");
System.out.println("您是否要租车:1是 0否");
int kais= input.nextInt();
if(kais==1) {
System.out.println("您可租车的类型及其价目表:");
System.out.println("序号 汽车名称 租金 容量\n 1. 奥迪A4 500元/天 载人:4人\n 2. 马自达6 400元/天 载人:4人\n 3. 皮卡雪6 450元/天 载人:4人\n 4. 金龙 800元/天 载人:20人\n 5. 松花江 400元/天 载货4吨\n 6. 依维柯 1000元/天 载货:20吨");
Num1 f1=new Num1();
Num2 f2=new Num2();
Num3 f3=new Num3();
Num4 f4=new Num4();
Num5 f5=new Num5();
Num6 f6=new Num6();
int max=0;
String Mname="";
float Mperson=0f;
float Mheavy=0f;
System.out.println("请输入您要租汽车的数量:");
int shul=input.nextInt();
for(int i=1;i<=shul;i++) {
System.out.println("请输入你要租的第"+i+"辆车序号");
int xuhao=input.nextInt();
if(xuhao==1) {
max=max+f1.money;
Mname=Mname+"丶 "+f1.name;
Mperson=Mperson+f1.person;
Mheavy=Mheavy+f1.heavy;
}else if(xuhao==2) {
max=max+f2.money;
Mname=Mname+"丶"+f2.name;
Mperson=Mperson+f2.person;
Mheavy=Mheavy+f2.heavy;
}else if(xuhao==3) {
max=max+f3.money;
Mname=Mname+"丶"+f3.name;
Mperson=Mperson+f3.person;
Mheavy=Mheavy+f3.heavy;
}else if(xuhao==4) {
max=max+f4.money;
Mname=Mname+"丶"+f4.name;
Mperson=Mperson+f4.person;
Mheavy=Mheavy+f4.heavy;
}else if(xuhao==5) {
max=max+f5.money;
Mname=Mname+"丶"+f5.name;
Mperson=Mperson+f5.person;
Mheavy=Mheavy+f5.heavy;
}else if(xuhao==6) {
max=max+f6.money;
Mname=Mname+"丶"+f6.name;
Mperson=Mperson+f6.person;
Mheavy=Mheavy+f6.heavy;
}else {
System.out.println("请输入1-6");
i--;
}
};
System.out.println("请输入你要租的天数");
int day=input.nextInt();
max=max*day;
System.out.println("你这次租车有"+Mname+"这几辆车;总共可以座"+Mperson+"个人;总共可以装"+Mheavy+"吨;总金额为"+max+"元");
}else {
System.out.println(" see you 凉凉");
}
}
}