package com.rent;public class Car {private String carName;//车名private int price;//日租金private int passengerNumber;//载客数private int burden;//载货量public String getCarName() {return carName;}public void setCarName(String carName) {this.carName = carName;}public int getPrice() {return price;}public void setPrice(int price) {this.price = price;}public int getPassengerNumber() {return passengerNumber;}public void setPassengerNumber(int passengerNumber) {this.passengerNumber = passengerNumber;}public int getBurden() {return burden;}public void setBurden(int burden) {this.burden = burden;}}package com.rent;public class smallCar extends Car {public smallCar(String carName,int price,int passengerNumber) {super();this.setCarName(carName);this.setPrice(price);this.setPassengerNumber(passengerNumber);}@Overridepublic String toString() {return this.getCarName()+"\t"+this.getPassengerNumber()+"\t\t\t\t"+this.getPrice();}}package com.rent;public class Truck extends Car{public Truck(String carName,int price,int burden) {super();this.setCarName(carName);this.setPrice(price);this.setBurden(burden);}@Overridepublic String toString() {return this.getCarName()+"\t\t\t"+this.getBurden()+"\t\t"+this.getPrice();}}package com.rent;public class pickup extends Car{public pickup(String carName,int price,int passengerNumber,int burden) {super();this.setCarName(carName);this.setPrice(price);this.setPassengerNumber(passengerNumber);this.setBurden(burden);}@Overridepublic String toString() {return this.getCarName()+"\t"+this.getPassengerNumber()+"\t\t"+this.getBurden()+"\t\t"+this.getPrice();}}package com.rent;import java.util.Scanner;public class Initial {public static void main(String[] args) {Car[] cars = new Car[]{new smallCar("奥迪A4", 500, 4),new smallCar("马自达6", 400, 4),new smallCar("金龙", 800, 20),new pickup("皮卡雪6", 450, 4, 2),new Truck("松花江", 400, 4),new Truck("依维柯", 1000, 20)};System.out.println("*****欢迎使用达达租车系统");System.out.println("*****您是否要租车?1是 2否");Scanner input = new Scanner(System.in);int checkNumber = input.nextInt();if (checkNumber != 1) {System.out.println("*****欢迎下次光临,再见!*****");}else {System.out.println("*****您可租车的类型及价目表:");System.out.println("序号"+"\t车名"+"\t载客数(人)"+"\t载货量(吨)"+"\t日租金(元/天)");for (int i = 0; i < cars.length; i++) {System.out.println((i+1)+"\t"+cars[i]);}System.out.println("*****请输入您要租车的数目:");int choose = input.nextInt();Car[] rentCarNumber = new Car[choose];int totalPrice = 0;int totalPassenger = 0;int totalBurden = 0;for (int i = 0; i < choose; i++) {System.out.println("*****请输入第"+(i+1)+"辆车的序号");int carX = input.nextInt();rentCarNumber[i] = cars[carX-1];}System.out.println("*****请输入要租借的天数:");int days = input.nextInt();for (int i = 0; i < rentCarNumber.length; i++) {totalPrice = totalPrice + rentCarNumber[i].getPrice()*days;}System.out.println("*****您的账单:");System.out.println("*****已选载人的车:");for (int i = 0; i < rentCarNumber.length; i++) {if (rentCarNumber[i].getPassengerNumber() != 0) {System.out.println(rentCarNumber[i].getCarName()+"\t");}totalPassenger = totalPassenger+rentCarNumber[i].getPassengerNumber();}System.out.println("\n");System.out.println("*****已选货车:");for (int i = 0; i < rentCarNumber.length; i++) {if (rentCarNumber[i].getBurden() != 0) {System.out.println(rentCarNumber[i].getCarName()+"\t");}totalBurden = totalBurden + rentCarNumber[i].getBurden();}System.out.println('\n');System.out.println("共载客:"+totalPassenger+"人");System.out.println("共载货:"+totalBurden+"吨");System.out.println("租车总价格:"+totalPrice+"元");System.out.println('\n');System.out.println("****感谢您的惠顾,欢迎再次光临!****");}}}
添加回答
举报
0/150
提交
取消