package second;
public abstract class Car {
String name;
double price;
int seatingCapacity;
float carryCapacity;
}
package second;
public class Trust extends Car{
public Trust(String name, double price, float carryCapacity) {
this.name = name;
this.price = price;
this.carryCapacity = carryCapacity;
}
@Override
public String toString() {
return name + "\t" + price + "元/天\t" + "载货:" + carryCapacity + "吨";
}
}
package second;
public class Bus extends Car{
public Bus(String name, double price, int seatingCapacity) {
this.name = name;
this.price = price;
this.seatingCapacity = seatingCapacity;
}
@Override
public String toString() {
return name + "\t" + price + "元/天\t" + "载人:" + seatingCapacity + "人 ";
}
}
package second;
public class PickUp extends Car{
public PickUp(String name,double price,int seatingCapacity,float carryCapacity) {
this.name=name;
this.price=price;
this.seatingCapacity=seatingCapacity;
this.carryCapacity=carryCapacity;
}
@Override
public String toString() {
return name+"\t"+price+"元/天\t"+"载人:"+seatingCapacity+"人 "+"载货:"+carryCapacity+"吨";
}
}
package second;
import java.util.Scanner;
public class Initial {
public static void main(String[] args) {
Car[] car = { new Bus("奥迪A4", 500, 4), new Bus("马自达6", 400, 4), new PickUp("皮卡雪", 450, 4, 2),
new Bus("金龙", 800, 20), new Trust("松花江", 400, 4), new Trust("依维柯", 100, 20) };
System.out.println("欢迎试用答答租车系统:");
System.out.println("您是否要租车:1是 0否");
Scanner in = new Scanner(System.in);
int input = in.nextInt();
if (input == 1) {
System.out.println("您可租车的类型及其价目表:");
System.out.println("序号\t汽车名称\t租金\t\t容量");
for (int i = 0; i < car.length; i++) {
System.out.println((i + 1) + ".\t" + car[i]);
}
String carCarry = "";
String carPeople = "";
float allCarry = 0;
int allPeople = 0;
double allPrice = 0;
System.out.println("请输入您要租车的数量:");
int count = in.nextInt();
for (int i = 0; i < count; i++) {
System.out.println("请输入第" + (i + 1) + "辆车的序号");
int a = in.nextInt();
System.out.println("该车为:" + car[i].name);
System.out.println("请输入租车的天数:");
int b = in.nextInt();
if (car[i].seatingCapacity != 0) {
carPeople += car[i].name+" " ;
allPeople += car[i].seatingCapacity;
}
if (car[i].carryCapacity != 0) {
carCarry += car[i].name+" " ;
allCarry += car[i].carryCapacity;
}
allPrice += car[i].price * b;
}
System.out.println("您的账单:");
System.out.println("****在载人的车有:\n" + carPeople);
System.out.println("****在载货的车有:\n" + carCarry);
System.out.print("总租金为:"+allPrice);
} else
return;
}
}
共同学习,写下你的评论
评论加载中...
作者其他优质文章