package com.imooc;
//创建一个Car类
public class Car {
String name ;
int pay ;
int id;
int huo;
int ke;
public Car(int id,String name,int pay,int huo,int ke){
this.id = id;
this.name =name;
this.pay = pay;
this.huo = huo;
this.ke = ke;
}
}
主类
package com.imooc;
import java.util.Scanner;
public class Dada {
public static void main(String[] args) {
System.out.println("欢迎来到答答租车系统\n"+
"您是否要租车:1是0否");
Scanner sc = new Scanner(System.in);
int i = sc.nextInt();
if (i <1) {
}
System.out.println("您可租的车型如下:");
System.out.println("ID\t名称\t租金\t载货量\t载客量");
Car [] che = {new Car(1,"奥迪A4",500,0,4),
new Car(2,"马自达6",400,0,4),
new Car(3,"皮卡雪6",450,2,4),
new Car(4,"金龙",800,0,20),
new Car(5,"松花江",400,4,0),
new Car(6,"依维柯",1000,20,0)};
for (int j = 0; j < che.length; j++) {
System.out.println(che[j].id +"\t" + che[j].name +"\t"+ che[j].pay +"元/天"+"\t"+
che[j].huo + "\t" +che[j].ke);
}
System.out.println("请输入您要租车的数量:");
int num = sc.nextInt();
Car [] zu =new Car[num];
for (int j = 0; j < zu.length; j++) {
System.out.println("请输入你选择的车辆ID");
zu[j] = che[sc.nextInt()-1];
}
System.out.println("请输入你租用天数");
int tian = sc.nextInt();
int pays = 0 ;
int keliang = 0;
int huoliang = 0;
System.out.println("您租用的车辆信息如下:");
for (int j = 0; j < zu.length; j++) {
System.out.println((j+1) +"\t" + zu[j].name +"\t"+ zu[j].pay +"元/天");
pays += zu[j].pay;
keliang += zu[j].ke;
huoliang += zu[j].huo;
}
System.out.println("一共租用"+tian+"天,"+"可载货"+huoliang+"T,"+
"可载人"+keliang+"人,"+"租金一共"+ pays*tian +"元.");
}
}
点击查看更多内容
1人点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦