搞了一個下午才寫出這些,求大神指點
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("序號:" + num + "\t汽車名:" + name + "\t 日租金:" + rent + "元" + "\t 可載客量:" + busload + "人"
+ "\t 可載貨量:" + boatload + "噸");
}
//計算賬單
public static void rental(int days, int rent, int num) {
int rental = days * rent * num;
System.out.println("***您的賬單***");
System.out.println("租用天數:" + days + "\t租用數量:" + num + "\t 總金額:" + rental + "元");
}
//輸入租車信息
public static void dowork(int rent) {
Scanner input = new Scanner(System.in);
System.out.println("請輸入您要租用的天數!");
int c = input.nextInt();
System.out.println("請輸入您要租用的車輛的數量!");
int d = input.nextInt();
rental(c, rent, d);
}
}
public class RentCat {
public static void main(String[] args) {
Automobile audiA4 = new Automobile();//創建奧迪A4對象
Automobile azda6 = new Automobile();//創建馬自達6對象
Automobile pick_up = new Automobile();//創建皮卡雪6對象
Automobile jinlong = new Automobile();//創建金龍對象
Automobile songhua = new Automobile();//創建松花江對象
Automobile iveco = new Automobile();//創建依維柯對象
System.out.println("歡迎來到噠噠租車系統!!");
System.out.println("您是否要租車,是按1,否按0");
Scanner input = new Scanner(System.in);
int a = input.nextInt();
if (a == 1) {
//租車價目表
System.out.println("您可租車的類型和價目表:");
audiA4.nature(1, "奧迪A4", 500, 4, 0);
azda6.nature(2, "馬自達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("請關閉系統!!");
}
System.out.println("請輸入您要租用的汽車序號:");
int b = input.nextInt();
if (b == 1) {
audiA4.nature(1, "奧迪A4", 500, 4, 0);
Automobile.dowork(500);
} else if (b == 2) {
azda6.nature(2, "馬自達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
可以選擇交互式對話框輸入。個人建議
2017-08-09
輸出結果