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

JAVA第二学,达达租车系统

标签:
Java
//汽车类
package Dada;
public abstract class Car {
    private String name;//汽车名字
    private String lord;//汽车的载重大小
    private int price;//汽车的日租价格

    public Car(String Name,String Lord,int Price){ //汽车属性初始化
        name = Name;
        lord = Lord;
        price = Price;

    }
    //封装属性****************************************
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getLord() {
        return lord;
    }

    public void setLord(String lord) {
        this.lord = lord;
    }

    public int getPrice() {
        return price;
    }

    public void setPrice(int price) {
        this.price = price;
    }
    //封装属性****************************************

    //判断值是否相等***********************************
    @Override
    public String toString() {
        return "Car [name=" + name + ", lord=" + lord
                + ", price=" + price + "]";
    }

    @Override//
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        Car other = (Car) obj;
        if (lord == null) {
            if (other.lord != null)
                return false;
        } else if (!lord.equals(other.lord))
            return false;
        if (name == null) {
            if (other.name != null)
                return false;
        } else if (!name.equals(other.name))
            return false;
        if (price != other.price)
            return false;
        return true;
    }   
}
//大卡车类
package Dada;

public class Atruck extends Car {
    public Atruck(String Name, String Lord, int Price) {
        super(Name, Lord, Price);
        // TODO Auto-generated constructor stub
    }
}
//小卡车类
package Dada;

public class Itruck extends Car {
    public Itruck(String Name,String Lord, int Price) {
        super(Name, Lord, Price);
        // TODO Auto-generated constructor stub
    }
}
//大客车类
package Dada;

public class Acoach extends Car {
    public Acoach(String Name, String Lord, int Price) {
        super(Name,Lord, Price);
        // TODO Auto-generated constructor stub
    }
}
//小客车类
package Dada;

public class Icoach extends Car {
    public Icoach(String Name,String Lord, int Price) {
        super(Name,Lord, Price);
        // TODO Auto-generated constructor stub
    }
}
//皮卡车类
package Dada;
public class Picup extends Car {

    public Picup(String Name, String Lord, int Price) {
        super(Name, Lord, Price);
        // TODO Auto-generated constructor stub
    }
}
//选择系统
package Dada;
import java.util.Scanner;

public class Persion {
    static Scanner input = new Scanner(System.in);
    private static boolean flag = true;
    private static Car[] Choose = {new Atruck("大货车", "5吨", 1500),
                                   new Itruck("小货车", "2吨", 1000),
                                   new Itruck("大客车", "100人", 2000),
                                   new Itruck("小客车", "60人", 1400),
                                   new Itruck("皮卡车", "1吨,40人", 1200)};//每种车型和载重量,价格

    public static void first(Scanner input){//开始的登录的方法

        System.out.println("欢迎来到达达租车系统,是否进行租车?");
        System.out.println("1:是    2:否");
        String a = input.next();
        switch(a){
        case"1":
            choose(input);
            break;
        case"2":
            System.out.println("系统结束!");
            flag = false;
            TotalP();
            break;
        default:
            System.out.println("选择错误请重新选择:");
            first(input);
            break;          
        }   
    }
    private static int AtruckP;//大货车的总价
    private static int ItruckP;//小货车的总价
    private static int AcoachP;//大客车的总价
    private static int IcoachP;//小客车的总价
    private static int PicupP;//皮卡车的总价
    private static int[] Prices = {AtruckP,ItruckP,AcoachP,IcoachP,PicupP};

    private static boolean flag2 = true;
    private static boolean flag3 = true;
    private static boolean flag4 = true;
    public static int num1;//选择车记录的数字
    public static int num2;
    public static int num3;
    public static int num4;
    public static int num5;

    public static void choose(Scanner input){   //选择当前什么车   
        while(flag2){
            input= new Scanner(System.in);//这个很尴尬,非常尴尬---------------------------没道理
            System.out.println("请选择要租车的类型:");

            for(int i=0;i<Choose.length;i++)//现在是当前可供选择的类型
            {       
                System.out.println("第"+(i+1)+"种类型为:"+Choose[i].getName()+"日租价为:"+Choose[i].getPrice());
            }
            try {
                num1 = input.nextInt();//显示当前所选的类型
                System.out.println("当前选择的是:"+Choose[num1-1].getName()+"日租价为:"+Choose[num1-1].getPrice());
                choose2(input);
                flag2=false;
            } catch (Exception e) {
                // TODO: handle exception
                System.out.println("输入错误请重新输入!");
                continue;
            }

        }       
    }

    public static int num11;//选择数量记录的数字
    public static void choose2(Scanner input)//选择当前车的数量
    {
        while(flag3){
        System.out.println("选择当前租车数量:");
        try {
            num11 =0;
            input= new Scanner(System.in);//这个很尴尬,非常尴尬---------------------------没道理
            num11 += input.nextInt();//选择租车的数目
            Prices[num1-1] += num11*Choose[num1-1].getPrice();//选择的租车类型的价钱乘以数目得出每一类总的日租金
            while(flag4) //选择是否继续租车
            {
                System.out.println("是否继续租车?\n 1:是  2:否");
                String text = input.next();

                if(text.equals("1")){
                    choose(input);
                    flag4=false;
                }
                else if(text.equals("2")){
                    System.out.println("选择结束!");
                    flag4 = false;
                    flag3 = false;
                    TotalP();
                }
                else{
                    System.out.println("输入有误请重新选择!");
                    continue;
                }
            }
        } catch (Exception e) {
            // TODO: handle exception
            System.out.println("输入错误请重新输入!");
            continue;   
        }
    }
}

    public static void TotalP(){
        int Allp = 0;
        for (int i=0;i<Prices.length;i++){
        Allp += Prices[i];
        }
        System.out.println("每日付出总价为:"+Allp+"元RMB,感谢谢使用!");
        System.out.println("其中每种车的需要付出的价格为:");
        for (int i = 0; i < Prices.length; i++) {
            System.out.println(Choose[i].getName()+"需每日付:"+Prices[i]+
                    " <"+(Prices[i]/Choose[i].getPrice())+">辆");
        }
        flag = false;
    }
    public static void main(String[] args) {

        while(flag){
        first(input);
        }       
    }
}
点击查看更多内容
5人点赞

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

评论

作者其他优质文章

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

100积分直接送

付费专栏免费学

大额优惠券免费领

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

举报

0/150
提交
取消