1.展示所有可租车辆
2.选择车型、租车量
3.展示租车清单,包含:总金额、总载货量及其车型、总载人量及其车型
在设计应用程序之前,应该明确该应用程序必须执行哪些任务。分析业务需求是应用程序开发中的最重要步骤之一。确认业务需求的目的在于创建一个能同时满足零售商和消费者需要的解决方案。
本题目背景,只需要考虑消费者即可:选车、租车天数、统计金额、载客、货量
如选车,如果用户输入数字1,则选择的是a车
显示:用户可以看到的信息提示界面
流程:显示信息的执行过程、步骤
本题目中,要以命令行的方式显示提示信息和输出结果信息,要考虑其样式,用户输入的数据不同,信息该如何提示、如何处理并显示出结果,这部分知识囊括了显示与流程的内容,例如:请选择车辆--请输入序号--输出总金额...
Car.java
public class Car {
protected String name; protected int rent; public Car(String name, int rent) {
this.name = name; this.rent = rent; } public String getName() {
return this.name; } public int getRent() {
return this.rent; }}
Truck.java
public class Truck extends Car {
protected double product; public Truck(String name, int rent, double product) {
super(name, rent); // TODO Auto-generated constructor stub this.product = product; } public double getProduct() {
return this.product; } }
Bus.java
public class Bus extends Car {
protected int person; public Bus(String name, int rent, int person) {
super(name, rent); // TODO Auto-generated constructor stub this.person = person; } public int getPerson() {
return this.person; }}
Pickup.java
public class Pickup extends Car {
protected double product; protected int person; public Pickup(String name, int rent,double product,int person) {
super(name, rent); // TODO Auto-generated constructor stub this.person = person; this.product = product; } public double getProduct() {
return this.product; } public int getPerson() {
return this.person; }}
Initial.java
import java.util.Scanner;public class Initial {
public static void main(String[] args) {
// TODO Auto-generated method stub System.out.println("欢迎光临达达租车系统"); System.out.println("请选择服务:租车 1 不租 0"); Scanner scan = new Scanner(System.in); int x = scan.nextInt(); if(x==1) {
System.out.println("您可租车的类型及其价目表"); System.out.println("序号"+" "+"汽车名称"+" "+"租金"+" "+"容量"); Car[] cars = {
new Bus("奥迪A4",500,4), new Bus("马自达6",400,4), new Pickup("皮卡雪6",450,2,4), new Bus("金龙",800,20), new Truck("松花江",400,4), new Truck("依维柯",1000,20) }; for(int i=0;i< cars.length;i++) {
int index = i+1; if(cars[i] instanceof Bus) {
Bus car = (Bus) cars[i]; System.out.println(index+". "+car.name+" "+car.rent+" 载人:"+car.person+"人"); }else if(cars[i] instanceof Truck) {
Truck car = (Truck) cars[i]; System.out.println(index+". "+car.name+" "+car.rent+" 载货:"+car.product+"吨"); }else {
Pickup car = (Pickup) cars[i]; System.out.println(index+". "+car.name+" "+car.rent+" 载人:"+car.person+"人 载货:"+car.product+"吨"); } } System.out.println("请输入您要租汽车的数量:"); Scanner scanTotal = new Scanner(System.in); int total = scanTotal.nextInt(); String carName = ""; double carRent = 0; int carPerson = 0; int carProduct = 0; String truckName = ""; String busName = ""; for(int i=0;i System.out.println("请输入第"+(i+1)+"辆车的序号:"); Scanner scanIndex = new Scanner(System.in); int index = scanIndex.nextInt(); carName = carName+cars[index-1].name+" "; carRent = carRent+cars[index-1].rent; if(cars[index-1] instanceof Bus) {
Bus car1 = (Bus) cars[index-1]; carPerson += car1.person; busName = busName+car1.name+" "; }else if(cars[index-1] instanceof Truck) {
Truck car1 = (Truck) cars[index-1]; carProduct += car1.product; truckName = truckName+car1.name+" "; }else {
Pickup car1 = (Pickup) cars[index-1]; carPerson += car1.person; carProduct += car1.product; busName = busName+car1.name+" "; truckName = truckName+car1.name+" "; } } System.out.println("请输入租车天数:"); Scanner scanDay = new Scanner(System.in); int day = scanDay.nextInt(); carRent = day*carRent; System.out.println("您的账单:"); System.out.println("***您所租的车有:"); System.out.println(carName); System.out.println("***可载人的车有:"); System.out.println(busName+" 共载人:"+carPerson+"人"); System.out.println("***可载货的车有:"); System.out.println(truckName+"共载货:"+carProduct+"吨"); System.out.println("***租车总价格"+carRent+"元"); }else if(x==0) {
System.out.println("退出访问,谢谢!"); } }}