问答详情
源自:12-1 综合练习

想了好几个小时没有头绪,看了下问答,有了点灵感~如有雷同,没错,我抄的!

public class Car {

int price;

int guest;

int weight;

String name;

public Car(String name,int price,int guest,int weight) {

this.name=name;

this.price=price;

this.guest=guest;

this.weight=weight;

}




}

package recentCar;


import java.util.Scanner;


public class test {


public static void main(String[] args) {

// TODO Auto-generated method stub

System.out.println("欢迎进入本系统"+'\n'+"请输入Y确认,输入任意键退出");

Scanner scanner=new Scanner(System.in);

String o=scanner.next();

if(o.contentEquals("Y")) {

int sum1=0;

int sum2=0;

int sum3=0;

Car[] CarList= {

new Car("奥迪A4",400,4,0),

new Car("马自达6",400,4,0),

new Car("皮卡雪",450,4,2),

new Car("金龙",800,20,0),

new Car("松花江",400,0,4),

new Car("依维柯",1000,0,20)

};

System.out.println("序列号:"+"\t"+"名称"+"\t"+"价格"+"\t"+"载客量"+"\t"+"载重量");

for(int i=0;i<CarList.length;i++) {

System.out.println("序列号:"+i+"\t"+CarList[i].name+"\t"+CarList[i].price+"/天"+"\t"+CarList[i].guest+"\t"+CarList[i].weight+"吨");

}

System.out.println("请输入租车数量");

Scanner scanner2=new Scanner(System.in);

int count=scanner2.nextInt();

Car[] zhuche=new Car[count];

for(int j=0;j<count;j++) {

System.out.println("请输入第"+(j+1)+"辆车的序号");

Scanner scanner3=new Scanner(System.in);

int count2=scanner3.nextInt();

if(count2>=0&&count2<6) {

zhuche[j]=CarList[count2];

}

else {

System.out.println("输入有误,请重新输入!");

j--;

}


}


System.out.println("请输入租车天数");

Scanner scanner4=new Scanner(System.in);

int count3=scanner4.nextInt();

for(int p=0;p<zhuche.length;p++) {

sum1=zhuche[p].guest+sum1;

sum2=zhuche[p].weight+sum2;

sum3=zhuche[p].price*count3+sum3;

}

System.out.println("下面是您的账单:"+'\n');

System.out.println("共租用车辆:"+count+'\n'+"载客总数:"+sum1+'\n'+"载重总数:"+sum2+'\n'+"总金额:"+sum3);

}

else {

System.out.println("感谢使用!再见!");

}

}



}


提问者:慕移动0111711 2019-09-26 00:33

个回答

  • 慕容1529948
    2019-09-30 11:12:44

    牛批!

  • 慕圣1643384
    2019-09-28 22:58:21

    怎么把可以载人的车和可以载物的车区分开?