精慕门4361104
2017-10-20 22:30
求源码
把所有的代码放在一起了,不然不好弄
package com.imooc.dd;
import java.util.Scanner;
public class main {
public main(String[] args) {
int[] cx = null; //存放出借车的序列
int num = 0; //所有出借车的价格之和
Car[] cars = {new ZaiHuoCar("松花江", 800, 3, 5), new ZaiHuoCar("松花江plus", 2000, 0, 20), new ZaiKeCar("奥迪", 300, 2, 20), new ZaiKeCar("金龙", 800, 30, 4), new PiKaCar("皮卡1", 200, 4, 2), new PiKaCar("皮卡2", 500, 2, 4)};
Scanner input = new Scanner(System.in);
System.out.println("欢迎使用达达租车系统:");
System.out.println("你是否要租车:1是 0否");
int t = input.nextInt();
if (t == 1) {
System.out.println("您可租车的类型及其价目表:");
System.out.println("序号\t汽车类型\t汽车名称\t租金\t容量");
for (int i = 0; i < cars.length; i++) {
System.out.println((i+1) + ".\t" + cars[i].user());
}
System.out.println("请输入您要租车的数量:");
int q = input.nextInt(); //出借车的数量
cx = new int[q];
for (int i = 0; i < q; i++) {
System.out.println("请输入第" + (i+1) + "辆车的序列:");
cx[i] = input.nextInt();
}
System.out.println("请输入您要租车的天数:");
int day = input.nextInt(); //出借车的天数
System.out.println("您的帐单:");
System.out.println("***可载人的车有:");
for (int i = 0; i < q; i++) {
if (cars[cx[i]-1].zr != 0) {
System.out.print("\t" + cars[cx[i]-1].name);
num += cars[cx[i]-1].zr;
}
}
System.out.println("\t共载人:" + num + "人");
num = 0;
System.out.println("***载货的车有:");
for (int i = 0; i < q; i++) {
if(cars[cx[i]-1].zh != 0) {
System.out.print("\t" + cars[cx[i]-1].name);
num += cars[cx[i]-1].zh;
}
}
System.out.println("\t共载货:" + num + "吨");
num = 0;
for (int i = 0; i < q; i++) {
num += cars[cx[i]-1].penny;
}
System.out.print("***租车总价格:" + num*day);
} else {
System.out.println("退出系统!");
}
}
/**
* 所有车的父类
*/
public abstract class Car {
String kinds; //车的种类
String name; //车的名字
int penny; //租车每天的价格
int zr; //载人量
int zh; //载货量
public abstract String user();
}
/**
* 载货车
*/
public class ZaiHuoCar extends Car {
public ZaiHuoCar(String name, int penny, int zr, int zh) {
super.name = name;
super.penny = penny;
if (zr != 0) {
super.zr = 0;
}
if (zh <= 0) {
System.out.println("输入的载货量有误!");
} else if (zh >0 && zh < 10) {
super.kinds = "轻型货运车";
super.zh = zh;
} else {
super.kinds = "重型货运车";
super.zh = zh;
}
}
@Override
public String user() {
return kinds + "\t" + name + "\t" + penny + "元/天\t载货:" + zh + "吨";
}
}
/**
* 载客车
*/
public class ZaiKeCar extends Car {
public ZaiKeCar(String name, int penny, int zr, int zh) {
super.name = name;
super.penny = penny;
if (zh != 0) {
super.zh = 0;
}
if (zr <= 0) {
System.out.println("输入的载人数有误!");
} else if (zr >0 && zr < 10) {
super.kinds = "小客车";
super.zr = zr;
} else {
super.kinds = "大客车";
super.zr = zr;
}
}
@Override
public String user() {
return kinds + "\t" + name + "\t" + penny + "元/天\t载人:" + zr + "人";
}
}
/**
* 皮卡车
*/
public class PiKaCar extends Car {
public PiKaCar(String name, int penny, int zr, int zh) {
super.name = name;
super.penny = penny;
super.kinds = "皮卡";
if (zr <= 0 || zr > 5) {
System.out.println("输入的载人数有误!");
} else {
super.zr = zr;
if (zh > 0 && zh < 5) {
super.zh = zh;
} else {
System.out.println("输入的载货量有误!");
}
}
}
@Override
public String user() {
return kinds + "\t" + name + "\t" + penny + "元/天\t载人:" + zr + "人 载货:" + zh + "吨";
}
}
}
Java入门第二季 升级版
530652 学习 · 6091 问题
相似问题