package 答答租车;
public class Car {
public String name;
public int huo;
public int ren;
public int price;
public Car(String newName,int newHuo,int newRen,int newPrice){
name=newName;
huo=newHuo;
ren=newRen;
price=newPrice;
}
}
package 答答租车;
import java.util.Scanner;
public class Main {
public void showCars(Car[] newCars){
int i=1;
for(Car car:newCars){
System.out.println(i+"."+car.name+" 租金:"+car.price+" 载人:"+car.ren+"人"+" 载货:"+car.huo+"吨");
i++;
}
}
//选车
public Car[] elect(int newB,Car[] newCars){
Car[] myCar=new Car[newB];
for(int i=1;i<=newB;i++){
System.out.println("请输入第"+i+"辆车号码:");
Scanner scanner=new Scanner(System.in);
int b=scanner.nextInt();
System.out.println(newCars[b-1].name);
myCar[i-1]=newCars[b-1];
}
return myCar;
}
//已选车
public int newShow(Car[] myCar,int k){
int i=1;
int sum=0;
for(Car car:myCar){
System.out.println(i+"."+car.name+" 租金:"+car.price+" 载人:"+car.ren+"人"+" 载货:"+car.huo+"吨");
sum=sum+car.price;
i++;
}
return sum*k;
}
public static void main(String[] args) {
// TODO 自动生成的方法存根
Car[] cars={new PassengerCar("奥迪A4",0,4,500),new PassengerCar("马自达6",0,4,400),new PickUp("皮卡雪",2,4,450)
,new PassengerCar("金龙",0,20,800),new Truck("松花江",4,0,400),new Truck("依维柯",20,0,1000)};
System.out.println("******欢迎来到答答租车系统!!!******");
System.out.println("你是否要租车?1.是 2.否");
for(;;){
Scanner scanner1=new Scanner(System.in);
int a=scanner1.nextInt();
if(a==1){
System.out.println("欢迎租车!!!");
break;
}else if(a==0){
System.out.println("不租车滚蛋!!!");
break;
}else{
System.out.println("让你选1或0,瞎按啥玩意,傻啊,要么重选,要么滚蛋!!!");
}
}
System.out.println("你有以下车可选:");
Main main=new Main();
main.showCars(cars);
System.out.println("请输入租车数量:");
Scanner scanner2=new Scanner(System.in);
int b=scanner2.nextInt();
Car[] myCar=main.elect(b, cars);
System.out.println("请输入租车天数:");
Scanner scanner3=new Scanner(System.in);
int c=scanner3.nextInt();
System.out.println("你的租车信息:");
int p=main.newShow(myCar, c);
System.out.println("总租金:"+p+"元");
}
}
点击查看更多内容
7人点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦