手记

答答租车系统,比较简陋

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+"元");
    }
}

}

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