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

Java课后项目 达达租车系统

回口回
关注TA
已关注
手记 2
粉丝 2
获赞 6
public abstract class Cars {
    //创建抽象主类
    public int id;
    public String name;
    public int money;
    public int num;
    public int day;

    public String toString2() {
        return id +"\t" + name +"\t"+num+"台\t"+day+"天\t"+money;
    }
}
public class Trunk extends Cars{
//Trunk类
    private int cap1;
    public  Trunk(int id,String name,int money,int cap1){
        this.id =id;
        this.name =name;
        this.money =money;
        this.cap1=cap1;
    }

    public String toString() {
        return id +"\t" + name +"\t"+money+"\t载货量:"+cap1+"吨";
    }
}
public class Bus extends Cars{
//Bus类
    private int cap2;
    public  Bus(int id,String name,int money,int cap2){
        this.id =id;
        this.name =name;
        this.money =money;
        this.cap2=cap2;
    }
    public String toString(){
        return id +"\t" + name +"\t"+money +"\t载人数:"+cap2+"人";  
    }
}
public class Pickup extends Cars{
//皮卡类
    private int cap1;
    private int cap2;
    public  Pickup(int id,String name,int money,int cap1,int cap2){
        this.id =id;
        this.name =name;
        this.money =money;
        this.cap1=cap1;
        this.cap2=cap2;
    }
    public String toString() {
        return id +"\t" + name +"\t"+money+"\t载货量:"+cap1+"吨"+" 载人数:"+cap2+"人";
    }
}
import java.util.Scanner;
public class Test {

    static int I1=0;
    static int I2=0;
    static int I3=0;
    static int I4=0;
    static int I5=0;
    static int I6=0;

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        //创建对象
            Cars c1 =new Bus(1,"奥迪A6",500,4);
            Cars c2 =new Bus(2,"马自达6",400,4);
            Cars c3 =new Pickup(3,"皮卡雪6",450,2,4);
            Cars c4 =new Bus(4,"金龙",800,20);
            Cars c5 =new Trunk(5,"松花江",300,2);
            Cars c6 =new Trunk(6,"依维柯",900,10);
            Cars Array[]=new Cars[]{c1,c2,c3,c4,c5,c6};
        //开始
        System.out.println("欢迎使用租车系统!");
        System.out.println("您是否要租车?\t1.Y\t2.N");
        Scanner input1 =new Scanner(System.in);
        if(input1.nextInt() == 1){
            System.out.println("您可租用的车型价目表:");
            System.out.println("序号\t汽车名称\t日租金\t容量");
            //列表
            for(int i=0;i<Array.length;i++)
                System.out.println(Array[i].toString());
            //选车(初始化)
            int start =1;
            int[] arr=new int[]{I1,I2,I3,I4,I5,I6};
            //选车(循环)

            do{
                System.out.print("请输入想选择的车的序号:");
                Scanner input2 =new Scanner(System.in);
                int ID=input2.nextInt();
                //验证序号合理性
                if(ID>6 ||ID<1){
                    System.out.println("输入错误!没有此序号的车!");
                    continue;
                }

                System.out.print("请输入想租的台数:");
                Scanner input3 =new Scanner(System.in);
                int NUM=input3.nextInt();
                //计数
                arr[ID-1]=arr[ID-1]+NUM;
                Array[ID-1].num =arr[ID-1];
                //天数
                System.out.print("请输入租车天数:");
                Scanner input4 =new Scanner(System.in);
                int DAY =input4.nextInt();
                Array[ID-1].day +=DAY;
                //询问循环
                System.out.println("请问还要继续租车吗?\t1.Y\t2.N");
                Scanner input5 =new Scanner(System.in);
                start =input5.nextInt();

            }while(start ==1);

            //输出订单
            int MONEY=0;
            System.out.println("您的订单:");
            System.out.println("序号\t名称\t数量\t天数\t日租金");
            for(int j=0;j<Array.length;j++){
                if(arr[j]!=0)
                System.out.println(Array[j].toString2());
//计算租金
            MONEY =(Array[j].day *Array[j].num *Array[j].money )+ MONEY;    
            }
            System.out.println("总租金为:"+MONEY);
        }
        System.out.println("谢谢使用。");    
    }
}
打开App,阅读手记
1人推荐
发表评论
随时随地看视频慕课网APP