慕雪7149511
2016-09-20 21:22
虽然说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 + "元");
}
}
虽然代码思路是对的 但你这完全是面向过程 java的面对对象特性没有任何体现,除了Scanner之外 全部都是流程控制if else 加上个输出语句。。。实在是浪费了java的好处。
Java入门第二季 升级版
530655 学习 · 6091 问题
相似问题