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

java第二季____哒哒租车系统

卖雪糕小贩
关注TA
已关注
手记 1
粉丝 0
获赞 20

Car类

public class Car {
    private int passenger_num;
    private int goods_num;
    private String name;
    private int price;
    public int getPassenger_num() {
        return passenger_num;
    }
    public void setPassenger_num(int passenger_num) {
        this.passenger_num = passenger_num;
    }
    public int getGoods_num() {
        return goods_num;
    }
    public void setGoods_num(int goods_num) {
        this.goods_num = goods_num;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public int getPrice() {
        return price;
    }
    public void setPrice(int price) {
        this.price = price;
    }
}

Goods_car类

public class Goods_car extends Car {
    public Goods_car(String name,int price,int goods_num){
        setName(name);
        setPrice(price);
        setGoods_num(goods_num);
    }
    public void Print(){
        System.out.println(getName()+"  "+getPrice()+"元/天    "+"载货:"+getGoods_num()+"吨");   
    }
}

Normal_car类

public class Normal_car extends Car {
    public Normal_car(String name,int price,int Passengers_num){
        setName(name);
        setPrice(price);
        setPassenger_num(Passengers_num);
    }
    public void Print(){
        System.out.println(getName()+"  "+getPrice()+"元/天    "+"载人:"+getPassenger_num()+"人");
    }
}

pika类

public class pika extends Car {
    public pika(String name,int price,int goods_num,int passengers_num){
        setName(name);
        setPrice(price);
        setPassenger_num(passengers_num);
        setGoods_num(goods_num);
    }
    public void Print(){
        System.out.println(getName()+"  "+getPrice()+"元/天    "+"载人:"+getPassenger_num()+"人 载货:"+getGoods_num()+"吨");
    }
}

Initial类

import java.util.Scanner;
public class Initial {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        System.out.println("欢迎使用哒哒租车系统");
        System.out.println("您是否要租车:1是 0否");
        Scanner in=new Scanner(System.in);
        int op=in.nextInt();
        if(op==0){
            System.out.println("正在推出出系统!!");
        }
        else{
        System.out.println("你可租车的类型及其价目表");
        System.out.println("序号   汽车名称    租金         容量");
        Car[] car=new Car[6];
        car[0]=new Normal_car("奥迪A6 ",500,4);
        car[1]=new Normal_car("马自达6",400,4);
        car[2]=new pika("皮卡雪   ",450,2,4);
        car[3]=new Normal_car("金龙       ",800,20);
        car[4]=new Goods_car("松花江   ",400,4);
        car[5]=new Goods_car("依维柯   ",1000,20);
        for(int i=0;i<car.length;i++){
            System.out.print(i+1+"     ");
            if(car[i] instanceof Normal_car) ((Normal_car)car[i]).Print();
            if(car[i] instanceof pika) ((pika)car[i]).Print();
            if(car[i] instanceof Goods_car) ((Goods_car)car[i]).Print();
        }
        System.out.println("请输入你要租车的数量:");
        int num=in.nextInt();
        int x[]=new int[100];
        for(int i=0;i<num;i++){
            System.out.println("请输入第"+(i+1)+"辆车的序号");
            x[i]=in.nextInt();
        }
        System.out.println("请输入租车天数:");
        int day=in.nextInt();
        System.out.println("您的账单:");
        System.out.println("***可载人的车有:");
        int sum=0;
        for(int i=0;i<num;i++){
            if(car[x[i]-1] instanceof Normal_car){
                ((Normal_car)car[x[i]-1]).Print();
                sum+=car[x[i]-1].getPassenger_num();
            }
            if(car[x[i]-1] instanceof pika){
                ((pika)car[x[i]-1]).Print();
                sum+=car[x[i]-1].getPassenger_num();
            }
        }
        System.out.println("可载人:"+sum+"人");
        sum=0;
        int price=0;
        System.out.println("***可载货的车有:");
        for(int i=0;i<num;i++){
            if(car[x[i]-1] instanceof Goods_car) {
                ((Goods_car)car[i]).Print();
                sum+=car[x[i]-1].getGoods_num();    
            }
            if(car[x[i]-1] instanceof pika){
                ((pika)car[x[i]-1]).Print();
                sum+=car[x[i]-1].getGoods_num();
            }
            price+=car[x[i]-1].getPrice();

        }
        System.out.println("可载货:"+sum+"吨");
        System.out.println("***总价格为:"+price*day+"元");

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

热门评论

这个x[i]-1是什么意思

查看全部评论