编了7小时,请指教
package com.zhou.rentCar;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class test {
public static void main(String[] args) {
System.out.println("欢迎使用答答租车系统");
Scanner console=new Scanner(System.in);
System.out.println("您是否要租车:1是 0否");
int k=(console.nextInt());
if(k==1)
{
System.out.println("您可租用的车类型和价目表如下");
carAll ca=new carAll();
System.out.println("序号"+"\t"+"汽车名称"+"\t"+"租金 "+"\t"+"容量");
for(int i=0;i<6;i++){
if(ca.carCateloge().get(i) instanceof LoadCustomer)
{
System.out.println(ca.carCateloge().get(i).getId()+"\t"+ca.carCateloge().get(i).getName()+"\t"+ca.carCateloge().get(i).getPrice()+"元每天"+"\t"+"载人:"+ca.carCateloge().get(i).getLoadPeooleNum()+"人");
}
if(ca.carCateloge().get(i) instanceof LoadGoods)
{
System.out.println(ca.carCateloge().get(i).getId()+"\t"+ca.carCateloge().get(i).getName()+"\t"+ca.carCateloge().get(i).getPrice()+"元每天"+"\t"+"载货:"+ca.carCateloge().get(i).getLoadGoodsNum()+"吨");
}
if(ca.carCateloge().get(i) instanceof Pika)
{ System.out.println(ca.carCateloge().get(i).getId()+"\t"+ca.carCateloge().get(i).getName()+"\t"+ca.carCateloge().get(i).getPrice()+"元每天"+"\t"+"载人:"+ca.carCateloge().get(i).getLoadPeooleNum()+"人 "+"载货:"+ca.carCateloge().get(i).getLoadGoodsNum()+"吨");
}
}
System.out.println("请输入您要租车的数量");
int num=console.nextInt();
int id=0;
List <Integer> l=new ArrayList<Integer>();
//System.out.println(num);
for(int j=1;j<=num;j++)
{
System.out.println("请输入第"+j+"辆车的序号");
id=console.nextInt();
l.add(id);
}
System.out.println("请输入您要租车的天数");
int daynum=console.nextInt();
bill b=new bill();
b.billAll(l, num,daynum);
}
else if(k==0)
{
System.out.println("感谢您使用答答租车系统,再见");
}
else
{
System.out.println("您的输入有误");
}
}
}
//定义皮卡类型的车
package com.zhou.rentCar;
public class Pika extends car {
private int id;
private String name;
private String price;
private String rentday;
private String LoadPeooleNum;
private String LoadGoodsNum;
public Pika()
{
}
public Pika(int id, String name,String price,String LoadPeooleNum,String LoadGoodsNum )
{
this.id=id;
this.name=name;
this.price=price;
this.LoadPeooleNum=LoadPeooleNum;
this.LoadGoodsNum=LoadGoodsNum;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getPrice() {
return price;
}
public void setPrice(String price) {
this.price = price;
}
public String getLoadPeooleNum() {
return LoadPeooleNum;
}
public void setLoadPeooleNum(String loadPeooleNum) {
LoadPeooleNum = loadPeooleNum;
}
public String getLoadGoodsNum() {
return LoadGoodsNum;
}
public void setLoadGoodsNum(String loadGoodsNum) {
LoadGoodsNum = loadGoodsNum;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getRentday() {
return rentday;
}
public void setRentday(String rentday) {
this.rentday = rentday;
}
}
//定义货车类
package com.zhou.rentCar;
public class LoadGoods extends car {
private int id;
private String name;
private String price;
private String rentday;
private String LoadGoodsNum;
public LoadGoods(){}
public LoadGoods(int id, String name,String price,String LoadGoodsNum)
{
this.id=id;
this.name=name;
this.price=price;
this.LoadGoodsNum=LoadGoodsNum;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getPrice() {
return price;
}
public void setPrice(String price) {
this.price = price;
}
public String getLoadGoodsNum() {
return LoadGoodsNum;
}
public void setLoadGoodsNum(String loadGoodsNum) {
LoadGoodsNum = loadGoodsNum;
}
public String getRentday() {
return rentday;
}
public void setRentday(String rentday) {
this.rentday = rentday;
}
}
//定义客车类
package com.zhou.rentCar;
public class LoadCustomer extends car{
private int id;
private String name;
private String price;
private String rentday;
private String LoadPeooleNum;
public String getLoadPeooleNum() {
return LoadPeooleNum;
}
public void setLoadPeooleNum(String loadPeooleNum) {
LoadPeooleNum = loadPeooleNum;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getPrice() {
return price;
}
public void setPrice(String pirce) {
this.price = price;
}
public LoadCustomer()
{}
public LoadCustomer(int id, String name,String price,String LoadPeooleNum) {
this.id=id;
this.name=name;
this.price=price;
this.LoadPeooleNum=LoadPeooleNum;
}
public String getRentday() {
return rentday;
}
public void setRentday(String rentday) {
this.rentday = rentday;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
//取得车库中所有的车
package com.zhou.rentCar;
import java.util.ArrayList;
import java.util.List;
public class carAll {
List <car> carList;
String [] s={};
public carAll(){
carList=new ArrayList<car>();
}
// car car1=new LoadCustomer(1,"奥迪","500","4");
// car car2=new LoadCustomer(2,"马自达","400","4");
// car car3=new Pika(3,"皮卡雪","450","4","2");
// car car4=new LoadCustomer(4,"金龙","800","20");
// car car5=new LoadGoods(5,"松花江","400","4");
// car car6=new LoadGoods(6,"依维柯","1000","20");
public List<car> carCateloge()
{
car car1=new LoadCustomer(1,"奥迪","500","4");
car car2=new LoadCustomer(2,"马自达","400","4");
car car3=new Pika(3,"皮卡雪","450","4","2");
car car4=new LoadCustomer(4,"金龙","800","20");
car car5=new LoadGoods(5,"松花江","400","4");
car car6=new LoadGoods(6,"依维柯","1000","20");
carList.add(car1);
carList.add(car2);
carList.add(car3);
carList.add(car4);
carList.add(car5);
carList.add(car6);
return carList;
}
}
//定义车的父类
package com.zhou.rentCar;
public class car {
private int id;
private String name;
private String price;
private String LoadPeooleNum;
private String LoadGoodsNum;
public car()
{}
public String getLoadPeooleNum() {
return LoadPeooleNum;
}
public void setLoadPeooleNum(String loadPeooleNum) {
LoadPeooleNum = loadPeooleNum;
}
public String getLoadGoodsNum() {
return LoadGoodsNum;
}
public void setLoadGoodsNum(String loadGoodsNum) {
LoadGoodsNum = loadGoodsNum;
}
public String getPrice() {
return price;
}
public void setPrice(String price) {
this.price = price;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
//结帐
package com.zhou.rentCar;
import java.util.ArrayList;
import java.util.List;
public class bill {
public void billAll(List<Integer> id,int num,int daynum)
{
List <car>list1=new ArrayList();
List <car>list2=new ArrayList();
List <car>list3=new ArrayList();
carAll ca=new carAll();
for(int i=0;i<num;i++){
if(ca.carCateloge().get( id.get(i)-1) instanceof LoadCustomer){
//System.out.println("您租用的载人的车有"+ca.carCateloge().get(Integer.valueOf((String) id.get(i))).getName());
list1.add(ca.carCateloge().get( id.get(i)-1));
}
if(ca.carCateloge().get( id.get(i)-1) instanceof LoadGoods)
{
list2.add(ca.carCateloge().get( id.get(i)-1));
}
if(ca.carCateloge().get( id.get(i)-1) instanceof Pika)
{
list3.add(ca.carCateloge().get(id.get(i)-1));
}
}
int num1=0;
int num2=0;
int num3=0;
int num4=0;
int price1=0;
int price2=0;
int price3=0;
int priceAll=0;
System.out.print("****您租用的载客的车有:");
for(car c:list1)
{
System.out.print(c.getName()+" ");
num1=Integer.valueOf(c.getLoadPeooleNum())+num1;
price1=Integer.valueOf(c.getPrice())+price1;
}
System.out.println("共载人:"+num1+"人");
System.out.println();
System.out.print("****您租用的载货的车有:");
for(car c:list2)
{
System.out.print(c.getName()+" ");
num2=Integer.valueOf(c.getLoadGoodsNum())+num2;
price2=Integer.valueOf(c.getPrice())+price2;
}
System.out.println("共载货:"+num2+"吨");
System.out.println();
System.out.print("****您租用的皮卡车有:");
for(car c:list3)
{
System.out.print(c.getName()+" ");
num3=Integer.valueOf(c.getLoadPeooleNum())+num3;
num4=Integer.valueOf(c.getLoadGoodsNum())+num4;
price3=Integer.valueOf(c.getPrice())+price3;
}
System.out.println("共载人:"+num3+"人 "+"共载货:"+num4+"吨");
System.out.println();
priceAll=price1+price2+price3;
System.out.println("****租车总价格为:"+priceAll*daynum);
}}