package carrentalcompany; public class saloon { //父类 方法类 private String pinpai; //品牌 private String chepai; //车牌 private String xinghao; //型号 private int money; //价格 private double sum; //总金额 public int getMoney() { return money; } public void setMoney(int money) { this.money = money; } public double getSum() { return sum; } public void setSum(double sum) { this.sum = sum; } public String getXinghao() { return xinghao; } public void setXinghao(String xinghao) { this.xinghao = xinghao; } public String getPinpai() { return pinpai; } public void setPinpai(String pinpai) { this.pinpai = pinpai; } public String getChepai() { return chepai; } public void setChepai(String chepai) { this.chepai = chepai; } void showinfo(){ System.out.println("品牌"+"\t\t车牌"+"\t\t型号"+"\t\t价格"); System.out.println(getPinpai()+"\t\t"+getChepai()+"\t\t"+getXinghao()+"\t\t"+getMoney()); } }
package carrentalcompany; public class coach { //添加车数 int money; int sum; saloon[] sal=new saloon[5]; public void cos(saloon salo){ for(int i=0;i<sal.length;i++){ if(sal[i]==null){ sal[i]=salo; break; } } } public void showCoach(){ //数出车数 System.out.println(); for(int i=0;i<sal.length;i++){ if(sal[i]!=null){ sal[i].showinfo(); } } } public void add(int boay){ // 赋值 轿车 的宝马 int money=300; this.money=boay*money; saloon sal1=new saloon(); sal1.setChepai("京NY2858"); sal1.setPinpai("宝马"); sal1.setXinghao("550i"); sal1.setMoney(this.money); sum+=this.money; cos(sal1); } public void bie(int boay){ //赋值 轿车 的别克 int money=350; this.money=boay*money; saloon sal2=new saloon(); sal2.setPinpai("别克"); sal2.setChepai("京NY2858"); sal2.setXinghao("550i"); sal2.setMoney(this.money); sum+=this.money; cos(sal2); } public void jin(int boay){ //赋值 金杯 int money=500; this.money=boay*money; saloon sal3=new saloon(); sal3.setPinpai("金杯"); sal3.setChepai("FY8668"); sal3.setXinghao("670t"); sal3.setMoney(this.money); sum+=this.money; cos(sal3); } public void lon(int boay){ //赋值 金龙 int money=400; this.money=boay*money; saloon sal4=new saloon(); sal4.setPinpai("金龙"); sal4.setChepai("京Ni4444"); sal4.setXinghao("777b"); sal4.setMoney(this.money); sum+=this.money; cos(sal4); } public void ka(int boay){ //赋值 大型卡车 int money=1000; this.money=boay*money; saloon sal4=new saloon(); sal4.setPinpai("大型卡车"); sal4.setChepai("京Ni4444"); sal4.setXinghao("568j"); sal4.setMoney(this.money); sum+=this.money; cos(sal4); } public void kas(int boay){ // 赋值 中型卡车 int money=800; this.money=boay*money; saloon sal4=new saloon(); sal4.setPinpai("中型卡车"); sal4.setChepai("京Ni4444"); sal4.setXinghao("375a"); sal4.setMoney(this.money); sum+=this.money; cos(sal4); } public void sums(){ System.out.println("总金额是:"+this.sum); } }
package carrentalcompany; import java.util.Scanner; public class TestCar { public static void main(String[] alg){ Scanner in=new Scanner(System.in); coach c=new coach(); boolean fale=true; while(fale){ System.out.println("欢迎来到租车公司!"); System.out.println("请输入要租车的天数:"); int tian=in.nextInt(); System.out.println("请输入你要租的汽车类型:1-轿车,2-客车,3-卡车,0-结束"); int x=in.nextInt(); if(x==1){//轿车 System.out.println("请输入要租的品牌:1-宝马,2-别克"); int b=in.nextInt(); if(b==1){//宝马 c.add(tian); c.showCoach(); }else if(b==2){ //别克 c. bie(tian); c.showCoach(); } }else if(x==2){//客车 System.out.println("请输入要租的品牌:1-金杯,2-金龙"); int b=in.nextInt(); if(b==1){ c.jin(tian); c.showCoach(); }else if(b==2){ c.lon(tian); c.showCoach(); } }else if(x==3){ //卡车 System.out.println("请输入要租的品牌:1-大型卡车,2-中型卡车"); int b=in.nextInt(); if(b==1){ c.ka(tian); c.showCoach(); }else if(b==2){ c.kas(tian); c.showCoach(); } } if(x==0){ fale=false; c.sums(); System.out.println("品牌"+"\t\t车牌"+"\t\t型号"+"\t\t价格"); } } } }
时间: 2024-10-18 15:38:32