initial
package com.immoc; import java.util.Scanner; public class Initial { public static void main(String[] args) { // TODO Auto-generated method stub System.out.println("欢迎使用"); System.out.println("是否需要租车"); Scanner input=new Scanner(System.in); System.out.println("1.是 2.否"); int choice=input.nextInt(); if(choice==1){ System.out.println("可用车辆价目表"); System.out.println("1.A 500元/天 载人:4人"); System.out.println("2.B 400元/天 载人:2人"); System.out.println("3.C 700元/天 载货:5吨"); System.out.println("4.D 1000元/天 载货:20吨"); System.out.println("5.E 450元/天 载人:2人 载货:2吨"); System.out.println("您需要租多少辆车?"); int num=input.nextInt(); ACar[] Car=new ACar[num]; int i; for(i=0;i<Car.length;i++){ System.out.println("请输入第"+(i+1)+"俩车的序号:"); switch(input.nextInt()){ case 1: Car[i]=new A(); break; case 2: Car[i]=new B(); break; case 3: Car[i]=new C(); break; case 4: Car[i]=new D(); break; case 5: Car[i]=new E(); break; default: System.out.println("无此序号!"); input.close(); } } System.out.println("请输入租车天数"); int day=input.nextInt(); int Allperson=0,Allcargo=0,price=0,personcount=0,cargocount=0; for(i=0;i<Car.length;i++){ if(Car[i].cargo!=0){ cargocount++; Allcargo=Car[i].cargo+Allcargo; } if(Car[i].person!=0){ personcount++; Allperson=Car[i].person+Allperson; } price=price+Car[i].rent*day; } System.out.println("可载货的车辆数为"+cargocount); System.out.println("可载人的车辆数为"+personcount); System.out.println("共可载货"+Allcargo+"吨"); System.out.println("共可载人"+Allperson+"位"); System.out.println("总价位"+price+"元"); input.close(); } else{ input.close(); System.out.println("谢谢使用!"); } } }
ACar
package com.immoc; public class ACar { public int person; public int cargo; public int rent; public String Name; public int NO; public ACar(){ this.NO=0; this.rent=0; this.cargo=0; this.person=0; this.Name=""; } }
A
package com.immoc; public class A extends ACar { public void ACar1(){ this.Name="A"; this.NO=1; this.person=4; this.cargo=0; this.rent=500; } }
B
package com.immoc; public class B extends ACar { public void Acar2(){ this.NO=2; this.person=2; this.cargo=0; this.Name="B"; this.rent=400; } }
C
package com.immoc; public class C extends ACar { public void ACar3(){ this.NO=3; this.Name="C"; this.rent=700; this.cargo=5; this.person=0; } }
D
package com.immoc; public class D extends ACar { public void ACar4(){ this.NO=4; this.Name="D"; this.rent=1000; this.cargo=20; this.person=0; } }
E
package com.immoc; public class E extends ACar { public void ACar5(){ this.NO=5; this.Name="E"; this.rent=450; this.person=2; this.cargo=2; } }
相关分类