搞了一个下午才写出这些,求大神指点

来源:-

慕侠4088786

2017-08-09 16:28

import java.util.Scanner;


 class Automobile {

private String name;//汽车名字

private int rent;//汽车日租金

private int busload;//汽车载客量

private int boatload;//汽车载货量

//租车车辆属性

public void nature(int num, String name, int rent, int busload, int boatload) {

this.name = name;

this.rent = rent;

this.busload = busload;

this.boatload = boatload;

System.out.println("序号:" + num + "\t汽车名:" + name + "\t 日租金:" + rent + "元" + "\t 可载客量:" + busload + "人"

+ "\t 可载货量:" + boatload + "吨");

}


//计算账单

public static void rental(int days, int rent, int num) {

int rental = days * rent * num;

System.out.println("***您的账单***");

System.out.println("租用天数:" + days + "\t租用数量:" + num + "\t 总金额:" + rental + "元");

}


//输入租车信息

public static void dowork(int rent) {

Scanner input = new Scanner(System.in);

System.out.println("请输入您要租用的天数!");

int c = input.nextInt();

System.out.println("请输入您要租用的车辆的数量!");

int d = input.nextInt();

rental(c, rent, d);

}


}




public class RentCat {

public static void main(String[] args) {

Automobile audiA4 = new Automobile();//创建奥迪A4对象

Automobile azda6 = new Automobile();//创建马自达6对象

Automobile pick_up = new Automobile();//创建皮卡雪6对象

Automobile jinlong = new Automobile();//创建金龙对象

Automobile songhua = new Automobile();//创建松花江对象

Automobile iveco = new Automobile();//创建依维柯对象


System.out.println("欢迎来到哒哒租车系统!!");

System.out.println("您是否要租车,是按1,否按0");

Scanner input = new Scanner(System.in);

int a = input.nextInt();

if (a == 1) {

//租车价目表

System.out.println("您可租车的类型和价目表:");

audiA4.nature(1, "奥迪A4", 500, 4, 0);

azda6.nature(2, "马自达6", 400, 4, 0);

pick_up.nature(3, "皮卡雪6", 450, 4, 2);

jinlong.nature(4, "金龙   ", 800, 20, 0);

songhua.nature(5, "松花江", 400, 0, 4);

iveco.nature(6, "依维柯", 1000, 0, 20);

} else {

System.out.println("请关闭系统!!");


}

System.out.println("请输入您要租用的汽车序号:");

int b = input.nextInt();

if (b == 1) {

audiA4.nature(1, "奥迪A4", 500, 4, 0);

Automobile.dowork(500);

} else if (b == 2) {

azda6.nature(2, "马自达6", 400, 4, 0);

Automobile.dowork(400);

} else if (b == 3) {

pick_up.nature(3, "皮卡雪6", 450, 4, 2);

Automobile.dowork(450);

} else if (b == 4) {

jinlong.nature(4, "金龙       ", 800, 20, 0);

Automobile.dowork(800);

} else if (b == 5) {

songhua.nature(5, "松花江", 400, 0, 4);

Automobile.dowork(400);

} else if (b == 6) {

iveco.nature(6, "依维柯", 1000, 0, 20);

Automobile.dowork(1000);

} else {

System.out.println("您的输入有误!!");

}


}

}


写回答 关注

2回答

  • 考考21
    2017-08-17 11:00:27

    可以选择交互式对话框输入。个人建议

  • 慕侠4088786
    2017-08-09 16:43:39

    http://img.mukewang.com/598acb290001193206250427.jpg

    输出结果


Java入门第二季 升级版

课程升级!以终为始告别枯燥,在开发和重构中体会Java面向对象编程的奥妙

531107 学习 · 6299 问题

查看课程

相似问题