package 练习1;
import java.util.Scanner;
public class Yunxin {
static Scanner in=new Scanner(System.in);
static int yi;
static int zhu;
static int cheshu=0;
static int xu=0;
static int zhonjin=0;
static int zhonren=0;
static int zhonhuo=0;
static int tian=0;
public static void main(String[] args) {
System.out.println("欢迎来到哒哒租车系统");
System.out.println("输入1.进入 0.退出");
yi=in.nextInt();
if (yi==1) {
Car cars[]={new Keche(4,"奥迪A4",1,500),
new Keche(4,"马自达6",2,400),
new Pika(4,"皮卡雪6",3,450,2),
new Keche(20,"金龙",4,800),
new Huoche("松花江",5,400,4),
new Huoche("依维柯",6,1000,20)};
System.out.println("请输入租车的数量:");
zhu=in.nextInt();
System.out.println("请输入租车的天数:");
tian=in.nextInt();
int zhuche[]=new int[zhu];
while (cheshu<zhu) {
System.out.println("请输入要租的第"+(cheshu+1)+"辆序号");
xu=in.nextInt();
if (xu<7) {
zhuche[cheshu]=xu;
cheshu++;
}else{
System.out.println("输入错误,请重新输入");
continue;
}
}
System.out.println("租用的皮卡有:");
for (int i=0;i<cars.length;i++) {
for (int j = 0; j < zhuche.length; j++) {
if (zhuche[j]==cars[i].xuhao&&cars[i].huo>0&&cars[i].ren>0){
zhonjin+=cars[i].jiner*tian;
zhonren+=cars[i].ren;
zhonhuo+=cars[i].huo;
System.out.print(cars[i].name+" ");
}
}
}
System.out.println();
System.out.println("租用的货车有:");
for (int i=0;i<cars.length;i++) {
for (int j = 0; j < zhuche.length; j++) {
if (zhuche[j]==cars[i].xuhao&&cars[i].huo>0){
if (cars[i].ren>0) {
break;
}else{
zhonjin+=cars[i].jiner*tian;
zhonhuo+=cars[i].huo;
System.out.print(cars[i].name+" ");
}
break;
}
}
}
System.out.println();
System.out.println("租用的客车有:");
for (int i=0;i<cars.length;i++) {
for (int j = 0; j < zhuche.length; j++) {
if (zhuche[j]==cars[i].xuhao&&cars[i].ren>0){
if (cars[i].huo>0) {
break;
}else{
zhonjin+=cars[i].jiner*tian;
zhonren+=cars[i].ren;
System.out.print(cars[i].name+" ");
}
break;
}
}
}
System.out.println();
System.out.println("租用总金额:"+zhonjin+" "+"总载客量: "+zhonren+"人"+" "+"总载货: "+zhonhuo+"吨");
}
else {
System.out.println("已退出");
}
}
}
package 练习1;
public class Car {
int ren;
String name;
int xuhao;
int jiner;
int huo;
public Car(int ren,String name,int xuhao,int jiner,int huo){
this.ren=ren;
this.name=name;
this.xuhao=xuhao;
this.jiner=jiner;
this.huo=huo;
}
public Car(int ren,String name,int xuhao,int jiner){
this.ren=ren;
this.name=name;
this.xuhao=xuhao;
this.jiner=jiner;
}
public Car(String name,int xuhao,int jiner,int huo){
this.name=name;
this.xuhao=xuhao;
this.jiner=jiner;
this.huo=huo;
}
}package 练习1;public class Pika extends Car { public Pika(int ren, String name, int xuhao, int jiner, int huo) { super(ren, name, xuhao, jiner, huo); System.out.println(xuhao+". "+name+" "+jiner+"元/天 "+ren+"人"+huo+"吨"); // TODO 自动生成的构造函数存根 }}package 练习1;public class Huoche extends Car { public Huoche(String name, int xuhao, int jiner, int huo) { super(name, xuhao, jiner, huo); // TODO 自动生成的构造函数存根 System.out.println(xuhao+". "+name+" "+jiner+"元/天 "+huo+"吨"); }}package 练习1;public class Keche extends Car { public Keche(int ren, String name, int xuhao, int jiner) { super(ren, name, xuhao, jiner); // TODO 自动生成的构造函数存根 System.out.println(xuhao+". "+name+" "+jiner+"元/天 "+ren+"人"); }}
添加回答
举报
0/150
提交
取消