Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //kravets
- public class Main
- {
- public static void main(String[] args)
- {
- Car car = new Car("BMW");
- car.upgrade_car(2000);
- car.get_properties();
- System.out.println(car.time_to_go(100, 200));
- Express express = new Express("Lastochka");
- express.buy_lunch(-2);
- }
- }
- class Vehicle
- {
- public String name;
- public float max_speed;
- Vehicle(String name)
- {
- this.name = name;
- }
- public float weight;
- public float cost;
- public int quantity_of_seats;
- public void get_properties()
- {
- System.out.println("name: " + this.name + "\nmaximum speed: " + this.max_speed + "\nweight: " + this.weight + "\ncost: " +
- this.cost + "\nplaces to seat: " + this.quantity_of_seats);
- }
- public double time_to_go(float way, int speed)
- {
- if (speed <= 0)
- return 0;
- if (speed > max_speed)
- {
- System.out.println("Your vehicle was broken!!!");
- return 0;
- }
- else
- return (way / speed);
- }
- }
- class Car extends Vehicle
- {
- Car(String name)
- {
- super(name);
- this.name = name;
- super.max_speed = 150;
- super.quantity_of_seats = 4;
- super.weight = 1000;
- super.cost = 10000;
- }
- public void upgrade_car(float money)
- {
- if (money <= 0)
- System.out.println("You can`t buy anything for $ " + money);
- else
- {
- System.out.println("The car`s was engine upgraded, now it has higher maximum speed!");
- super.max_speed += money / 100;
- }
- }
- public void replace_wheel(int number)
- {
- if (number > 4)
- System.out.println("You can`t replace more wheels than your car has!!!");
- else if (number<=0)
- System.out.println("You wanna replace " + number + " wheels? Are you seriously?");
- else
- System.out.println("Successfully replaced " + number + " wheels.");
- }
- }
- class Train extends Vehicle
- {
- public int number_of_trains;
- public int seats_in_1_train = 40;
- public int weight_of_1_train = 24000;
- public float ticket_price;
- Train(String name)
- {
- super(name);
- this.name = name;
- this.number_of_trains = 7;
- super.max_speed = 115;
- super.quantity_of_seats = seats_in_1_train * number_of_trains;
- super.weight = 25000 + weight_of_1_train * number_of_trains;
- super.cost = 2000000 + 700000 * number_of_trains;
- this.ticket_price = 20;
- }
- public void buy_tickets(int quantity)
- {
- if (quantity <= 0)
- System.out.println("You must set positive number of tickets!!!");
- else
- {
- System.out.println("You bought " + quantity + " ticket(s). And you spent $ " + (quantity * this.ticket_price));
- }
- }
- @Override
- public void get_properties() {
- System.out.println("name: " + this.name + "\nmaximum speed: " + this.max_speed + "\nweight: " + this.weight + "\ncost: " +
- this.cost + "\nplaces to seat: " + this.quantity_of_seats + "\nprice of ticket: $ " + this.ticket_price);
- }
- }
- class Express extends Train //shvudkiy poizd
- {
- public static int price_of_lunch = 15;
- Express(String name)
- {
- super(name);
- this.name = name;
- this.number_of_trains = 5;
- super.seats_in_1_train = 35;
- super.weight_of_1_train = 19000;
- super.max_speed = 210;
- super.quantity_of_seats = seats_in_1_train * number_of_trains;
- super.weight = 22000 + weight_of_1_train * number_of_trains;
- super.cost = 3000000 + 900000 * number_of_trains;
- this.ticket_price = 50;
- }
- public void buy_lunch(int quantity)
- {
- if (quantity > 0)
- System.out.println("You bought " + quantity + " lunches (sandwich + cola)\nTotal price: $ " +
- (quantity * price_of_lunch));
- else
- System.out.println("You wanna buy " + quantity + " lunches? Seriously!?");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement