手记

哒哒租车系统——java练习

哒哒租车系统

car类
package test10;

public class car {
public String name;
public int num;
public int price;

public int sum(int time){
    return price*time;
}

}


truck类

package test10;

public class truck {
public String name;
public int price;
public int num;

public int sum(int time){
    return price*time;
}

}


pickup类
package test10;

public class pickup {
public String name;
public int num_people;
public double num_goods;
public int price;

public double sum(int time){
    return price*time;
}

}


bus类
package test10;

public class bus {
public String name;
public int price;
public int num;

public int sum(int time){
    return price*time;
}

}


DaDaSystem类
package test10;
import java.util.Scanner;

public class DaDaSystem {

public static void main(String[] args) {
    // TODO Auto-generated method stub
    car car1=new car();
    car1.name="奔驰";
    car1.num=4;
    car1.price=500;
    car car2=new car();
    car2.name="吉普";
    car2.num=6;
    car2.price=350;

    truck t1=new truck();
    t1.name="雪铁龙";
    t1.num=20;
    t1.price=600;
    truck t2=new truck();
    t2.name="福田";
    t2.num=25;
    t2.price=750;

    pickup p1=new pickup();
    p1.name="福特";
    p1.num_goods=1.5;
    p1.num_people =2;
    p1.price=480;

    bus b1=new bus();
    b1.name="宇通";
    b1.num=48;
    b1.price=900;
    bus b2=new bus();
    b2.name="金龙";
    b2.num=42;
    b2.price=850;
    System.out.println("你好!欢迎进入答答在线汽车租赁系统。");
    System.out.println("你是否需要租车服务?1 是  0 否");
    Scanner input=new Scanner(System.in);
    int key=input.nextInt();
    if(key==1){
        System.out.println("以下是本公司所有车辆的详细信息");
        System.out.println("#1"+car1.name+" 载客量:"+car1.num+"人  价格: "+car1.price+"元/天");
        System.out.println("#2"+car2.name+" 载客量:"+car2.num+"人  价格: "+car2.price+"元/天");
        System.out.println("#3"+t1.name+" 载货量:"+t1.num+"吨  价格: "+t1.price+"元/天");
        System.out.println("#4"+t2.name+" 载客量:"+t2.num+"人  价格: "+t2.price+"元/天");
        System.out.println("#5"+p1.name+" 载客量:"+p1.num_people+"人   载货量: "+p1.num_goods+"吨  价格: "+car1.price+"元/天");
        System.out.println("#6"+b1.name+" 载客量:"+b1.num+"人  价格: "+b1.price+"元/天");
        System.out.println("#7"+b2.name+" 载客量:"+b2.num+"人  价格: "+b2.price+"元/天");

        System.out.println("请输入你想要租赁的汽车种类数:");
        int all=input.nextInt();
        double SumMoney=0;
        double SumGoods=0;
        double SumPeople=0;
        String list1[]=new String[all];
        String list2[]=new String[all];
        int p=0;
        int q=0;
        for(int i=0;i<all;i++){
            System.out.println("请输入第"+(i+1)+"种汽车的编号:");
            int m=input.nextInt();
            System.out.println("您想要租赁该种车型的数量?");
            int n=input.nextInt();
            System.out.println("您想要租赁该种车型的天数?");
            int d=input.nextInt();
            switch(m){
            case 1:
                SumMoney=SumMoney+n*car1.sum(d);
                SumPeople=SumPeople+n*car1.num;
                list1[p]=car1.name;
                p++;
                break;
            case 2:
                SumMoney=SumMoney+n*car2.sum(d);
                SumPeople=SumPeople+n*car2.num;
                list1[p]=car2.name;
                p++;
                break;
            case 3:
                SumMoney=SumMoney+n*t1.sum(d);
                SumGoods=SumGoods+n*t1.num;
                list2[q]=t1.name;
                q++;
                break;
            case 4:
                SumMoney=SumMoney+n*t2.sum(d);
                SumGoods=SumGoods+n*t2.num;
                list2[q]=t2.name;
                q++;
                break;
            case 5:
                SumMoney=SumMoney+n*p1.sum(d);
                SumGoods=SumGoods+n*p1.num_goods;
                SumPeople=SumPeople+n*p1.num_people;
                list1[p]=p1.name;
                list2[q]=p1.name;
                p++;
                q++;
                break;
            case 6:
                SumMoney=SumMoney+n*b1.sum(d);
                SumPeople=SumPeople+n*b1.num;
                list1[p]=b1.name;
                p++;
                break;
            case 7:
                SumMoney=SumMoney+n*b2.sum(d);
                SumPeople=SumPeople+n*b2.num;
                list1[p]=b2.name;
                p++;
                break;
            }//Switch 语句结束

        }//for循环结束
        System.out.println("您的账单");
        System.out.println("*****可载人的汽车:");
        for(int j=0;j<p;j++){
            System.out.print(list1[j]+'\t');
        }
        System.out.println("总载客数: "+SumPeople+"人");
        System.out.println("*****可载货的汽车:");
        for(int j=0;j<q;j++){
            System.out.print(list2[j]+'\t');
        }
        System.out.println("总载货量: "+SumGoods+"吨");
        System.out.println("*****总金额:");
        System.out.println(SumMoney+"元");
    } //if语句结束

    else
        System.out.println("欢迎下次使用!");

}

}

4人推荐
随时随地看视频
慕课网APP