/2016年3月28日 11:27:24
@author 围城
/
package com.imocc;
public abstract class Car {
public String name;
public double price;
public int Capacity;//人容量
public int GCapacity;//物容量
@Override
public String toString() {
return "Car [name=" + name + ", price=" + price + ", Capacity=" + Capacity + ", GCapacity=" + GCapacity + "]";
}
}
package com.imocc;
public class PeGoodsCar extends Car{
public PeGoodsCar(String string, int i, int j,int k) {
name = string;
price =i;
Capacity =j;
GCapacity =k;
// TODO Auto-generated constructor stub
}
}
package com.imocc;
public class PersonCar extends Car {
public PersonCar(String string, int i, int j) {
name = string;
price =i;
Capacity =j;//人容量
// TODO Auto-generated constructor stub
}
}
package com.imocc;
public class GoodsCar extends Car {
public GoodsCar(String string, int i, int j) {
name = string;
price =i;
GCapacity =j;//物容量
// TODO Auto-generated constructor stub
}
}
package com.imocc;
import java.util.Scanner;
public class Main {
public static void main(String[] args){
Car car[]={new PersonCar("奥迪A4",500, 4),
new PersonCar("马自达",800,20),
new PersonCar("松花江",500, 20),
new GoodsCar("皮卡雪",400, 4),
new GoodsCar("金龙",400, 4),
new PeGoodsCar("依维柯",500,5,4)};
Scanner sc = new Scanner(System.in);
Car car2[]=car;
Car car3[]=car;
System.out.println("欢迎使用迪迪租车系统!");
System.out.println("请输入1:租车 2:退出");
int i = sc.nextInt();
if (i == 1) {
System.out.println("您可租车的类型及价目表:");
System.out.println("序号 汽车名称 租金 容量");
System.out.println("1: 奥迪A4 500元/天 载人:4人");
System.out.println("2: 马自达 800元/天 载人:20人");
System.out.println("3: 松花江 500元/天 载人:20人");
System.out.println("4: 皮卡雪 400元/天 载物:4吨");
System.out.println("5: 金龙 400元/天 载物:4吨");
System.out.println("6: 依维柯 500元/天 载人:5人 载物4吨");
System.out.println("请输入您要租车的数量:");
int num = sc.nextInt();
int sum = 0;
int b=0;
int c=0;
for (int j = 1; j <= num; j++) {
System.out.println("您要租的第" + j + "辆车序号是:");
int k = sc.nextInt();
if(k==1||k==2||k==4)
{
car2[b].name=car[k-1].name;
b++;
}
else if(k==3||k==5)
{
car3[c].name= car[k-1].name;
c++;
}
else if(k==6){
car2[b].name =car[5].name;
car3[c].name =car[5].name;
}
else
System.out.println("输入有误!");
switch (k) {
case 1:
sum = sum + 500;
break;
case 2:
sum = sum + 800;
break;
case 3:
sum = sum + 500;
break;
case 4:
sum = sum + 400;
break;
case 5:
sum = sum + 400;
break;
case 6:
sum = sum + 500;
break;
}
}
System.out.println("请问你需要租借几天:");
int h = sc.nextInt();
System.out.println("***载人的车有:");
for(int x=0;x<b;x++)
{
System.out.print(""+car2[b-1].name+"\t");
b--;
}
System.out.println();
System.out.print("***载货的车有:");
for(int x=0;x<c;x++)
{
System.out.print(""+car3[c-1].name);
c--;
}
System.out.println();
System.out.println("共需要支付: " + (h * sum) + "¥");
} else
return;
}
}
热门评论
挺好