Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Main {
- public static void main(String[] args) {
- Transport t = new Transport("Car", 1500);
- System.out.println(t.GetInfo(5));
- Transport d = new Transport("Car", -1000);
- System.out.println(d.GetInfo(2));
- Car c1 = new Car("Audi", 500, "premium", 50);
- System.out.println(c1.GetInfo(1));
- }
- }
- class Transport {
- public double rentPrice;
- public String name;
- public String GetInfo(int hours){
- return name + "............" + (rentPrice * hours);
- }
- //setters
- public void SetRentPrice(double rentPrice){
- if(rentPrice >= 0){
- this.rentPrice = rentPrice;
- }else{
- this.rentPrice = 0;
- System.out.println("Error: negative rent price");
- }
- }
- //constructors
- public Transport(String name, double rentPrice){
- SetRentPrice(rentPrice);
- this.name = name;
- }
- }
- class Car extends Transport {
- /*
- "eco" - 100%
- "business" - 120%
- "premium" - 200%
- */
- public String complectation;
- public int extraPrice;
- public Car(String name, double rentPrice, String complectation, int extraPrice){
- super(name, rentPrice);
- SetPrice(extraPrice);
- this.complectation = complectation;
- }
- public void SetPrice(int extraPrice){
- if(extraPrice >= 0){
- this.extraPrice = extraPrice;
- }else{
- this.extraPrice = 0;
- System.out.println("Error");
- }
- }
- @Override
- public String GetInfo(int hours){
- double finalRentPrice;
- switch(complectation){
- case ("eco"):
- finalRentPrice = rentPrice;
- break;
- case ("business"):
- finalRentPrice = rentPrice * 1.2;
- break;
- case ("premium"):
- finalRentPrice = rentPrice * 2;
- break;
- default:
- System.out.println("Error: incorrect complectation!");
- finalRentPrice = rentPrice;
- }
- return name + "............" + (finalRentPrice * hours + extraPrice);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement