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

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

還望老師在思想面不吝賜教

雖然說java是面向對象的,之前我是學過C的,總擺脫不了C的思維,這一次老師給的項目練習我就這么淡定的用C的思想硬生生的用java敲出來了,請問我是不是中毒太深了,而且我也不覺的這有什么不好的,下面是我的代碼,請老師過目:

package com.imooc;


import java.util.Scanner;


public class Dadazhuchesystem {


public static void main(String[] args) {

// TODO Auto-generated method stub

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

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

Scanner input = new Scanner(System.in);

int i = input.nextInt();

if(i == 1) {

System.out.println("您可租車的類型及其價格表");

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

System.out.println("1 奧迪A4 500/天 載人:4");

System.out.println("2 馬自達6 400/天 載人:4");

System.out.println("3 皮卡雪6 450/天 載人:4;載物:2t");

System.out.println("4 金龍 800/天 載人:20");

System.out.println("5 松花江 400/天 載貨4t");

System.out.println("6 依維柯 1000/天 載貨20t");

System.out.print("請輸入您需要租車的數量:");

System.out.println();

} else {System.out.println("感謝您的光臨!");}

Scanner input2 = new Scanner(System.in);

int i2 = input.nextInt();

int count1 = 0, count2 = 0, count3 = 0, count4 = 0, count5 = 0, count6 = 0, countPerson = 0, countThing = 0, countMoney = 0;

for(int m = 1; m <= i2; m++) {

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

Scanner input3 = new Scanner(System.in);

int i3 = input.nextInt();

if(i3 == 1) {

count1++; countPerson += 4; countMoney += 500;

} else if(i3 == 2) {

count2++; countPerson += 4; countMoney += 400;

} else if(i3 == 3) {

count3++; countPerson += 4; countThing += 2; countMoney += 450;

} else if(i3 == 4) {

count4++; countPerson += 20; countMoney += 800;

} else if(i3 == 5) {

count5++; countThing += 4; countMoney += 400;

} else if(i3 == 6) {

count6++; countThing += 20; countMoney += 1000;

}

}

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

Scanner input4 = new Scanner(System.in);

int i4 = input.nextInt();

countMoney = i4 * countMoney;

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

if(count1 != 0) {System.out.print("奧迪A4 ");}

if(count2 != 0) {System.out.print("馬自達6 ");}

if(count3 != 0) {System.out.print("皮卡雪6 ");}

if(count4 != 0) {System.out.print("金龍 ");}

System.out.println("可載人數: " + countPerson + ";");

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

if(count3 != 0) {System.out.print("皮卡雪6 ");}

if(count5 != 0) {System.out.print("松花江 ");}

if(count6 != 0) {System.out.print("依維柯 ");}

System.out.println("可載貨重量: " + countThing + "t");

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

}


}


正在回答

1 回答

雖然代碼思路是對的 ?但你這完全是面向過程 ?java的面對對象特性沒有任何體現,除了Scanner之外 全部都是流程控制if else 加上個輸出語句。。。實在是浪費了java的好處。

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

舉報

0/150
提交
取消

還望老師在思想面不吝賜教

我要回答 關注問題
微信客服

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

幫助反饋 APP下載

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

公眾號

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