继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

租车系统简易代码个人思路

Curry_Coder
关注TA
已关注
手记 1
粉丝 2
获赞 0
package com.imooc;

public  class Car {

    //汽车数量
    int num ;
    //汽车名称
    String name ;
    //汽车租金
    int money;
    //汽车载人量
    int manned;
    //汽车载重量
    int load;

    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 getMoney() {
        return money;
    }
    public void setMoney(int money) {
        this.money = money;
    }
    public int getManned() {
        return manned;
    }
    public void setManned(int manned) {
        this.manned = manned;
    }
    public int getLoad() {
        return load;
    }
    public void setLoad(int load) {
        this.load = load;
    }

}

package com.imooc;
/**

  • 小汽车 只载人
  • @author Curry_Coder
  • */
    public class SmallCar extends Car {

    public SmallCar(int num,String name,int money,int manned){
    this.setNum(num);
    this.setManned(manned);
    this.setMoney(money);
    this.setName(name);
    }
    }

package com.imooc;

public class PickCar extends Car {

    public PickCar (int num,String name,int money,int load,int manned){
        this.setLoad(load);
        this.setManned(manned);
        this.setMoney(money);
        this.setName(name);
        this.setNum(num);
    }
}
package com.imooc;

public class BigCar extends Car {

    public BigCar(int num,String name,int money,int load){
        this.setLoad(load);
        this.setMoney(money);
        this.setName(name);
        this.setNum(num);
    }

}
package com.imooc;

import java.util.Scanner;

public class Test {

    public static void main(String[] args) {

        Car car[] = { new SmallCar(1,"奥迪A8"+"\t",500,4),
                    new SmallCar(2,"玛莎拉蒂"+"\t",400,4),
                    new PickCar(3,"猛禽"+"\t",450,4,2),
                    new SmallCar(4,"GTR"+"\t",80,20),
                    new BigCar(5,"东风"+"\t",400,4),
                    new BigCar(6,"依维柯"+"\t",1000,20)
        };
        System.out.println("欢迎使用嗒嗒租车系统:");
        System.out.println("您是否要租车: 1 是    0 否");
        Scanner input = new Scanner(System.in);
        int a = input.nextInt();
        if(a==1){
            String name1=" ";
            String name2=" ";
            String name3=" ";
            String name4=" ";
            String name5=" ";
            String name6=" ";
            int AllPeople = 0;
            int people = 0;
            int money = 0;
            int AllMoney = 0;
            int load = 0;
            int AllLoad = 0;
            int manned = 0;
            int AllManned = 0;
            System.out.println("你可以租车的类型以及价目表:");

            System.out.println("序号"+"\t"+"汽车名称"+"\t"+"租金"+"\t"+"容量");
            for(int x = 0;x<6;x++){
                if(x==3){

                    System.out.println(car[x].getNum()+"."+"\t"
                            +car[x].getName() + car[x].getMoney()+"元/天"+"\t"+
                            "载人"+car[x].getManned()+"载物"+car[x].getLoad()+"吨");

                }else if(x==6 | x ==5){

                    System.out.println(car[x].getNum()+"."+"\t"
                            +car[x].getName() + car[x].getMoney()+"元/天"+"\t"+
                            "载物"+car[x].getLoad()+"吨");

                }else{

                    System.out.println(car[x].getNum()+"."+"\t"
                            +car[x].getName() + car[x].getMoney()+"元/天"+"\t"+
                            "载人"+car[x].getManned());

                }
            }
            System.out.println("请输入你要选择的车辆的数量:");
            Scanner intp = new Scanner(System.in);
            int n = intp.nextInt();
            for(int i=1;i<= n;i++){
                System.out.println("请输入第"+i+"辆车的序号");
                Scanner intput = new Scanner(System.in);
                int chose = intput.nextInt();
                if(chose ==1){
                    name1 = car[0].getName();
                    money = car[0].getMoney();
                    people = car[0].getManned();
                }else if(chose ==2){
                    name2 = car[1].getName();
                    money = car[1].getMoney();
                    people=car[1].getManned();
                }else if(chose ==3){
                    name3 = car[2].getName();
                    money = car[2].getMoney();
                    people=car[2].getManned();
                    load = car[2].getLoad();
                }else if(chose ==4){
                    name4 = car[3].getName();
                    money = car[3].getMoney();
                    people= car[3].getManned();
                }else if(chose ==5){
                    name5 = car[4].getName();
                    money = car[4].getMoney();
                    load  = car[4].getLoad();
                }else {
                    name6 = car[5].getName();
                    money = car[5].getMoney();
                    load  = car[5].getLoad();
                }
                AllPeople = AllPeople + people;
                people = 0;
                AllLoad = AllLoad + load;
                load = 0;
                AllMoney = AllMoney + money;
                money = 0;

                }
            System.out.println("请输入你要租多少天:");
            Scanner intp3 = new Scanner(System.in);
            int day = intp3.nextInt();
            System.out.println("您的账单为:");
            System.out.println("***可载人的车辆有");
            System.out.println(name1+name2+name3+name4+"共载人"+AllPeople+"人");
            System.out.println("***可载货的车辆有");
            System.out.println(name3+name5+name6+"共载货"+AllLoad+"吨");
            System.out.println("租车费用共计:"+AllMoney*day);

            }
        else{
            System.out.println("感谢使用,0");
        }
        }
    }
打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP