想了好幾個(gè)小時(shí)沒(méi)有頭緒,看了下問(wèn)答,有了點(diǎn)靈感~如有雷同,沒(méi)錯(cuò),我抄的!
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("歡迎進(jìn)入本系統(tǒng)"+'\n'+"請(qǐng)輸入Y確認(rèn),輸入任意鍵退出");
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("馬自達(dá)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("序列號(hào):"+"\t"+"名稱"+"\t"+"價(jià)格"+"\t"+"載客量"+"\t"+"載重量");
for(int i=0;i<CarList.length;i++) {
System.out.println("序列號(hào):"+i+"\t"+CarList[i].name+"\t"+CarList[i].price+"/天"+"\t"+CarList[i].guest+"\t"+CarList[i].weight+"噸");
}
System.out.println("請(qǐng)輸入租車數(shù)量");
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("請(qǐng)輸入第"+(j+1)+"輛車的序號(hào)");
Scanner scanner3=new Scanner(System.in);
int count2=scanner3.nextInt();
if(count2>=0&&count2<6) {
zhuche[j]=CarList[count2];
}
else {
System.out.println("輸入有誤,請(qǐng)重新輸入!");
j--;
}
}
System.out.println("請(qǐng)輸入租車天數(shù)");
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'+"載客總數(shù):"+sum1+'\n'+"載重總數(shù):"+sum2+'\n'+"總金額:"+sum3);
}
else {
System.out.println("感謝使用!再見(jiàn)!");
}
}
}
2019-09-30
牛批!
2019-09-28
怎么把可以載人的車和可以載物的車區(qū)分開(kāi)?