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

答答租车系统,比较简陋

lucky_qi
关注TA
已关注
手记 2
粉丝 4
获赞 4

package com.imooc;
import java.util.Scanner;
public class Dada {

public static void main(String[] args) {
    // TODO 自动生成的方法存根
    int sumPrice=0;
    int sumPerson=0;
    int sumTon=0;
    System.out.println("欢迎使用答答租车系统!");
    System.out.println("您是否要租车:1是 0否");
    Scanner in=new Scanner(System.in);
    int write= in.nextInt();
    if(write==1){
        System.out.println("您可租车的类型及其价目表");
        System.out.println("序号"+"汽车名称  "+"租金             "+"容量");
        A a=new A();
        a.express();
        B b=new B();
        b.express();
        C c=new C();
        c.express();
        D d=new D();
        d.express();
        E e=new E();
        e.express();
        F f=new F();
        f.express();
        System.out.println("请输入您要租车的数量:");
        int n= in.nextInt();
        int[] arr = new int[n];
        for(int i=1;i<=n;i++){
            System.out.printf("请输入第"+i+"辆车的序号:");
            int m= in.nextInt();
               arr[i-1]=m;
            switch(m){
               case 1:System.out.println(a.name);
                        sumPrice+=a.price;sumPerson+=a.num;break;
               case 2:System.out.println(b.name);
                        sumPrice+=b.price;sumPerson+=b.num;break;
               case 3:System.out.println(c.name);
                        sumPrice+=c.price;sumPerson+=c.num;sumTon+=c.kg;break;
               case 4:System.out.println(d.name);
                        sumPrice+=d.price;sumPerson+=d.num;break;
               case 5:System.out.println(e.name);
                        sumPrice+=e.price;sumTon+=e.kg;break;
               case 6:System.out.println(f.name);
                        sumPrice+=f.price;sumTon+=f.kg;break;
            }

        }
        System.out.println("请输入租车的天数:");    
        int t=in.nextInt();
        System.out.println("您的账单:");
        System.out.println("***可载人的车有:");
        for(int i=0;i<arr.length;i++){
            switch(arr[i]){
            case 1:System.out.print(a.name+"  ");break;
            case 2:System.out.print(b.name+"  ");break;
            case 3:System.out.print(c.name+"  ");break;
            case 4:System.out.print(d.name+"  ");break;
            }
        }
        System.out.println("共载"+sumPerson+"人");
        System.out.println("***可载货的车有:");
        for(int i=0;i<arr.length;i++){
            switch(arr[i]){
            case 3:System.out.print(c.name+"  ");break;
            case 5:System.out.print(e.name+"  ");break;
            case 6:System.out.print(f.name+"  ");break;
            }
        }
        System.out.println("共载"+sumTon+"吨");
        System.out.println("***租车总共价格:"+t*sumPrice+"元");
    }
}

}

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