亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

重新來下

import?java.util.Scanner;


public?class?Car?{
???????public?String?name;
???????public?int?money;
???????public?int?people;
???????public?int?things;
???????public?double?thing;
???????public?Car(String?name,?int?money,?int?people){
????	???this.name=name;
????	???this.money=money;
????	???this.people=people;
????	???System.out.println(???name??+?"??????"??+?money??+?"元/天"??+?"?????????"?+?"載人:"?+?people?+?"人");
???????}
???????public?Car?(String?name,?int?money,?int?people,?int?things){
????	???
????	???this.name=name;
????	???this.money=money;
????	???this.people=people;
????	???this.things=things;
????	???System.out.println(?name?+??"?????????????????????????????"??+?money?+?"元/天"?+?"?????????"?+?"載人:"?+?people?+?"人"?+?"?????????"?+?"載貨"?+?things?+?"噸"?);
???????}
???????
????public?Car?(String?name,?int?money,??double?thing){
????	???
????	???this.name=name;
????	???this.money=money;
????	???this.thing=thing;
????	???System.out.println(??name?+??"???????????????????????"??+?money?+?"元/天"?+?"?????????"?+?"載貨:"?+?thing?+?"噸"?);
???????}
???????
???????
}





import java.util.Scanner;

public class InitialCar {


public static void main(String[] args) {

// TODO Auto-generated method stub

? System.out.println("歡迎使用嗒嗒租車系統");

? ? System.out.println("你是否想要租車:1是 ? ?0否");

? ? Scanner scanner =new Scanner(System.in);

? ? int a=scanner.nextInt();

? ? if(a==1){

System.out.println("你可租車的類型及其價目表:");?

System.out.println("序號 ? ? ? ? " + "汽車名稱 ? ? ? ? ? ? ? ? ? " + "租金 ? ? ? ? ? ? ? ? ? ? ?" + "容量 ");?

Car car1=new Car("1. ? 奧迪A4", 500, 4);

Car car2=new Car("2. ? 馬自達6", 400, 4);

Car car3=new Car("3. ? 皮卡", 450, 4,2);

Car car4=new Car("4. ? 金龍32", 800, 20);

Car car5=new Car("5. ? 松花江", 400, 4.0);

Car car6=new Car("6. ? 依擒科", 1000, 20.0);

System.out.println("請輸入你要租的汽車數量");

Scanner sc =new Scanner(System.in);

? int b=sc.nextInt();

??

? int price=0;

? int sum=0;

? int weight=0;

? String logo=" ";

? String logo1=" ";

?for(int i=1; i<=b; i++){

System.out.println("請輸入第" + i + "輛車的序號");?

Scanner scnn =new Scanner(System.in);

? int c=scnn.nextInt();

? switch (c){

? case 1:

? logo="奧迪A4";

? ? ? price=500;

? ? ? sum=4;

? ? ? break;

?case 2:

? logo="馬自達6";

? ? ? price=400;

? ? ? sum=4;

? ? ?break;

case 3:

? logo="皮卡";

? ? ? price=450;

? ? ? sum=4;?

? ? ? weight=2;

? ? ? logo1="皮卡";

? ? ? break;

case 4:

? logo="金龍32";

? ? ? price=800;

? ? ? sum=20;?

? ? ? break;

case 5:

? logo1="松花江";

? ? ? price=400;

? ? ? weight=4;

? ? ? break;

case 6:

? logo1="依擒科";

? ? ? price=1000;

? ? ? weight=20;?

? ? ? break;

? ? ??

? ? ??

? }

? logo += logo;?

? sum += sum ;

? weight +=weight;

? price +=price;

? logo1 += logo1; ?

? ? ? ? ? ?

? ??

?}

?

System.out.println("請輸入租車天數");

Scanner day =new Scanner(System.in);

? int days=day.nextInt();

?

System.out.println("你的賬單:");

System.out.println("*****可載人的車有:"); ?

System.out.println(logo + " ? 共載人:" + sum);

System.out.println("*****可載貨的車有:" );

System.out.println(logo1 + " ? 共載貨:" + weight);?

System.out.println("租車總價格: ? " + price*days + "元");?

??

? ?}else{

? System.out.println("你已退出!");

? ?}

? ? ? ??

}


}



運行結果是亂的,不知道哪里出了問題

望高手指點


正在回答

1 回答

? logo += logo;?

? sum += sum ;

? weight +=weight;

? price +=price;

? logo1 += logo1; ?

這里出了問題,看上去像是沒有問題,但是測試過后,你會發現結果會比正確值多一半。。比如sum+=sum,假設case:1時,結果會是sum=4+4,但是我們是需要它的結果是sum=0+4;所以需要改成sum1+=sum,重新定義一個int sum1=0,就可以了,同理另外四個也需要改哈。。

0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消
Java入門第二季 升級版
  • 參與學習       531144    人
  • 解答問題       6326    個

課程升級!以終為始告別枯燥,在開發和重構中體會Java面向對象編程的奧妙

進入課程
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號