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

java第二季最后一题项目

qq_小生莫怕_03245556
关注TA
已关注
手记 1
粉丝 0
获赞 0

package javahhh;

public class Car {
public String name;
public int money;
public int people;
public int huowu;

}

package javahhh;

public class Dache extends Car {
public Dache(String name,int money,int huowu){
this.name = name;
this.money = money;
this.huowu = huowu;
}

@Override
public String toString() {
    return "大挂车 [名称=" + name + ", 金钱=" + money +"/天"+ ", 载货=" + huowu+"吨" 

            + "]";
}

}

package javahhh;

public class Pika extends Car {
public Pika(String name,int money,int people,int huowu){
this.name = name;
this.money = money;
this.people = people;
this.huowu = huowu;
}

@Override
public String toString() {
    return "皮卡 [名称=" + name + ", 金钱=" + money +"/天"+ ", 载人=" + people +",载货="+huowu+"吨"

            + "]";
}

}

package javahhh;

public class Xiaoche extends Car {
public Xiaoche(String name,int money,int people){
this.name = name;
this.money = money;
this.people = people;
}

@Override
public String toString() {
    return "小车 [名称=" + name + ", 金钱=" + money +"/天"+ ", 载人=" + people 

            + "]";
}

}

package javahhh;

import java.util.Scanner;

public class ceshi {
static Scanner scanner = new Scanner(System.in);
static Car car[] = {new Xiaoche("奥迪", 500, 5),new Xiaoche("马自达", 400, 5),
new Pika("皮卡", 450, 2, 2),new Dache("五十铃", 600, 6),new Dache("大挂车", 100, 20)};

public static void main(String[] args) {
    // TODO Auto-generated method stub

    ceshi cs = new ceshi();
    System.out.println("你是否需要租车?1.是,2否");
    int select = scanner.nextInt();
    if (select == 2) {
        scanner.close();
        System.out.println("谢谢你的光临");
        System.exit(-1);

    }
    System.out.println("你可租车的类型如下");
    System.out.println("序号    汽车名称      租金             容量");
    System.out.println("  1    奥迪             500/天       5人");
    System.out.println("  2    马自达          400/天       5人");
    System.out.println("  3    皮卡             450/天        5人");
    System.out.println("  4    五十铃          600/天        5人");
    System.out.println("  5    大挂车          1000/天      5人");
    int xz = scanner.nextInt();
    if (xz>0&&xz<car.length) {
        System.out.println("你要租用的车是"+xz+car[xz-1]);
    }else {
        System.err.println("你输入有误");

    }

    System.out.println("你需要租用几天");
    int tianshu = scanner.nextInt();
    System.out.println("你租用的车"+car[xz-1]+"租用的天数是"+tianshu+"总金额"+car[xz-1].money*tianshu);

}

}

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