求指导啊Orz.....我实在是弄不出来了!!!!
我就学了前两季,实在是不知道要怎么搞了,谁可以告诉我怎么把数据保存然后在用么Orz!!(不管如何我都做不到让车的类型在账单中显示)
显示车类及价目表我是借鉴了别人的方法的.......主要是我自己弄的那个在容量那接不上.......
求指导Orz
车的父类
package com.imooc; public class Car { //序号 private int num; public int getNum() { return num; } public void setNum(int num) { this.num = num; } //汽车的类型 private String name; public String getName() { return name; } public void setName(String name) { this.name = name; } //租金 private double price; public double getPrice() { return price; } public void setPrice(double price) { this.price = price; } }
载人汽车类
package com.imooc; public class Salooncar extends Car implements ISeat { //载人数量(座位) private int seat; @Override public int getSeat(){ // TODO Auto-generated method stub return seat; } public void setSeat(int newSeat) { this.seat = newSeat; } //构造初始化 public Salooncar(int newNum,String newName,double newPrice ,int newSeat) { this.setNum(newNum); this.setName(newName); this.setPrice(newPrice); this.seat =newSeat; } }
皮卡车类
package com.imooc; public class Pickup extends Car implements ISeat,IBurden{ //载人数量(座位) private int seat; @Override public int getSeat() { return seat; } public void setSeat(int newSeat) { this.seat = newSeat; } //载货量 private double burden; @Override public double getBurden() { return burden; } public void setBurden(double newSurden) { this.burden = newSurden; } //构造初始化 public Pickup(int newNum,String newName,double newPrice,int newSeat,double newSurden){ this.setNum(newNum); this.setName(newName); this.setPrice(newPrice); this.seat = newSeat; this.burden = newSurden; } }
货车类
package com.imooc; public class Wagon extends Car implements IBurden { //载货量 private double burden; @Override public double getBurden() { return burden; } public void setBurden(double newBurden) { this.burden = newBurden; } //构造初始化 public Wagon(int newNum,String newName,double newPrice,double newBurden){ this.setNum(newNum); this.setName(newName); this.setPrice(newPrice); this.burden = newBurden; } }
座位(载人数人数)的接口
package com.imooc; public interface ISeat { public int getSeat(); }
载货量的接口
package com.imooc; public interface IBurden { public double getBurden(); }
主函数
package com.imooc; import java.util.Scanner; import org.omg.CORBA.PUBLIC_MEMBER; public class Initail { public static void main(String[] args) { // TODO Auto-generated method stub final int yes = 1; final int no = 0; //单价 int sum = 0; //总金额 int sums = 0; //单辆车可载人数 int people = 0; //最多可载人数 int peoples = 0; //单辆车可载货量 int burden1 = 0; //最多可载载货量 int burden2 = 0; Car[] car = {new Salooncar(1, "奥迪A4", 500, 4),new Salooncar(2, "马自达6", 400, 4),new Pickup(3, "皮卡雪6", 450, 4, 2),new Salooncar(4, "金龙", 400, 4),new Wagon(5, "松花江", 800, 4),new Wagon(6, "依维柯", 1000, 20)}; Car prives = new Car(); //询问是否进入租车系统 System.out.println("欢迎使用答答租车系统"); System.out.println("请问您是否需要租车:"+"\n"+yes+".是"+"\t"+no+".否"); //创建Scanner对象,对象名为input Scanner input = new Scanner(System.in); int one = input.nextInt();//登录系统用的 //登录系统 if(one == yes){ System.out.println("下列是出租车的类型及其价目表"); System.out.println("序号"+"\t"+"汽车类型"+"\t"+"\t"+"出租价格"+"\t"+"\t"+"容量"); //显示出租车的清单列表 for(Car car2:car){ if(car2 instanceof Salooncar){ System.out.println(car2.getNum()+"."+"\t"+car2.getName()+"\t"+"\t"+car2.getPrice()+"元/天"+"\t"+"载人:"+((Salooncar)car2).getSeat()); } if(car2 instanceof Pickup){ System.out.println(car2.getNum()+"."+"\t"+car2.getName()+"\t"+"\t"+car2.getPrice()+"元/天"+"\t"+"载人:"+((Pickup)car2).getSeat()+"人"+"\t"+"载货:"+((Pickup)car2).getBurden()+"吨"); } if(car2 instanceof Wagon){ System.out.println(car2.getNum()+"."+"\t"+car2.getName()+"\t"+"\t"+car2.getPrice()+"元/天"+"\t"+"载货:"+((Wagon)car2).getBurden()+"吨"); } } //询问需要汽车的辆数 System.out.println("请问需要组多少辆汽车:"); int two = input.nextInt();//选择汽车数量用的 for(int i=1;i<=two;i++){ System.out.println("请输入第"+i+"辆汽车的序号"); int three = input.nextInt(); //不同类型车的租金,载人量,载货量(现在只想到这种方法=-=) if(three >=1){ int[] price = {500,400,450,400,800,1000}; int[] seat = {4,20}; int[] burden = {2,4,20}; switch(three){ case 1:{ sum = price[0]; people = seat[0]; } break; case 2:{ sum = price[1]; people = seat[0]; } break; case 3:{ sum = price[2]; people = seat[0]; burden1 = burden[0]; } break; case 4:{ sum = price[3]; people = seat[1]; } break; case 5:{ sum = price[4]; burden1 = burden[1]; } break; case 6:{ sum = price[5]; burden1 = burden[2]; } break; } } sums = sums + sum ; peoples = peoples + people; burden2 = burden2 + burden1; } //出租的天数 System.out.println("请输入租借的天数"); int four = input.nextInt(); int days = four; //计算总金额,总人数,总载货量 sums = sums*days; peoples = peoples*days; burden2 = burden2*days; System.out.println("*****您的账单"); System.out.println("载人类汽车:"+"\t"+"最多可载人:"+peoples+"人"); System.out.println("载货类汽车:"+"\t"+"最多可载货:"+burden2+"吨"); System.out.println("一共的价格:"+sums); System.out.println("谢谢惠顾~!"); //退出系统 }else if(one == no){ System.out.println("感谢您的再次使用!再见!"); }else{ System.out.println("输入信息出错"); } } }