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

**记录下第一次敲代码**课程《JAVA入门第二季》项目实战 达达租车系统

qq_析木_0
关注TA
已关注
手记 1
粉丝 8
获赞 0
package com.imooc;
import java.util.Scanner;
public class Test {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
         Aodi aodi=new Aodi();
         Mazida mazida=new Mazida();
         Pikaxue pikaxue=new Pikaxue();
         Jinlong jinlong=new Jinlong();
         Songhuajiang songhuajiang=new Songhuajiang();
         Yiweike yiweike=new Yiweike();

        System.out.println("欢迎使用达达租车系统:");
        System.out.println("您是否要租车:1 是  2 否");
        Scanner input=new Scanner(System.in);
        int answer=input.nextInt();
        if (answer==1){
            System.out.println("序号\t"+"汽车名称\t"+"租金\t\t"+"容量\t\t\t"); 
            System.out.println(aodi.num+"."+"\t"+aodi.name+"\t"+aodi.money+"元/每天"+"\t"+"载人:"+aodi.peopleMount+"人");
            System.out.println(mazida.num+"."+"\t"+mazida.name+"\t"+mazida.money+"元/每天"+"\t"+"载人"+mazida.peopleMount+"人");
            System.out.println(pikaxue.num+"."+"\t"+pikaxue.name+"\t"+pikaxue.money+"元/每天"+"\t"+"载人"+pikaxue.peopleMount+"人"+"\t"+"载重:"+pikaxue.goodsMount+"吨");
            System.out.println(jinlong.num+"."+"\t"+jinlong.name+"\t"+jinlong.money+"元/每天"+"\t"+"载人:"+jinlong.peopleMount+"人");
            System.out.println(songhuajiang.num+"."+"\t"+songhuajiang.name+"\t"+songhuajiang.money+"元/每天"+"\t"+"载重:"+songhuajiang.goodsMount+"吨");
            System.out.println(yiweike.num+"."+"\t"+yiweike.name+"\t"+yiweike.money+"元/每天"+"\t"+"载重:"+yiweike.goodsMount+"吨");
        }
         System.out.println("请输入您要租汽车的数量:");
         Scanner input2=new Scanner(System.in);
         int count=input2.nextInt();
         int totalCount=0;
         int totalprice=0;
         int totalload=0;
         String a = null;
         String b = null;
         for(int i=1;i<=count;i++){
             System.out.println("请输入第"+i+"辆车的序号:");
             Scanner input3=new Scanner(System.in);
             int carCount=input3.nextInt();
             if(carCount==aodi.num){
                 totalCount=totalCount+aodi.peopleMount;
                 totalprice=totalprice+aodi.money;
                 a=aodi.name;
             }else if(carCount==mazida.num){
                 totalCount=totalCount+mazida.peopleMount;  
                 totalprice=totalprice+mazida.money;
                 a=a+"\t"+mazida.name;
             }else if(carCount==pikaxue.num){
                 totalCount=totalCount+pikaxue.peopleMount;
                 totalprice=totalprice+pikaxue.money;
                 totalload=totalload+pikaxue.goodsMount;
                 a=a+"\t"+pikaxue.name;
                 b=b+"\t"+pikaxue.name;
             }else if(carCount==jinlong.num){
                 totalCount=totalCount+jinlong.peopleMount; 
                 totalprice=totalprice+jinlong.money;
                 a=a+"\t"+jinlong.name;
             }else if(carCount==songhuajiang.num){
                 totalprice=totalprice+songhuajiang.money;
                 totalload=totalload+songhuajiang.Goodsmonut;   
                 a=a+"\t"+songhuajiang.name;
                 b=b+"\t"+songhuajiang.name;
             }else if(carCount==yiweike.num){
                 totalprice=totalprice+yiweike.money;
                 totalload=totalload+yiweike.Goodsmonut;
                 a=a+"\t"+yiweike.name;
                 b=b+"\t"+yiweike.name;
             }
            }
         System.out.println("请输入租车天数:");
         Scanner input4=new Scanner(System.in);
          int carDay=input.nextInt();
          System.out.println("您的账单:");
          System.out.println("可载人的车有:"+a+"\t共载人:"+totalCount+"人");
          System.out.println("可载货的车有:"+b+"\t共载货:"+totalload+"吨");
         System.out.println("**租车总价格"+totalprice*carDay+"元"); 
    }
}

运行结果:
图片描述

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