package com.company.imooc;
/**
* Created by junius on 2016/11/8.
*/
public class Audi extends Car {
public Audi() {
}
public Audi(String name, double price, int capacity) {
super(name, price, capacity);
}
}
package com.company.imooc;
/**
* Created by junius on 2016/11/8.
*/
public class Car {
public String name;
public double price;
private int capacity;
private double weight;
public int getCapacity() {
return capacity;
}
public void setCapacity(int capacity) {
this.capacity = capacity;
}
public double getWeight() {
return weight;
}
public void setWeight(double weight) {
this.weight = weight;
}
public Car() {
}
public Car(String name, double price, int capacity, double weight) {
this.name = name;
this.price = price;
this.capacity = capacity;
this.weight = weight;
}
public Car(String name, double price, int capacity) {
this.name = name;
this.price = price;
this.capacity = capacity;
}
public Car(String name, double price, double weight) {
this.name = name;
this.price = price;
this.weight = weight;
}
}
package com.company.imooc;
/**
* Created by junius on 2016/11/8.
*/
public class Jinglong extends Car {
public Jinglong() {
}
public Jinglong(String name, double price, int capacity) {
super(name, price, capacity);
}
}
package com.company.imooc;
/**
* Created by junius on 2016/11/8.
*/
public class Mazda extends Car{
public Mazda() {
}
public Mazda(String name, double price, int capacity) {
super(name, price, capacity);
}
}
package com.company.imooc;
/**
* Created by junius on 2016/11/8.
*/
public class Pickup extends Car {
public Pickup() {
}
public Pickup(String name, double price, int capacity, double weight) {
super(name, price, capacity, weight);
}
}
package com.company.imooc;
/**
* Created by junius on 2016/11/8.
*/
public class Songhuajiang extends Car {
public Songhuajiang() {
}
public Songhuajiang(String name, double price, double weight) {
super(name, price, weight);
}
}
package com.company.imooc;
/**
* Created by junius on 2016/11/8.
*/
public class Yiweik extends Car {
public Yiweik() {
}
public Yiweik(String name, double price, double weight) {
super(name, price, weight);
}
}
import com.company.imooc.*;
import java.util.Scanner;
public class TestDemo {
public static void main(String[] args){
pickBAuto();
}
private static void pickBAuto() {
Car c1 = new Audi("Audi A4", 500, 4);
Car c2 = new Mazda("Mazda-6", 400, 4);
Car c3 = new Pickup("Pickup", 450, 4, 2);
Car c4 = new Jinglong("金龙", 800, 20);
Car c5 = new Songhuajiang("松花江", 400, 4);
Car c6 = new Yiweik("依维柯", 1000, 20);
System.out.println("=====>欢迎使用哒哒租车系统<=====");
System.out.println("您是否要租车:1-是 0-否");
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
if (0 == x) {
System.out.println("欢迎下次使用!");
return;
}
System.out.println("您可租车的类型及其价目表:");
System.out.println("序号\t车型\t\t租金\t\t容量");
System.out.println("1.\t" + c1.name + "\t\t" + c1.price + "元/天\t\t载人:" + c1.getCapacity() + "人");
System.out.println("2.\t" + c2.name + "\t\t" + c2.price + "元/天\t\t载人:" + c2.getCapacity() + "人");
System.out.println("3.\t" + c3.name + "\t\t" + c3.price + "元/天\t\t载人:" + c3.getCapacity() + "人,载货" + c3.getWeight() + "吨");
System.out.println("4.\t" + c4.name + "\t\t" + c4.price + "元/天\t\t载人:" + c4.getCapacity() + "人");
System.out.println("5.\t" + c5.name + "\t\t" + c5.price + "元/天\t\t载货:" + c5.getWeight() + "吨");
System.out.println("6.\t" + c6.name + "\t\t" + c6.price + "元/天\t\t载货:" + c6.getWeight() + "吨");
System.out.println("请输入您要租汽车数量:");
Scanner sc2 = new Scanner(System.in);
int y = sc2.nextInt();
double totalPrice = 0;
int sumCapacity = 0;
int sumWeight = 0;
StringBuilder str1 = new StringBuilder();
StringBuilder str2 = new StringBuilder();
for (int i = 1; i < y + 1; i++) {
System.out.println("请输入第 " + i + " 辆车的序号");
Scanner sc3 = new Scanner(System.in);
int z = sc3.nextInt();
switch (z) {
case 1:
totalPrice = totalPrice + c1.price;
sumCapacity = sumCapacity + c1.getCapacity();
str1.append(c1.name+'\t');
break;
case 2:
totalPrice = totalPrice + c2.price;
sumCapacity = sumCapacity + c2.getCapacity();
str1.append(c2.name+'\t');;
break;
case 3:
totalPrice += c3.price;
sumCapacity += c3.getCapacity();
sumWeight += c3.getWeight();
str1.append(c3.name+'\t');;
str2.append(c3.name+'\t');;
break;
case 4:
totalPrice += c4.price;
sumCapacity += c4.getCapacity();
str1.append(c4.name+'\t');;
break;
case 5:
totalPrice += c5.price;
sumWeight += c5.getWeight();
str2.append(c5.name+'\t');;
break;
case 6:
totalPrice += c6.price;
sumWeight += c6.getWeight();
str2.append(c6.name+'\t');;
break;
}
}
System.out.println("请输入租车天数:");
Scanner sc4 = new Scanner(System.in);
int days = sc4.nextInt();
totalPrice *= days;
System.out.println("您的账单:");
if(0==sumWeight){
if(0!=sumCapacity){
System.out.print(str1.toString());
System.out.println("可载人:"+sumCapacity+" 人");
}
}else {
if(0!=sumCapacity){
System.out.print(str1.toString());
System.out.println("可载人:"+sumCapacity+" 人");
}
System.out.print(str2.toString());
System.out.println("可载货:"+sumWeight+" 吨");
}
System.out.println("总计:" + totalPrice+" 元");
}
}
点击查看更多内容
16人点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦