为了账号安全,请及时绑定邮箱和手机立即绑定

java第二季综合练习,答答租车系统

标签:
Java

Initial .java

package 答答租车系统;
import java.util.Scanner;

public class Initial {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        //用户输入序号num
        int num;
        //循环判断用户输入值
        do{
            System.out.println("********欢迎使用答答租车系统********");
            System.out.println("您是否要租车:1是 0否");
            num = input.nextInt();
            if(num == 1){
                System.out.println("您可租车的类型及其价目表:");
                System.out.println("序号  汽车名称  租金                 容量");
                Vehicle audi   = new Vehicle(1, "奥迪A4",  500,  4, 0);
                Vehicle mazda  = new Vehicle(2, "马自达6", 400,  4, 0 );
                Vehicle pickup = new Vehicle(3, "皮卡雪6", 450,  4, 2 );
                Vehicle kinglong=new Vehicle(4, "金龙",    800,  20,0);
                Vehicle sonhj  = new Vehicle(5, "松花江",  400,  0, 4);
                Vehicle naveco = new Vehicle(6, "依维柯",  1000, 0, 20);               
                System.out.println("请输入您要租车的数量:");
                num = input.nextInt();
                //可载人的车名数组
                String[] personVeName = new String[num];
                //可载货的车名数组
                String[] cagoVeName = new String[num];
                //用户输入的车辆序号veNum
                int veNum;
                //总载人数
                int sumPer = 0;
                //总载货量
                double sumCag = 0;
                //总单价
                double sumPP = 0;
                //总载人车数
                int personVeSum = 0;
                //总载货车数
                int cagoVeSum = 0;
                for(int i=1; i<=num; i++){
                    System.out.println("请输入第" + i + "辆车的序号:");  
                    veNum = input.nextInt();
                    //合计总载人数、总载货量、总单价、分别总车数
                    switch(veNum){
                        case 1:
                            sumPer += audi.capPerson;
                            sumPP += audi.price;
                            personVeSum++;
                            personVeName[personVeSum-1] = audi.name;
                            break;
                        case 2:
                            sumPer += mazda.capPerson;
                            sumPP += mazda.price;
                            personVeSum++;
                            personVeName[personVeSum-1] = mazda.name;
                            break;
                        case 3:
                            sumPer += pickup.capPerson;
                            sumCag += pickup.capCago;
                            sumPP += pickup.price;
                            personVeSum++;
                            cagoVeSum++;
                            personVeName[personVeSum-1] = pickup.name;
                            cagoVeName[cagoVeSum-1] = pickup.name;
                            break;
                        case 4:
                            sumPer += kinglong.capPerson;
                            sumPP += kinglong.price;
                            personVeSum++;
                            personVeName[personVeSum-1] = kinglong.name;
                            break;
                        case 5:
                            sumCag += pickup.capCago;
                            sumPP += sonhj.price;
                            cagoVeSum++;
                            cagoVeName[cagoVeSum-1] = pickup.name;
                            break;
                        case 6:
                            sumCag += pickup.capCago;
                            sumPP += naveco.price;
                            cagoVeSum++;
                            cagoVeName[cagoVeSum-1] = pickup.name;
                            break;                                          
                    }
                }
                System.out.println("请输入租车天数:");
                //用户租车天数rentDays
                int rentDays = input.nextInt();             
                System.out.println("您的账单:");
                ///System.out.println("***共载人数为:" + sumCap);
                System.out.println("***可载人的车有:");
                for(int i=0; i<personVeSum; i++){
                    System.out.print("  " + personVeName[i]);
                }
                System.out.println("    共载人:" + sumPer + "人");
                System.out.println("***可载货的车有:");
                for(int i=0; i<cagoVeSum; i++){
                    System.out.print("  " + cagoVeName[i]);
                }
                System.out.println("    共载货:" + sumCag + "吨");
                System.out.println("***租车总价格:" + sumPP*rentDays);               
                input.close();
                break;
            }else if(num == 0){
                System.out.println("谢谢您的使用!欢迎再次光临!");
                continue;
            }else{
                System.out.println("您的输入有误请重新输入:");
                continue;
            }           
        }while(true);       
    }   
}

Vehicle.java

package 答答租车系统;

public class Vehicle {
    int VeNum;     //车序号
    String name;   //车名
    int price;     //租金
    int capPerson; //载客量
    double capCago;   //载货量
    public Vehicle(int VeNum,String name,int price,int capPerson,double capCago){
        this.VeNum = VeNum;
        this.name = name;
        this.price = price;
        this.capPerson = capPerson;
        this.capCago = capCago;
        if(capCago == 0){
            System.out.println(VeNum + ".  " + this.name + "  " + this.price + "元/天" + "       载人:" + this.capPerson + "人");
        }else if(capPerson == 0){
            System.out.println(VeNum + ".  " + this.name + "  " + this.price + "元/天" + "       载货:" + this.capCago + "吨");
        }else {
            System.out.println(VeNum + ".  " + this.name + "  " + this.price + "元/天" + "       载人:" + this.capPerson + "人 " + "载货:" + this.capCago + "吨");
        }
    }
}
点击查看更多内容
10人点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消