福尔摩灰
2016-08-27 11:18:30浏览 2390
public abstract class Car {
public String name;
public int price;
public void pr(){
System.out.println(name + "\t" + price + "元/天\t");
}
}
public class PeopleCar extends Car {
public int people ;
@Override
public void pr() {
// TODO 自动生成的方法存根
System.out.println(name + "\t" + price + "\t载人量:" + people +"人");
}
public PeopleCar(String s,int a,int b)
{
this.name = s;
this.price = a;
this.people = b;
}
}
public class PickUp extends Car {
public int people ;
public int goods;
@Override
public void pr() {
// TODO 自动生成的方法存根
System.out.println(name + "\t" + price + "\t载人量:" + people +"人" +",载货量:"+goods +"吨");
}
public PickUp(String a,int b,int c,int d) {
// TODO 自动生成的构造函数存根
this.name = a;
this.price = b;
this.people = c;
this.goods = d;
}
}
public class Truck extends Car {
public int goods;//载货量
@Override
public void pr() {
// TODO 自动生成的方法存根
System.out.println(name + "\t" + price + "\t载货量:" + goods +"吨");
}
public Truck(String s,int a,int b)
{
this.name = s;
this.price = a;
this.goods = b;
}
}
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
// TODO 自动生成的方法存根
Test test = new Test();
Car[] car={
new PeopleCar("奥迪A4",500,4),
new PeopleCar("马自达6", 400,4),
new PickUp("皮卡雪6", 450, 4, 2),
new PeopleCar("金龙", 800, 20),
new Truck("松花江", 400, 4),
new Truck("依维柯", 1000, 20),
};
int weather;
int number,a;
int day;
int sum = 0;
Scanner input = new Scanner(System.in);
System.out.println("是否租车?1.是 0.不是");
weather = input.nextInt();
if(weather == 1)
{
System.out.println("可租的汽车类型及价格表");
System.out.println("序号\t汽车名称\t租金\t容量\t");
for(int i = 0;i<6;i++)
{
System.out.print( (i+1) + "\t" );
car[i].pr();
}
System.out.println("请输入您要租的车辆数:");
number = input.nextInt();
for(int i = 0; i<number; i++)
{
System.out.println("请输入要选的车的序号:");
a=input.nextInt();
sum += car[a-1].price;
}
System.out.println("请输入租车天数:");
day = input.nextInt();
System.out.println("总的租金为:" + day*sum +"元");
}
else{System.out.println("退出租车系统");}
}
}