package org.java.entity; /** * car父类 * @author 1 * */ public class Car { public int num;//序号 public String name;//车名 public int rental;//租金 public int manned; //载人 public Double load=0.00; //载重 public int getNum() { return num; } public void setNum(int num) { this.num = num; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getRental() { return rental; } public void setRental(int rental) { this.rental = rental; } public Car(){} public void show() { System.out.println(num+"\t"+name+"\t"+rental+"元/天 载人:"+manned+"人,"+load+"吨"); } } package org.java.entity; /** 客车 **/ public class Coach extends Car { public Coach(int num,String name,int rental,int manned){ this.num = num; this.name = name; this.rental = rental; this.manned = manned; } } package org.java.entity; /** 皮卡 **/ public class Pika extends Car { public Pika(int num,String name,int rental,int manned,Double load){ this.num = num; this.name = name; this.rental = rental; this.manned = manned; this.load = load; } } package org.java.entity; /** * 小轿车 * @author 1 * */ public class Sedan extends Car { public Sedan(int num,String name,int rental,int manned){ this.num = num; this.name = name; this.rental = rental; this.manned = manned; } } package org.java.entity; /** * 货车 * @author 1 * */ public class Trucks extends Car { public Trucks(int num,String name,int rental,Double load){ this.num = num; this.name = name; this.rental = rental; this.load = load; } } package org.java.test; import java.util.Scanner; import org.java.entity.Car; import org.java.entity.Coach; import org.java.entity.Pika; import org.java.entity.Sedan; import org.java.entity.Trucks; public class Test1 { public static void main(String[] args) { // TODO Auto-generated method stub //车辆信息 Sedan c1 = new Sedan(1,"奥迪A4",500,4); Sedan c2 = new Sedan(2,"马自达6",400,4); Pika c3 = new Pika(3,"皮卡雪6",450,4,2.0); Coach c4 = new Coach(4,"金龙",800,20); Trucks c5 = new Trucks(5,"松花江",400,4.0); Trucks c6 = new Trucks(6,"依维柯",1000,20.0); Car[] carl = {c1,c2,c3,c4,c5,c6}; int day ;//租用天数 int count;//车辆数 int[] carCount = null; Scanner input = new Scanner(System.in); System.out.println("欢迎进入嗒嗒租车系统"); System.out.println("按1进入\t按0退出"); int choose = input.nextInt(); if(choose==1) { System.out.println("你可以租车的类型及价格"); System.out.println("序号\t汽车名称\t租金\t容量"); for (Car car : carl) { car.show(); } System.out.println("请序号进行选择"); System.out.println("请选择租车数量"); count = input.nextInt(); carCount = new int[count]; for(int i=1;i<=count;i++) { System.out.println("请输入第"+i+"辆的的类型"); //将车辆信息保存到数组 carCount[i-1] = input.nextInt(); } System.out.println("请输入租车的天数:"); day = input.nextInt(); String[] money = money(carCount,day); System.out.println("金额为"+money[0]+"元"); System.out.println("载重为"+money[1]+"吨"); System.out.println("载人数为"+money[2]+"人"); }else { System.out.println("退出系统>>>>>>"); } } public static String[] money(int[] carcount,int day) { int a1 = 0; int a2 = 0; int a3 = 0; int a4 = 0; int a5 = 0; int a6 = 0; int sum = 0; double load = 0.00; int count = 0; for(int i=0;i<carcount.length;i++) { switch (carcount[i]) { case 1: a1++; break; case 2: a2++; break; case 3: a3++; break; case 4: a4++; break; case 5: a5++; break; case 6: a6++; break; default:break; } } if(a1!=0) { sum += a1*500; count += a1*4; } if(a2!=0) { sum += a2*400; count += a2*4; } if(a3!=0) { sum += a3*450; count += a3*4; load += a3*2.0; } if(a4!=0) { sum += a4*800; count =a4*20; } if(a5!=0) { sum += a5*400; load += a5*4.0; } if(a6!=0){ sum += a6*100; load += a6*20.0; } sum = sum*day;//计算金额数 String strsum = Integer.valueOf(sum).toString(); String strload = Double.valueOf(load).toString(); String strcount = Integer.valueOf(count).toString(); String[] str = new String[3]; str[0] = strsum; str[1] = strload; str[2] = strcount; return str; } }
能完成那个要求的功能吧。。。
点击查看更多内容
为 TA 点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦