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

不管怎么样,这是我第一次自己动手写这么长的程序,请各位幕友多多指教

小毛豆
关注TA
已关注
手记 1
粉丝 0
获赞 3

package com.x;

import java.util.Scanner;
public class RentTest {
public int i,money,tPerson,tThing;/i表示车的序号,name 车的名称, money租金
tPerson 载人数 tThing 载货量
/
public String name;
public RentTest(int i,String name,int money,int tPerson,int tThing){
this.i=i;
this.name=name;
this.money=money;
this.tThing=tThing;
this.tPerson=tPerson;
System.out.print(this.i+"、 " +this.name+" "+this.money+"元/天 ");
if(this.tPerson!=0){
System.out.print("载人:"+this.tPerson+"人 ");

    }
    else
        System.out.printf("");
    if(this.tThing!=0)
        System.out.printf("载货:"+this.tThing+"吨");
    else 
        System.out.print("");
    System.out.println("");
}
public static void main(String[] args) {
    Scanner input=new Scanner(System.in);
    System.out.println("欢迎使用答答租车系统:");
    System.out.println("您是否要租车:1是 0否");
    input.nextInt();
    System.out.println("您可租车的类型及价目表:");
    RentTest audi=new RentTest(1,"奥迪A4",500,4,0);
    RentTest mazda=new RentTest(2,"马自达6",400,4,0);
    RentTest pika=new RentTest(3, "皮卡雪5", 450,4,2);
    RentTest jlong=new RentTest(4, "金龙",800,20,0);
    RentTest sHua=new RentTest(5,"松花江",400,0,4);
    RentTest yiW=new RentTest(6, "依维柯",1000,0,20);
    System.out.println("请输入您要租车的数量:");
    int i=input.nextInt();
    int[] n=new int[i];
    for(int j=0;j<i;j++){
        System.out.println("请输入第"+(j+1)+"辆车的序号:");
        n[j]=input.nextInt();
    }
    System.out.println("请输入租车天数:");
    int k=input.nextInt();
    System.out.println("***可载人的车有:");
    int sum=0,person=0,things=0;
    for(int j=0;j<i;j++){
        switch (n[j]) {
        case 1:
            System.out.print("奥迪A4  ");
            sum+=500;
            person+=4;
            break;
        case 2:
            System.out.print("马自达6  ");
            sum+=500;
            person+=4;
            break;
            case 3:
                System.out.print("皮卡雪6  ");
                sum+=450;
                person+=4;
                things+=2;
                break;
            case 4:
                System.out.print("金龙     ");
                sum+=800;
                person+=20;
                break;
            case 5:
                System.out.print("松花江    ");
                sum+=400;
                things+=4;
                break;
            case 6:
                System.out.print("依维柯   ");
                sum+=1000;
                things+=20;
                break;
            default:
                break;
        }
    }
    System.out.print("   共载人:"+person+"人");
    System.out.println("");
    System.out.println("***可载货的车有:");
    for(int j=0;j<i;j++){
        switch (n[j]) {
        case 3:
            System.out.print("皮卡雪6  ");
            break;
        case 5:
            System.out.print("松花江    ");
            break;
        case 6:
            System.out.print("依维柯   ");
            break;

        default:
            break;
        }
    }
    System.out.print("   共载货:"+things+"吨");
    System.out.println("");
    System.out.print("***租车总价格:"+k*sum);

}

}

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

热门评论

好好。慢慢来,路还长。

查看全部评论