Created
July 31, 2021 15:33
-
-
Save TuHuynhVan/6deadbe31de35a30f58ba31cfe50b79f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package exercises.constructor; | |
import java.util.Arrays; | |
import java.util.List; | |
public class Vehicle { | |
private final double BYCICLE_PRICE = 1; | |
private final double ELECTRIC_BYCICLE_PRICE = 3; | |
private final double MOTOR_BYCICLE_PRICE = 5; | |
private final String BYCICLE_NAME = "dap"; | |
private final String ELECTRIC_BYCICLE_NAME = "dien"; | |
private final String MOTOR_BYCICLE_NAME = "may"; | |
private double priceFactor = 1.5; | |
private String vehicleType; | |
private double vehiclePrice; | |
private String location; | |
public Vehicle() { | |
} | |
public Vehicle(String vehicleType) { | |
this.vehicleType = vehicleType; | |
setSpecialPrice(vehicleType); | |
} | |
public Vehicle(String vehicleType, String location) { | |
this.vehicleType = vehicleType; | |
this.location = location; | |
setSpecialPrice(vehicleType); | |
} | |
private void setVehiclePrice(double vehiclePrice) { | |
this.vehiclePrice = vehiclePrice; | |
} | |
private void setSpecialPrice(String vehicleType) { | |
boolean isSpecialLocation = this.location !=null; | |
switch (vehicleType) { | |
case BYCICLE_NAME: | |
setVehiclePrice(isSpecialLocation ? BYCICLE_PRICE * priceFactor : BYCICLE_PRICE); | |
break; | |
case ELECTRIC_BYCICLE_NAME: | |
setVehiclePrice(isSpecialLocation ? ELECTRIC_BYCICLE_PRICE * priceFactor : ELECTRIC_BYCICLE_PRICE); | |
break; | |
case MOTOR_BYCICLE_NAME: | |
setVehiclePrice(isSpecialLocation ? MOTOR_BYCICLE_PRICE * priceFactor : MOTOR_BYCICLE_PRICE); | |
break; | |
} | |
} | |
public String getVehicleType() { | |
return vehicleType; | |
} | |
public void setVehicleType(String vehicleType) { | |
this.vehicleType = vehicleType; | |
} | |
public double getVehiclePrice() { | |
return vehiclePrice; | |
} | |
public String getLocation() { | |
return location; | |
} | |
public void setLocation(String location) { | |
this.location = location; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment