package com.ddzuche; public class Car { protected int num; protected String name ; protected int rental; protected int peopleNum; protected int weight; public int getNum(){ return num; } public String getName(){ return name; } public int getRental(){ return rental; } public int getPeopleNum(){ return peopleNum; } public int getWeight(){ return weight; } public void setName(String name){ this.name=name; } public void setRental(int rental){ this.rental=rental; } public void setPeopleNum(int peopleNum){ this.peopleNum=peopleNum; } public void setWeight(int weight){ this.weight=weight; } public void setNum(int num){ this.weight=num; } }
package com.ddzuche; public class PassengerCar extends Car { public PassengerCar(int m_num, String m_name, int m_rental,int m_peopleNum ){ this.num=m_num; this.name=m_name; this.peopleNum=m_peopleNum; this.rental=m_rental; } }
package com.ddzuche; public class Pickup extends Car { public Pickup(int m_num, String m_name, int m_rental, int m_peopleNum,int m_weight){ this.num=m_num; this.name=m_name; this.peopleNum=m_peopleNum; this.rental=m_rental; this.weight=m_weight; } }
package com.ddzuche; public class Trunk extends Car { public Trunk(int m_num, String m_name, int m_rental,int m_weight){ this.num=m_num; this.name=m_name; this.weight=m_weight; this.rental=m_rental; } }
package com.ddzuche; import java.util.Scanner; import java.util.Arrays; public class Demo { public static void main(String[] args) { // TODO Auto-generated method stubt Car[] cars={new PassengerCar(1,"奥迪A4",500,3), new Trunk(2,"东风200",500,10), new Pickup(3,"皮卡",300,3,5), new PassengerCar(4,"奥迪A6",600,3), new PassengerCar(5,"丰田",300,3), new Trunk(6,"解放60",500,12), new Pickup(7,"皮卡200",600,4,8)}; System.out.println("*****欢迎使用答答租车系统******"); System.out.println("您是否要租车:1是 0否"); Scanner scan =new Scanner(System.in); int input=scan.nextInt(); if(input==1){ System.out.println("您可租车的类型及其价目表"); System.out.println("序号"+"\t汽车名称"+"\t租金"+"\t载客"+"\t载货"); for(int i=0;i<=6;i++){ System.out.println(cars[i].getNum()+"\t"+cars[i].getName()+"\t"+cars[i].getRental()+"\t"+cars[i].getPeopleNum()+"\t"+cars[i].getWeight()); } int totalPrice=0; int rentdays=0; String[] pc= new String[5]; String[] tc= new String[4]; int n=0; int m=0; System.out.println("请输入你要租车的数量"); int carsNum=scan.nextInt(); for (int j=0;j<carsNum;j++){ System.out.println("请输入第"+(j+1)+"辆车的序号"); int carNum=scan.nextInt(); totalPrice+=cars[carNum-1].getRental(); if(cars[carNum-1].peopleNum>0){ pc[n]=cars[carNum-1].getName(); n=n+1; } if(cars[carNum-1].weight>0){ tc[m]=cars[carNum-1].getName(); m=m+1; } } System.out.println("请输入租车时间:"); rentdays=scan.nextInt(); scan.close(); System.out.println("您的账单:"); System.out.println("*****可载人的车有*****"); System.out.println(Arrays.toString(pc)); System.out.println("*****可载货的车有*****"); System.out.println(Arrays.toString(tc)); System.out.println("租车总价格为;"+totalPrice*rentdays); } } }