//界面类
package com.dada;
import java.util.*;
public class UI {
public static void main(String[] args) {
// TODO Auto-generated method stub
while(true){
System.out.println("欢迎使用答答租车系统:");
System.out.println("您是否要租车?1是,0否");
Scanner in=new Scanner(System.in);
int go;
go=in.nextInt();
if(go==0)
break;
else if(go!=1)
System.out.println("输入有误,请重新输入");
else
{
System.out.println("您可租车的类型及其价目表");
System.out.println("序号 汽车名称 租金 容量");
System.out.println("1. 奥迪A4 500元/天 载入:4人" );
System.out.println("2. 马自达6 400元/天 载入:4人" );
System.out.println("3. 皮卡雪6 450元/天 载入:4人,载货:2吨" );
System.out.println("4. 金龙 800元/天 载入:20人" );
System.out.println("5. 松花江 400元/天 载货:4吨" );
System.out.println("6. 依维柯 1000元/天 载货:20吨" );
System.out.println("请输入您要租汽车的数量:");
int num=in.nextInt();
List list=new List(num);
Car car=new Car();
for(int i=0;i<num;i++)
{
System.out.println("请输入第"+(i+1)+"辆车的序号");
int choiceCar=in.nextInt();
switch(choiceCar)
{
case 1:car=new Car("奥迪A4",500,4,0);list.carlist[i]=car; break;
case 2:car=new Car("马自达6",400,4,0);list.carlist[i]=car;break;
case 3:car=new Car("皮卡雪6",450,4,2);list.carlist[i]=car;break;
case 4:car=new Car("金龙",800,20,0);list.carlist[i]=car;break;
case 5:car=new Car("松花江",400,0,4);list.carlist[i]=car;break;
case 6:car=new Car("依维柯",1000,0,20);list.carlist[i]=car;break;
}
}
System.out.println("请输入租车天数:");
int day=in.nextInt();
list.show(day);
System.out.println();
System.out.println();
}
}
}
}
//Car类
package com.dada;
public class Car {
String carName;//车名
int carPrice;//租金
int manned;//载人数
int cargo;//载货量
public Car(){}
public Car(String carName,int carPrice,int manned,int cargo)
{
this.carName=carName;
this.carPrice=carPrice;
this.manned=manned;
this.cargo=cargo;
}
}
//清单类
package com.dada;
public class List {
int totalPrice;//总价格
int totalmanned;//总载入
int totalcargo;//总载货
Car[]carlist;//已选汽车
public List(int sum)
{
carlist=new Car[sum];
}
public void show(int day)
{
for(Car i:carlist)
{
totalmanned+=i.manned;
totalcargo+=i.cargo;
}
System.out.println("您的账单:");
System.out.println("***可载人的的车有:");
for(Car i:carlist)
if(i.manned!=0)
System.out.print(i.carName+" ");
System.out.println("共载人"+totalmanned+"人");
System.out.println("***载货的的车有:");
for(Car i:carlist)
if(i.cargo!=0)
System.out.print(i.carName+" ");
System.out.println("共载货:"+totalcargo+"吨");
for(Car i:carlist)
totalPrice+=i.carPrice;
totalPrice*=day;
System.out.println("***租车总价格:"+totalPrice+"元");
}
}
热门评论
carlist=new Car[sum];
作者: 长歌当酒
链接:http://www.imooc.com/article/8533
来源:慕课网
小白表示看不懂这一句诶,是表示创建了一个名称为carlist的数组吗?那数组的类型是什么呢?