JAVA入门小程序

发布时间:2024-11-18 17:38

编程基础:Python或Java入门教程推荐 #生活技巧# #工作学习技巧# #专业技能培训#

public abstract class Vehicle {

private String id;

private String brand;

private int perRent;

public Vehicle(){}

public Vehicle(String id, String brand, int perRent) {

this.id = id;

this.brand = brand;

this.perRent = perRent;

}

public void setId(String id){

this.id=id ;

}

public String getId(){

return id;

}

public void setBrand(String brand){

this.brand=brand;

}

public String getBrand(){

return brand;

}

public void setPerRent(int perRent){

this.perRent=perRent;

}

public int getPerRent(){

return perRent;

}

public abstract double calcRent(int days);

}

public class Car extends Vehicle{

private String type;

public void setType(String type){

this.type=type;

}

public String getType(){

return type;

}

public Car(){}

public Car(String id, String brand, int perRent,String type) {

super(id,brand,perRent);

this.type = type;

}

public double calcRent(int days) {

double price = this.getPerRent()*days;

if(days>7 && days<=30){

price *= 0.9;

}else if(days>30 && days<=150){

price *= 0.8;

}else if(days>150){

price *= 0.7;

}

return price;

}

}

public class Bus extends Vehicle{

private int seatCount;

public void setSeatCount(int seatCount){

this.seatCount=seatCount;

}

public int getSeatCount(){

return seatCount;

}

public Bus(){}

public Bus(String id,String brand,int perRent,int seatCount){

super(id,brand,perRent);

this.seatCount = seatCount;

}

public double calcRent(int days) {

double price = this.getPerRent()*days;

if(days>=3 && days<7){

price *= 0.9;

}else if(days>=7 && days<30){

price *= 0.8;

}else if(days>=30 && days<150){

price *= 0.7;

}else if(days>150){

price *= 0.6;

}

return price;

}

}

public class Operation {

public Vehicle[] vehicle = new Vehicle[8];

public void init(){

vehicle[0] = new Car("京NY28588","宝马",800,"X6");

vehicle[1] = new Car("京CNY32584","宝马",600,"550i");

vehicle[2] = new Car("京NT37465","别克",300,"林荫大道");

vehicle[3] = new Car("京NT96968","别克",600,"GL8");

vehicle[4] = new Bus("京6566754","金杯",800,16);

vehicle[5] = new Bus("京8696997","金龙",800,16);

vehicle[6] = new Bus("京9696996","金杯",1500,34);

vehicle[7] = new Bus("京8696998","金龙",1500,34);

}

public Vehicle zuChe(String brand,String type,int seatCount){

Vehicle che = null;

for(Vehicle myche : vehicle){

if(myche instanceof Car){

Car car = (Car)myche;

if(car.getBrand().equals(brand) && car.getType().equals(type)){

che=car;

break;

}

}else{

Bus bus = (Bus)myche;

if(bus.getBrand().equals(brand) && bus.getSeatCount() == seatCount){

che=bus;

break;

}

}

}

return che;

}

}

public class Rent {

public static void main(String[] args) {

Scanner input = new Scanner(System.in);

Operation operation = new Operation();

operation.init();

System.out.println("**********欢迎光临租赁公司**********");

System.out.println("1.轿车\t\t2.客车");

System.out.println("请选择您要租赁的汽车类型:(1.轿车 2.客车)");

int cheType = input.nextInt();

String brand = "";

String type = "";

int seatCount = 0;

if(cheType == 1){

System.out.println("请选择您要租赁的轿车品牌:(1.别克 2.宝马)");

int choose = input.nextInt();

if(choose == 1){

brand="别克";

System.out.println("请选择您要租赁的汽车型号:(1.林荫大道 2.GL8)");

type=(input.nextInt() == 1)?"林荫大道":"GL8";

}else if(choose == 2){

brand="宝马";

System.out.println("请选择您要租赁的汽车型号:(1.X6 2.550i)");

type=(input.nextInt() == 1)?"X6":"550i";

}

}else if(cheType == 2){

type= "";

System.out.println("请选择您要租赁的客车品牌:(1.金杯 2.金龙)");

brand=(input.nextInt()==1)?"金杯":"金龙";

System.out.println("请选择您要租赁的客车座位数:(1.16座 2.32座)");

seatCount=(input.nextInt() == 1)?16:34;

}

Vehicle che = operation.zuChe(brand, type, seatCount);

System.out.println("请输入您的租赁天数:");

int days = input.nextInt();

double money = che.calcRent(days);

System.out.println("租车成功,请按照如下车牌号提车:"+che.getId());

System.out.println("您需要支付:"+money+"元");

}

}

网址:JAVA入门小程序 https://www.yuejiaxmz.com/news/view/122858

相关内容

java毕业设计宠物领养小程序[附源码]
java基于微信小程序的美食制作教程系统 uniapp 小程序
10年Java面试总结:Java程序员面试必备的面试技巧
java计算机毕业设计宠物养护系统(开题+程序+论文)
java计算机毕业设计东大日程app(开题+程序+论文)
Java程序员不得不会的124道面试题(含答案)
java计算机毕业设计宠物管理系统(开题+程序+论文)
【2024】穿衣搭配小程序/一周穿搭APP/小程序
基于微信小程序的时间管理小程序
java计算机毕业设计大学生体质管理app(开题+程序+论文)

随便看看