Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Airplane {
- private String name;
- private double emptyWeight;
- private int numberOfSeats;
- private double fuelConsumption;
- public Airplane() {}
- public Airplane(String name, int numberOfSeats) {
- this.name = name;
- this.numberOfSeats = numberOfSeats;
- }
- public Airplane(String name, double emptyWeight, int numberOfSeats, double fuelConsumption) {
- this.name = name;
- this.emptyWeight = emptyWeight;
- this.numberOfSeats = numberOfSeats;
- this.fuelConsumption = fuelConsumption;
- }
- public String getName() {
- return name;
- }
- public double getEmptyWeight() {
- return emptyWeight;
- }
- public int getNumberOfSeats() {
- return numberOfSeats;
- }
- public double getFuelConsumption() {
- return fuelConsumption;
- }
- public void addSeats(int x) {
- numberOfSeats += x;
- }
- public void display() {
- System.out.println("name = " + name +
- "\nemptyWeight = " + emptyWeight +
- "\nnumberOfSeats = " + numberOfSeats +
- "\nfuelConsumption = " + fuelConsumption);
- }
- public int compare(Airplane a) {
- return numberOfSeats - a.numberOfSeats;
- }
- public static void display(Airplane airplane) {
- airplane.display();
- }
- public static int compare(Airplane a, Airplane b) {
- return a.numberOfSeats - b.numberOfSeats;
- }
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- Airplane a = new Airplane("Boeing", 200);
- System.out.println(a.getNumberOfSeats());
- a.addSeats(50);
- System.out.println(a.getNumberOfSeats());
- display(a); // static
- a.display(); // instance
- Airplane b = new Airplane(
- sc.next(),
- sc.nextDouble(),
- sc.nextInt(),
- sc.nextDouble()
- );
- System.out.println(compare(a, b)); // static
- System.out.println(a.compare(b)); // instance
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment