Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Program {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- String name;
- double maxLoad;
- double seats;
- System.out.printf("Enter the name of the plane: ");
- name = sc.nextLine();
- System.out.printf("Enter number of max passengers:");
- maxLoad = sc.nextDouble();
- Plane p1 = new Plane(name, maxLoad);
- System.out.printf("Enter the amount of the plane: ");
- seats = sc.nextDouble();
- System.out.println("Result:");
- Passengers ps1 = new Passengers(seats);
- p1.add(ps1);
- }
- }
- ----------------------------------
- import java.util.ArrayList;
- public class Plane {
- private String name;
- private double maxLoad;
- private ArrayList<Passengers> cargo;
- public Plane(String name, double maxLoad) {
- this.name = name;
- this.maxLoad = maxLoad;
- this.cargo = new ArrayList<Passengers>();
- }
- public void add(Passengers patnici) {
- if(patnici.getSeats() > this.maxLoad) {
- System.out.println(this.name + " can't load " + patnici.getSeats());
- } else {
- System.out.println(this.name + " loaded " + patnici.getSeats());
- this.cargo.add(patnici);
- }
- }
- }
- ------------------------------------
- public class Passengers {
- private double seats;
- public Passengers(double seats) {
- this.seats = seats;
- }
- public double getSeats() {
- return seats;
- }
- public void setSeats(double seats) {
- this.seats = seats;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement