package only;
import java.util.Scanner;
public class Initial {
public static void main(String[] args) {
// TODO 自动生成的方法存根
System.out.println("欢迎使用答答租车系统:");
System.out.println("您是否需要租车:1 是 0 否");
Scanner input = new Scanner(System.in);
int temp = input.nextInt();
if(temp == 0)
return ;
else {
System.out.println("您可租车的类型及其价目表:");
System.out.println("序号 汽车名称 租金 容量");
/*******/
Cars[] o = {new Cars(),new AodiA4("奥迪A4",4,0,500),new Mazida("马自达6", 4, 0, 400),new Pika("皮卡雪6",4,2,450),new Jinlong("金龙",20,0,800),new Songhuajiang("松花江",0,4,400),new Yiweike("依维柯",0,20,1000)};
System.out.println("1. "+o[1].name+" "+o[1].price+"/天 载人:"+o[1].people+"人");
System.out.println("2. "+o[2].name+" "+o[2].price+"/天 载人:"+o[2].people+"人");
System.out.println("3. "+o[3].name+" "+o[3].price+"/天 载人:"+o[3].people+"人 载货:"+o[3].stuff+"吨");
System.out.println("4. "+o[4].name+" "+o[4].price+"/天 载人:"+o[4].people+"人");
System.out.println("5. "+o[5].name+" "+o[5].price+"/天 载人:"+o[5].stuff+"吨");
System.out.println("6. "+o[6].name+" "+o[6].price+"/天 载人:"+o[6].stuff+"吨");
/*******/
System.out.println("请输入您要租车的输量:");
int tempNum = input.nextInt();
int tempArray[] = new int[tempNum+1];
int totalPeople = 0;
int totalStuff = 0;
int totalPrice = 0;
for(int i = 1;i <= tempNum; i++){
System.out.println("请输入第"+i+"车的序号");
tempArray[i] = input.nextInt();
if(tempArray[i] > 6){
System.out.println("对不起,没有此类型的车辆,请重新输入:");
i--;
}else{
totalPeople += o[tempArray[i]].people;
totalStuff += o[tempArray[i]].stuff;
totalPrice += o[tempArray[i]].price;
}
}
System.out.println("请输入租车天数:");
int days = input.nextInt();
totalPrice *= days;
System.out.println("您的账单:");
System.out.println("***载人的车有:");
for(int i = 1;i <= tempNum;i++){
if(o[tempArray[i]].people != 0)
System.out.print(" "+o[tempArray[i]].name);
}
System.out.println(" 共载人:"+totalPeople+"人");
System.out.println("***载货的汽车:");
for(int i = 1;i <= tempNum;i++){
if(o[tempArray[i]].stuff != 0)
System.out.print(" "+o[tempArray[i]].name);
}
System.out.println(" 共载货:"+totalStuff+"吨");
System.out.println("***租车总价格:"+totalPrice+"元");
}
}
}
package only;
public class Cars {
public String name;
public int people;
public int stuff;
public int price;
}
package only;
public class AodiA4 extends Cars {
public AodiA4(String name,int people,int stuff,int price){
this.name = name;
this.people = people;
this.stuff = stuff;
this.price = price;
}
}
package only;
public class Pika extends Cars {
public Pika(String name,int people,int stuff,int price){
this.name = name;
this.people = people;
this.stuff = stuff;
this.price = price;
}
}
package only;
public class Jinlong extends Cars {
public Jinlong(String name,int people,int stuff,int price){
this.name = name;
this.people = people;
this.stuff = stuff;
this.price = price;
}
}
package only;
public class Songhuajiang extends Cars {
public Songhuajiang(String name,int people,int stuff,int price){
this.name = name;
this.people = people;
this.stuff = stuff;
this.price = price;
}
}
package only;
public class Mazida extends Cars {
public Mazida(String name,int people,int stuff,int price){
this.name = name;
this.people = people;
this.stuff = stuff;
this.price = price;
}
}
package only;
public class Yiweike extends Cars {
public Yiweike(String name,int people,int stuff,int price){
this.name = name;
this.people = people;
this.stuff = stuff;
this.price = price;
}
}
打开App,阅读手记