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("请挑选你想选择的车辆!");

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("请输入你想要租车的数量:");

int sum = sc.nextInt();

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

double m1 = 500 * sum;

System.out.println("请输入你想要租用的天数:");

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

break;

case 2:

System.out.println("请输入你想要租车的数量:");

sum = sc.nextInt();

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

m1 = 400 * sum;

System.out.println("请输入你想要租用的天数:");

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

break;

case 3:

System.out.println("请输入你想要租车的数量:");

sum = sc.nextInt();

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

m1 = 450 * sum;

System.out.println("请输入你想要租用的天数:");

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

break;

case 4:

System.out.println("请输入你想要租车的数量:");

sum = sc.nextInt();

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

m1 = 800 * sum;

System.out.println("请输入你想要租用的天数:");

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

break;

case 5:

System.out.println("请输入你想要租车的数量:");

sum = sc.nextInt();

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

m1 = 400 * sum;

System.out.println("请输入你想要租用的天数:");

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

break;

case 6:

System.out.println("请输入你想要租车的数量:");

sum = sc.nextInt();

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

m1 = 1000 * sum;

System.out.println("请输入你想要租用的天数:");

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

break;}

}

else{

System.out.println("输入有误,请重新输入!");

continue;}

}while (true) ;

}

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 【程序1】 题目:古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第三个月后每个月又生一对兔...
    叶总韩阅读 5,187评论 0 41
  • Java经典问题算法大全 /*【程序1】 题目:古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子...
    赵宇_阿特奇阅读 1,981评论 0 2
  • 1 顺序语句 语句:使用分号分隔的代码称作为一个语句。 注意:没有写任何代码只是一个分号的时候,也是一条语句,...
    哈哈哎呦喂阅读 424评论 0 0
  • 比较笨就把所有的都复制过来吧,以后再整理://for(表达式1,条件表达式;表达式2){// 语句块//} pu...
    人鱼姑娘5394阅读 710评论 0 0
  • 1. Java基础部分 基础部分的顺序:基本语法,类相关的语法,内部类的语法,继承相关的语法,异常的语法,线程的语...
    子非鱼_t_阅读 31,874评论 18 399