交作業(yè)了,只提交了main函數(shù)部分
package com.test.car;
import java.util.Scanner;
public class MainFunc {
?public static void main(String[] args) {
??// 1 初始化車輛信息
??Car[] cars = {
????new LittleCar("卡羅拉", 100, 5),
????new LittleCar("奧迪A2", 200, 4),
????new Bus("宇通客車", 300, 25),
????new Bus("宇通客車", 400, 40),
????new Truck("福田", 500, 20),
????new Truck("江淮", 600, 12),
????new Pickup("福特猛禽", 1000, 3, 2),
????new Pickup("長城風駿", 2000, 3, 3)
??};
??
??// 租車系統(tǒng)實現(xiàn)部分
??// (1)租車提示
??System.out.println("歡迎使用答答租車系統(tǒng)!");
??System.out.println("您是否要租車:1是? 0否");
??
??// (2)確認是否租車
??Scanner sc = new Scanner(System.in);
??if(!sc.next().equals("1")){
???System.out.println("您已經(jīng)退出租車系統(tǒng)");
???sc.close();
???return;?
??}else{
???System.out.println("您可以租用的車輛類型及價格表:");
???System.out.println("序號"+"\t"+"車輛名稱"+"\t"+"租金"+"\t"+"容量");
???
??// (3)顯示所有待出租車輛信息
???for(int i=0; i<cars.length; i++)
???{
????System.out.print((i+1)+".\t");
????cars[i].showCarInfo();
???}
???
??// (4)選車
???int[] array = new int[cars.length];
???System.out.println("請輸入您要租用車輛的數(shù)量:");
???int rentNum = sc.nextInt();
???int loopi, serialNum;
???for(loopi=0;loopi<rentNum;loopi++){
????System.out.println("請輸入第"+(loopi+1)+"輛車的序號:");
????serialNum = sc.nextInt();
????if(serialNum > cars.length)
????{
?????sc.close();
?????System.out.println("車輛序號超出范圍,請重新選擇。");
?????return;
????}
????array[loopi] = serialNum;
???}
???
??// (5)顯示待支付總租金
???int totalMoney = 0;?
???for(int j=0; j<loopi; j++)
???{
????totalMoney += cars[array[j]-1].getRentMoney();
???}
??
???sc.close();
???System.out.println("您需要支付的總租金為:"+ totalMoney);?
??}
?}
}
2018-08-05
還可以