搞了一個(gè)下午才寫(xiě)出這些,求大神指點(diǎn)
import java.util.Scanner;
?class Automobile {
private String name;//汽車名字
private int rent;//汽車日租金
private int busload;//汽車載客量
private int boatload;//汽車載貨量
//租車車輛屬性
public void nature(int num, String name, int rent, int busload, int boatload) {
this.name = name;
this.rent = rent;
this.busload = busload;
this.boatload = boatload;
System.out.println("序號(hào):" + num + "\t汽車名:" + name + "\t 日租金:" + rent + "元" + "\t 可載客量:" + busload + "人"
+ "\t 可載貨量:" + boatload + "噸");
}
//計(jì)算賬單
public static void rental(int days, int rent, int num) {
int rental = days * rent * num;
System.out.println("***您的賬單***");
System.out.println("租用天數(shù):" + days + "\t租用數(shù)量:" + num + "\t 總金額:" + rental + "元");
}
//輸入租車信息
public static void dowork(int rent) {
Scanner input = new Scanner(System.in);
System.out.println("請(qǐng)輸入您要租用的天數(shù)!");
int c = input.nextInt();
System.out.println("請(qǐng)輸入您要租用的車輛的數(shù)量!");
int d = input.nextInt();
rental(c, rent, d);
}
}
public class RentCat {
public static void main(String[] args) {
Automobile audiA4 = new Automobile();//創(chuàng)建奧迪A4對(duì)象
Automobile azda6 = new Automobile();//創(chuàng)建馬自達(dá)6對(duì)象
Automobile pick_up = new Automobile();//創(chuàng)建皮卡雪6對(duì)象
Automobile jinlong = new Automobile();//創(chuàng)建金龍對(duì)象
Automobile songhua = new Automobile();//創(chuàng)建松花江對(duì)象
Automobile iveco = new Automobile();//創(chuàng)建依維柯對(duì)象
System.out.println("歡迎來(lái)到噠噠租車系統(tǒng)!!");
System.out.println("您是否要租車,是按1,否按0");
Scanner input = new Scanner(System.in);
int a = input.nextInt();
if (a == 1) {
//租車價(jià)目表
System.out.println("您可租車的類型和價(jià)目表:");
audiA4.nature(1, "奧迪A4", 500, 4, 0);
azda6.nature(2, "馬自達(dá)6", 400, 4, 0);
pick_up.nature(3, "皮卡雪6", 450, 4, 2);
jinlong.nature(4, "金龍 ? ", 800, 20, 0);
songhua.nature(5, "松花江", 400, 0, 4);
iveco.nature(6, "依維柯", 1000, 0, 20);
} else {
System.out.println("請(qǐng)關(guān)閉系統(tǒng)!!");
}
System.out.println("請(qǐng)輸入您要租用的汽車序號(hào):");
int b = input.nextInt();
if (b == 1) {
audiA4.nature(1, "奧迪A4", 500, 4, 0);
Automobile.dowork(500);
} else if (b == 2) {
azda6.nature(2, "馬自達(dá)6", 400, 4, 0);
Automobile.dowork(400);
} else if (b == 3) {
pick_up.nature(3, "皮卡雪6", 450, 4, 2);
Automobile.dowork(450);
} else if (b == 4) {
jinlong.nature(4, "金龍 ? ? ? ", 800, 20, 0);
Automobile.dowork(800);
} else if (b == 5) {
songhua.nature(5, "松花江", 400, 0, 4);
Automobile.dowork(400);
} else if (b == 6) {
iveco.nature(6, "依維柯", 1000, 0, 20);
Automobile.dowork(1000);
} else {
System.out.println("您的輸入有誤!!");
}
}
}
2017-08-17
可以選擇交互式對(duì)話框輸入。個(gè)人建議
2017-08-09
輸出結(jié)果