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

答答租车系统【Van0512】

慕姐3585284
关注TA
已关注
手记 10
粉丝 22
获赞 199
package dada_car_rental_system;

public class Car {
    public String name;
    public int rent;
    public int person;
    public int cargo;

    public Car(String name, int rent, int person, int cargo){
        this.name = name;
        this.rent = rent;
        this.person = person;
        this.cargo = cargo;
    }
}
package dada_car_rental_system;

public class Audi extends Car {

    public Audi(String name, int rent, int person, int cargo) {
        super(name, rent, person, cargo);
        // TODO Auto-generated constructor stub
    }

}

。。。
。。。
。。。

package dada_car_rental_system;
import java.util.Scanner;

public class Test {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        System.out.println("欢迎使用答答租车系统:");
        System.out.println("您是否要租车:1是    0否");
        Scanner input = new Scanner(System.in);
        int a = input.nextInt();
        if(a != 1){
            System.out.println("Goodbye. Welcome to you next time.");
        }else{
            new Test().list();
            double totalPrice = 0;
            int num1 = 0;   //载人数
            double num2 = 0;    //载货数
            Car[] cars = {new Audi("奥迪A4", 500, 4, 0), new Mazda("马自达6", 400, 4, 0), new PickupSnow("皮卡雪6", 450, 4, 2), 
                    new KingLong("金龙", 800, 20, 0), new SongHua("松花江", 400, 0, 4), new Iveco("依维柯", 1000, 0, 20)};

            System.out.println("请输入您要租车的数量");
            int n = input.nextInt();
            int[] nums = new int[n];    //记录租车序号
            for(int i=0; i<n; i++){
                System.out.println("请输入第" + (i+1) + "辆车的序号:");
                nums[i] = input.nextInt();
                totalPrice += cars[nums[i] - 1].rent;
                num1 += cars[nums[i] - 1].person;
                num2 += cars[nums[i] - 1].cargo;
            }
            System.out.println("请输入租车天数:");
            int days = input.nextInt();

            System.out.println("您的账单:");
            System.out.println("***可载人的车有:");
            for(int i=0; i<n; i++){
                if(nums[i] != 5 && nums[i] != 6)
                    System.out.print(cars[nums[i] - 1].name + " ");
            }
            System.out.println("共载人:" + num1 + "人");
            System.out.println("***可载货的车有");
            for(int i=0; i<n; i++){
                if(nums[i] == 3  nums[i] == 5  nums[i] == 6)
                    System.out.print(cars[nums[i] - 1].name + " ");
            }
            System.out.println("共载货:" + num2 + "吨");
            System.out.println("***租金总价格:" + totalPrice * days);
        }
        input.close();
    }

    private void list(){
        System.out.println("您可租车的类型及其价目表:"
                + "\n序号\t汽车名称   租金  容量"
                + "\n1.\t奥迪A4   500元/天  载人:4人"
                + "\n2.\t马自达6   400元/天  载人:4人"
                + "\n3.\t皮卡雪6   450元/天  载人:4人 载货:2吨"
                + "\n4.\t金龙 800元/天  载人:20人"
                + "\n5.\t松花江    400元/天  载货:4吨"
                + "\n6.\t依维柯    1000元/天 载货:20吨");
    }

}
打开App,阅读手记
2人推荐
发表评论
随时随地看视频慕课网APP

热门评论

test

test;
as a test;


查看全部评论