手记

答答租车系统(虽然不是面对对象,但相对精简)

import java.util.Scanner;

public class Dada {

public static void main(String[] args) {
     System.out.println("欢迎使用答答租车系统:");
      Scanner input=new Scanner(System.in);
     System.out.println("您是否需要租车:1是 0否");
     int lent=input.nextInt();
     if(lent==1)
     {System.out.println("您可租车的类型及其价目");
        System.out.println("序号    汽车名称       租金               容量");
        System.out.println(" 1         奥迪A4   500元/天     载人:4人" );
        System.out.println(" 2         马自达6  400元/天     载人:4人" );
        System.out.println(" 3         皮卡雪6  450元/天     载人:4人 载货:2吨" );
        System.out.println(" 4           金龙        800元/天     载人:20人" );
        System.out.println(" 5         松花江      400元/天     载货:4吨" );
        System.out.println(" 6         依维柯      1000元/天   载货:20吨" );
         Scanner input1=new Scanner(System.in);
         System.out.println("请输入您要租车的数量:");
         int c=input1.nextInt();
         int count=0;
         String ren = " ";
         String huo = " ";
         int s=0;
         int d=0;
         for(int i=1;i<=c;i++){
             Scanner input11=new Scanner(System.in);
             System.out.println("请输入第"+i+"辆车的序号");
             int a=input11.nextInt();
             switch(a){
             case 1:
                 count=count+500;
                 ren=ren+"奥迪A4"+" ";
                 s=s+4;
             break;
             case 2:
                 count=count+400;
                 ren=ren+"马自达6"+" ";
                 s=s+4;
             case 3:
                 count=count+450;
                 ren=ren+"皮卡雪6"+" ";
                 s=s+4;
                 huo=huo+"皮卡雪6"+" ";
                 d=d+2;
                 break;
             case 4:
                 count=count+800;
                 ren=ren+"金龙"+" ";
                 s=s+20;
                 break;
             case 5:
                 count=count+400;
                 huo=huo+"松花江"+" ";
                 d=d+4;
                 break;
             case 6:
                 count=count+1000;
                 huo=huo+"依维柯"+" ";
                 d=d+20;
                 break;

             }
        }

         Scanner input12=new Scanner(System.in);
         System.out.println("请输入租车天数");
         int z=input12.nextInt();
         count=count*z;
         System.out.println("您的帐单:");
         System.out.println("***可载人的车有:");
         System.out.println(ren+"共载人"+s+"人");
         System.out.println("***载货的车有:");
         System.out.println(huo+"共载货:"+d+"吨");
         System.out.println("***所需支付的总金额为:"+count+"元");
     }
     else
         System.exit(0);
}

}

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