Create Airplane.java

This commit is contained in:
mayfff 2023-02-23 15:18:47 +02:00 committed by GitHub
parent 33f8aa39e1
commit 71b6763c9d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 59 additions and 0 deletions

View File

@ -0,0 +1,59 @@
import java.util.Comparator;
public class Airplane {
private String name;
private String type;
private int weight;
private int amountOfEngines;
private int year;
private String color;
private int capacity;
private int price;
public Airplane(String name, String type, int weight, int amountOfEngines, int year, String color, int capacity, int price) {
this.name = name;
this.type = type;
this.weight = weight;
this.amountOfEngines = amountOfEngines;
this.year = year;
this.color = color;
this.capacity = capacity;
this.price = price;
}
public int getPrice() {
return price;
}
public int getYear() {
return year;
}
@Override
public String toString() {
return "Plane : " +
"name = " + name +
", type = " + type +
", weight = " + weight + " tons" +
", amount of engines = " + amountOfEngines +
", year = " + year +
", color = " + color +
", capacity = " + capacity +
", price = " + price + " millions dollars.";
}
}
class SortByPrice implements Comparator<Airplane> {
public int compare(Airplane a, Airplane b) {
return a.getPrice() - b.getPrice();
}
}
class SortByYear implements Comparator<Airplane> {
public int compare(Airplane a, Airplane b) {
return a.getYear() - b.getYear();
}
}