Advertisement
darkor

lab_2

Feb 25th, 2020
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.13 KB | None | 0 0
  1. //kravets
  2. public class Main
  3. {
  4.     public static void main(String[] args)
  5.     {
  6.         Car car = new Car("BMW");
  7.         car.upgrade_car(2000);
  8.         car.get_properties();
  9.         System.out.println(car.time_to_go(100, 200));
  10.  
  11.         Express express = new Express("Lastochka");
  12.         express.buy_lunch(-2);
  13.     }
  14. }
  15.  
  16. class Vehicle
  17. {
  18.     public String name;
  19.     public float max_speed;
  20.  
  21.     Vehicle(String name)
  22.     {
  23.         this.name = name;
  24.     }
  25.  
  26.     public float weight;
  27.     public float cost;
  28.     public int quantity_of_seats;
  29.  
  30.     public void get_properties()
  31.     {
  32.         System.out.println("name: " + this.name + "\nmaximum speed: " + this.max_speed + "\nweight: " + this.weight + "\ncost: " +
  33.                 this.cost + "\nplaces to seat: " + this.quantity_of_seats);
  34.     }
  35.  
  36.     public double time_to_go(float way, int speed)
  37.     {
  38.         if (speed <= 0)
  39.             return 0;
  40.         if (speed > max_speed)
  41.         {
  42.             System.out.println("Your vehicle was broken!!!");
  43.             return 0;
  44.         }
  45.         else
  46.             return (way / speed);
  47.     }
  48. }
  49.  
  50. class Car extends Vehicle
  51. {
  52.     Car(String name)
  53.     {
  54.         super(name);
  55.         this.name = name;
  56.         super.max_speed = 150;
  57.         super.quantity_of_seats = 4;
  58.         super.weight = 1000;
  59.         super.cost = 10000;
  60.     }
  61.     public void upgrade_car(float money)
  62.     {
  63.         if (money <= 0)
  64.             System.out.println("You can`t buy anything for $ " + money);
  65.         else
  66.         {
  67.             System.out.println("The car`s was engine upgraded, now it has higher maximum speed!");
  68.             super.max_speed += money / 100;
  69.         }
  70.     }
  71.  
  72.     public void replace_wheel(int number)
  73.     {
  74.         if (number > 4)
  75.             System.out.println("You can`t replace more wheels than your car has!!!");
  76.         else if (number<=0)
  77.             System.out.println("You wanna replace " + number + " wheels? Are you seriously?");
  78.         else
  79.             System.out.println("Successfully replaced " + number + " wheels.");
  80.     }
  81. }
  82.  
  83. class Train extends Vehicle
  84. {
  85.     public int number_of_trains;
  86.     public int seats_in_1_train = 40;
  87.     public int weight_of_1_train = 24000;
  88.     public float ticket_price;
  89.     Train(String name)
  90.     {
  91.         super(name);
  92.         this.name = name;
  93.         this.number_of_trains = 7;
  94.         super.max_speed = 115;
  95.         super.quantity_of_seats = seats_in_1_train * number_of_trains;
  96.         super.weight = 25000 + weight_of_1_train * number_of_trains;
  97.         super.cost = 2000000 + 700000 * number_of_trains;
  98.         this.ticket_price = 20;
  99.     }
  100.     public void buy_tickets(int quantity)
  101.     {
  102.         if (quantity <= 0)
  103.             System.out.println("You must set positive number of tickets!!!");
  104.         else
  105.         {
  106.             System.out.println("You bought " + quantity + " ticket(s). And you spent $ " + (quantity * this.ticket_price));
  107.         }
  108.     }
  109.  
  110.     @Override
  111.     public void get_properties() {
  112.         System.out.println("name: " + this.name + "\nmaximum speed: " + this.max_speed + "\nweight: " + this.weight + "\ncost: " +
  113.                 this.cost + "\nplaces to seat: " + this.quantity_of_seats + "\nprice of ticket: $ " + this.ticket_price);
  114.     }
  115. }
  116.  
  117. class Express extends Train //shvudkiy poizd
  118. {
  119.     public static int price_of_lunch = 15;
  120.     Express(String name)
  121.     {
  122.         super(name);
  123.         this.name = name;
  124.         this.number_of_trains = 5;
  125.         super.seats_in_1_train = 35;
  126.         super.weight_of_1_train = 19000;
  127.         super.max_speed = 210;
  128.         super.quantity_of_seats = seats_in_1_train * number_of_trains;
  129.         super.weight = 22000 + weight_of_1_train * number_of_trains;
  130.         super.cost = 3000000 + 900000 * number_of_trains;
  131.         this.ticket_price = 50;
  132.     }
  133.     public void buy_lunch(int quantity)
  134.     {
  135.         if (quantity > 0)
  136.             System.out.println("You bought " + quantity + " lunches (sandwich + cola)\nTotal price: $ " +
  137.                     (quantity * price_of_lunch));
  138.         else
  139.             System.out.println("You wanna buy " + quantity + " lunches? Seriously!?");
  140.     }
  141. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement