18 代碼2

package qwr;

import java.util.Scanner;

/**

* Created by Administrator on 2016/12/2.

*/

public class Initial {

static int is = 0;

public static void main(String[] args) {

Initial it = new Initial();

System.out.println("請問您是否需要租車?");

System.out.println("輸入:1進入挑選 輸入0:退出");

do {

Scanner sc = new Scanner(System.in);

int isof = sc.nextInt();

if (isof == 0) {

System.out.println("歡迎您下次光臨!");

break;

} else if (isof == 1) {

System.out.println("請?zhí)暨x你想選擇的車輛!");

is = isof;

it.test();

break;

} else {

System.out.println("輸入有誤,請重新輸入!");

continue;

}

}while (true);

}

public void test() {

Didi[] carsForRent = {

new PassengerCar("奧迪A4", 500, 4),

new PassengerCar("馬自達6", 500, 4),

new PickUp("皮卡雪6", 450, 4, 2),

new PassengerCar("金龍", 800, 20),

new CurrentCar("松花江", 400, 4),

new CurrentCar("依維柯", 1000, 20)};

int i = 1;

if (is == 1) {

for (Didi currentCar : carsForRent) {

if (currentCar instanceof PassengerCar) {

System.out.println("" + i + "\t" + currentCar.getName() + "\t" + currentCar.getRentm() + "元/天" + "\t" + "載人:" + currentCar.getTake() + "人");

i++;

} else if (currentCar instanceof PickUp) {

System.out.println("" + i + "\t" + currentCar.getName() + "\t" + currentCar.getRentm() + "元/天" + "\t" + "載人:" + currentCar.getTake() + "人" + "載貨:" + currentCar.getTon() + "噸");

i++;

} else {

System.out.println("" + i + "\t" + currentCar.getName() + "\t" + currentCar.getRentm() + "元/天" + "\t" + "載貨:" + currentCar.getTon() + "噸");

i++;

}

}

}

double money = 0;

do {

System.out.println("請輸入你想要租車的序號(選購完成請輸入0):");

Scanner sc = new Scanner(System.in);

int n = sc.nextInt();

if (n == 0) {

System.out.println("歡迎您下次光臨!");

System.out.println("**租車總價格:" + money + "元");

System.out.println("**可載人的車有:");

int sumper = 0;

for (int x = 0; x < 6; x++) {

if (carsForRent[x].getRentsum() > 0 && carsForRent[x].getTake() > 0) {

System.out.print(carsForRent[x].getName() + "x" + carsForRent[x].getRentsum());

sumper = sumper + carsForRent[x].getRentsum() * carsForRent[x].getTake();

}}

if (sumper > 0) {

System.out.println("\t" + "可載人: " + sumper + "人");

}

else{

System.out.println("無車可載人!");

}

int ton = 0;

System.out.println("**可載貨的車有:");

for (int x = 0; x < 6; x++) {

if (carsForRent[x].getRentsum() > 0 && carsForRent[x].getTon() > 0) {

System.out.print(carsForRent[x].getName() + "x" + carsForRent[x].getRentsum());

ton = ton + carsForRent[x].getRentsum() * carsForRent[x].getTon();

}

}

if (ton > 0) {

System.out.println("\t" + "可載貨:" + ton + "噸");

} else {

System.out.println("無車可載貨!");

}

break;}

else if (n == 1 || n == 2 || n == 3 || n == 4 || n == 5 || n == 6) {

switch (n) {

case 1:

System.out.println("請輸入你想要租車的數(shù)量:");

int sum = sc.nextInt();

carsForRent[n - 1].setRentsum(sum);

double m1 = 500 * sum;

System.out.println("請輸入你想要租用的天數(shù):");

money = money + m1 * sc.nextInt();

break;

case 2:

System.out.println("請輸入你想要租車的數(shù)量:");

sum = sc.nextInt();

carsForRent[n - 1].setRentsum(sum);

m1 = 400 * sum;

System.out.println("請輸入你想要租用的天數(shù):");

money = money + m1 * sc.nextInt();

break;

case 3:

System.out.println("請輸入你想要租車的數(shù)量:");

sum = sc.nextInt();

carsForRent[n - 1].setRentsum(sum);

m1 = 450 * sum;

System.out.println("請輸入你想要租用的天數(shù):");

money = money + m1 * sc.nextInt();

break;

case 4:

System.out.println("請輸入你想要租車的數(shù)量:");

sum = sc.nextInt();

carsForRent[n - 1].setRentsum(sum);

m1 = 800 * sum;

System.out.println("請輸入你想要租用的天數(shù):");

money = money + m1 * sc.nextInt();

break;

case 5:

System.out.println("請輸入你想要租車的數(shù)量:");

sum = sc.nextInt();

carsForRent[n - 1].setRentsum(sum);

m1 = 400 * sum;

System.out.println("請輸入你想要租用的天數(shù):");

money = money + m1 * sc.nextInt();

break;

case 6:

System.out.println("請輸入你想要租車的數(shù)量:");

sum = sc.nextInt();

carsForRent[n - 1].setRentsum(sum);

m1 = 1000 * sum;

System.out.println("請輸入你想要租用的天數(shù):");

money = money + m1 * sc.nextInt();

break;}

}

else{

System.out.println("輸入有誤,請重新輸入!");

continue;}

}while (true) ;

}

}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

  • 【程序1】 題目:古典問題:有一對兔子,從出生后第3個月起每個月都生一對兔子,小兔子長到第三個月后每個月又生一對兔...
    葉總韓閱讀 5,229評論 0 41
  • Java經(jīng)典問題算法大全 /*【程序1】 題目:古典問題:有一對兔子,從出生后第3個月起每個月都生一對兔子,小兔子...
    趙宇_阿特奇閱讀 2,084評論 0 2
  • 1 順序語句 語句:使用分號分隔的代碼稱作為一個語句。 注意:沒有寫任何代碼只是一個分號的時候,也是一條語句,...
    哈哈哎呦喂閱讀 482評論 0 0
  • 比較笨就把所有的都復制過來吧,以后再整理://for(表達式1,條件表達式;表達式2){// 語句塊//} pu...
    人魚姑娘5394閱讀 765評論 0 0
  • 1. Java基礎部分 基礎部分的順序:基本語法,類相關的語法,內(nèi)部類的語法,繼承相關的語法,異常的語法,線程的語...
    子非魚_t_閱讀 34,822評論 18 399

友情鏈接更多精彩內(nèi)容