package Rentalcar;
public abstract class Cars {
private int no;
private String name;
private int rent;
private int carrypeople;
private int carrygoods;
public Cars(int no,String name,int rent,int carrypeople,int carrygoods) {
this.no=no;
this.name=name;
this.rent=rent;
this.carrypeople=carrypeople;
this.carrygoods=carrygoods;
}
public String getName() {
return name;
}
public int getRent() {
return rent;
}
public int getCarrypeople() {
return carrypeople;
}
public int getCarrygoods() {
return carrygoods;
}
public int getNo() {
return no;
}
public abstract void Print();
}
package Rentalcar;
public class PersonCars extends Cars {
public PersonCars(int no, String name, int rent, int carrypeople, int carrygoods) {
super(no, name, rent, carrypeople, 0);
}
public void Print() {
System.out.println(super.getNo()+". "+super.getName()+"\t"+super.getRent()+"/天\t 载人:"
+super.getCarrypeople()+"人");
}
}
package Rentalcar;
public class Trunk extends Cars {
public Trunk(int no,String name, int rent, int carrygoods) {
super(no,name, rent,0, carrygoods);
}
public void Print() {
System.out.println(super.getNo()+". "+super.getName()+"\t"+super.getRent()+"/天\t 载货:"
+super.getCarrygoods()+"吨");
}
}
package Rentalcar;
public class PiKa extends Cars {
public PiKa(int no ,String name, int rent, int carrypeople, int carrygoods) {
super(no ,name, rent, carrypeople, carrygoods);
}
public void Print() {
System.out.println(super.getNo()+". "+super.getName()+"\t"+super.getRent()+"/天\t 载人:"
+super.getCarrypeople()+"人 载货:"+super.getCarrygoods()+"吨");
}
}
package Rentalcar;
import java.util.*;
public class Test {
public static void main(String[] args) {
int sumMoney=0;
int sumPeople=0;
int sumGoods=0;
Cars carForRent[]= {new PersonCars(1,"奥迪A4",500,4, 0),
new PersonCars(2,"马自达6",400,4,0),
new PersonCars(3,"金龙",800,20,0),
new Trunk(4,"松花江",400,4),
new Trunk(5,"依维柯",1000,20),
new PiKa(6,"皮卡雪",450,4,4)
};
System.out.println("欢迎使用答答租车系统:");
System.out.println("您是否要租车:\n 提示:租车输入1 不租车输入0");
Scanner input=new Scanner(System.in);
System.out.print("请输入:");
String num=input.next();
if(num.equals("1")) {
System.out.println("您可租车的类型及其价目表:");
System.out.println("序号 汽车名称\t租金\t\t容量");
for(int i=0;i<carForRent.length;i++)
carForRent[i].Print();
System.out.print("请输入您要租车的数量: ");
int num2=input.nextInt();
int Array[]=new int [num2];
for(int i=0;i<num2;i++) {
System.out.print("请输入第"+(i+1)+"辆车的序号: ");
int num3=input.nextInt();
num3-=1;
Array[i]=num3;
}
System.out.print("请输入租车天数:");
int days=input.nextInt();
for(int i=0;i<Array.length;i++) {
sumPeople+=carForRent[Array[i]].getCarrypeople();
sumGoods+=carForRent[Array[i]].getCarrygoods();
sumMoney+=carForRent[Array[i]].getRent();
}
sumMoney*=days;
System.out.println("");
System.out.println("请稍等。。。。。\n您的账单:");
if(sumPeople!=0) {
System.out.println("***可载人的车有:");
for(int i=0;i<Array.length;i++) {
if(Array[i]+1==4||Array[i]+1==5)
continue;
System.out.print(" "+carForRent[Array[i]].getName()+" ");
}
System.out.println("共载"+sumPeople+"人");
}
if(sumGoods!=0) {
System.out.println("***可载货的车有:");
for(int i=0;i<Array.length;i++) {
if(Array[i]+1==1||Array[i]+1==2||Array[i]+1==3)
continue;
System.out.print(" "+carForRent[Array[i]].getName()+" ");
}
System.out.println("共载货:"+sumGoods+"吨");
}
System.out.println("***租车总价格:\n "+sumMoney+"元");
}else {
System.out.println("\n虽然只是心动了一下,期待您的下次光临");
}
}
}
打开App,阅读手记