還望老師在思想面不吝賜教
雖然說(shuō)java是面向?qū)ο蟮模拔沂菍W(xué)過(guò)C的,總擺脫不了C的思維,這一次老師給的項(xiàng)目練習(xí)我就這么淡定的用C的思想硬生生的用java敲出來(lái)了,請(qǐng)問(wèn)我是不是中毒太深了,而且我也不覺(jué)的這有什么不好的,下面是我的代碼,請(qǐng)老師過(guò)目:
package com.imooc;
import java.util.Scanner;
public class Dadazhuchesystem {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("歡迎使用嗒嗒租車系統(tǒng): ");
System.out.println("你是否需要租車: 1.是 0.否");
Scanner input = new Scanner(System.in);
int i = input.nextInt();
if(i == 1) {
System.out.println("您可租車的類型及其價(jià)格表");
System.out.println("序號(hào) 汽車名稱 租金 容量");
System.out.println("1 奧迪A4 500/天 載人:4");
System.out.println("2 馬自達(dá)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("請(qǐng)輸入您需要租車的數(shù)量:");
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("請(qǐng)輸入第" + m + "輛車的序號(hào): ");
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("請(qǐng)輸入租車的天數(shù): ");
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("馬自達(dá)6 ");}
if(count3 != 0) {System.out.print("皮卡雪6 ");}
if(count4 != 0) {System.out.print("金龍 ");}
System.out.println("可載人數(shù): " + 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("***租車總價(jià)格: " + countMoney + "元");
}
}
2016-09-20
雖然代碼思路是對(duì)的 ?但你這完全是面向過(guò)程 ?java的面對(duì)對(duì)象特性沒(méi)有任何體現(xiàn),除了Scanner之外 全部都是流程控制if else 加上個(gè)輸出語(yǔ)句。。。實(shí)在是浪費(fèi)了java的好處。