写的第一个项目大家看看
package com.dinyanqing;
public abstract class taxi {
public String name;
public double rent;
int id;
public String getName() {
return name;
}
public double getRent() {
return rent;
}
public void show() {
System.out.println("1");
}
public int getId() {
return id;
}
}
package com.dinyanqing;
public class passengerCar extends taxi {
private double peopleCapacity;//载客量
public passengerCar(int id ,String name,double rent,double peopleCapacity) {
this.name=name;
this.rent=rent;
this.peopleCapacity=peopleCapacity;
this.id=id;
}
public void show() {
System.out.println(id+"\t"+name+"\t"+rent+"元/天"+"\t"+"载人:"+peopleCapacity+"人");
}
public double getPeopleCapacity() {
return peopleCapacity;
}
public void setPeopleCapacity(double peopleCapacity) {
this.peopleCapacity=peopleCapacity;
}
}
package com.dinyanqing;
public class PickUp extends taxi {
private double cargoCapacity;
private double peopleCapacity;
public PickUp(int id,String name,double rent,double peopleCapacity,double cargoCapacity) {
this.name=name;
this.rent=rent;
this.peopleCapacity=peopleCapacity;
this.cargoCapacity=cargoCapacity;
this.id=id;
}
public void show() {
System.out.println(id+"\t"+name+"\t"+rent+"元/天"+"\t"+"载人:"+peopleCapacity+"人"+" 载货:"+cargoCapacity+"吨");
}
public double getPeopleCapacity() {
return peopleCapacity;
}
public void setPeopleCapacity(double peopleCapacity) {
this.peopleCapacity=peopleCapacity;
}
public double getCargoCapacity() {
return cargoCapacity;
}
public void setCargoCapacity(double cargoCapacity) {
this.cargoCapacity = cargoCapacity;
}
public double getRent() {
return rent;
}
}
package com.dinyanqing;
public class Trunk extends taxi {
private double cargoCapacity;
public Trunk(int id,String name,double rent,double cargoCapacity) {
this.name=name;
this.rent=rent;
this.cargoCapacity=cargoCapacity;
this.id=id;
}
public void show() {
System.out.println(id+"\t"+name+"\t"+rent+"元/天"+"\t"+"载货:"+cargoCapacity+"吨");
}
public double getCargoCapacity() {
return cargoCapacity;
}
public void setCargoCapacity(double cargoCapacity) {
this.cargoCapacity = cargoCapacity;
}
}
package com.dinyanqing;
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
taxi[] carsForRent={new passengerCar(1,"奥迪A4",500,4),new passengerCar(2,"奔驰S600",600,4),new PickUp(3,"皮卡雪", 450, 4, 2),
new Trunk(4,"松花江",400 , 4)};
System.out.println("欢迎使用答答租车系统:");
System.out.println("你是否需要租车:1是0否");
@SuppressWarnings("resource")
Scanner scan=new Scanner(System.in);
String input=scan.next();
if(input.equals("1")) {
System.out.println("你可租车的类型及其价目表");
System.out.println("序号\t汽车名称\t租金\t\t容量");
}
else {
System.out.println("滚吧!");
System.exit(0);
}
for(taxi cout:carsForRent){
cout.show();
}
System.out.println("请输入您要租车的数量:");
int c[]=new int [] {500,600,450,400} ;
double sum=0;
int input1=scan.nextInt();
if (input1>4||input1<=0) {
System.out.println("输入错误请退出重试");
System.exit(0);
}
else {
for(int j=1;j<=input1;j++) {
System.out.println("请输入第"+j+"辆车的序号:");
int input2=scan.nextInt();
sum+=c[(input2)-1];
}
}
System.out.println("请输入租车天数:");
int input3=scan.nextInt();
double price=sum*input3;
System.out.println("租车总价格:");
System.out.println(price);
}
}