Advertisement
16120

Airline

May 15th, 2019
9,470
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.44 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Program {
  4.  
  5.     public static void main(String[] args) {
  6.         Scanner sc = new Scanner(System.in);
  7.         String name;
  8.         double maxLoad;
  9.         double seats;
  10.         System.out.printf("Enter the name of the plane: ");
  11.         name = sc.nextLine();
  12.         System.out.printf("Enter number of max passengers:");
  13.         maxLoad = sc.nextDouble();
  14.         Plane p1 = new Plane(name, maxLoad);
  15.         System.out.printf("Enter the amount of the plane: ");
  16.         seats = sc.nextDouble();
  17.         System.out.println("Result:");
  18.         Passengers ps1 = new Passengers(seats);
  19.         p1.add(ps1);
  20.     }
  21.  
  22. }
  23. ----------------------------------
  24. import java.util.ArrayList;
  25.  
  26. public class Plane {
  27.     private String name;
  28.     private double maxLoad;
  29.     private ArrayList<Passengers> cargo;
  30.    
  31.     public Plane(String name, double maxLoad) {
  32.         this.name = name;
  33.         this.maxLoad = maxLoad;
  34.         this.cargo = new ArrayList<Passengers>();
  35.     }
  36.  
  37.     public void add(Passengers patnici) {
  38.         if(patnici.getSeats() > this.maxLoad) {
  39.             System.out.println(this.name + " can't load " + patnici.getSeats());
  40.         } else {
  41.             System.out.println(this.name + " loaded " + patnici.getSeats());
  42.             this.cargo.add(patnici);
  43.         }
  44.     }
  45.  
  46. }
  47. ------------------------------------
  48.  
  49. public class Passengers {
  50.     private double seats;
  51.    
  52.     public Passengers(double seats) {
  53.         this.seats = seats;
  54.     }
  55.  
  56.     public double getSeats() {
  57.         return seats;
  58.     }
  59.  
  60.     public void setSeats(double seats) {
  61.         this.seats = seats;
  62.     }
  63.    
  64.    
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement