Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ASTRONAUT
- package spaceStationRecruitment;
- public class Astronaut {
- public String name;
- public int age;
- public String country;
- public Astronaut(String name, int age, String country) {
- this.name = name;
- this.age = age;
- this.country = country;
- }
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public int getAge() {
- return age;
- }
- public void setAge(int age) {
- this.age = age;
- }
- public String getCountry() {
- return country;
- }
- public void setCountry(String country) {
- this.country = country;
- }
- @Override
- public String toString() {
- return String.format("Astronaut: %s, %d (%s)",this.name,this.age,this.country) ;
- }
- }
- SPACESTATION
- package spaceStationRecruitment;
- import java.util.LinkedList;
- import java.util.List;
- public class SpaceStation {
- public String name;
- public int capacity;
- public List<Astronaut> data;
- public SpaceStation(String name, int capacity) {
- this.name = name;
- this.capacity = capacity;
- this.data = new LinkedList<>();
- }
- public String getName() {
- return name;
- }
- public int getCapacity() {
- return capacity;
- }
- public int getCount() {
- return data.size();
- }
- public void add(Astronaut astronaut) {
- if (this.capacity != 0) {
- this.data.add(astronaut);
- this.capacity--;
- }
- }
- public boolean remove(String name) {
- return this.data.removeIf(astronaut -> astronaut.getName().equals(name));
- }
- public Astronaut getOldestAstronaut() {
- return data.stream().max((f, s) -> Integer.compare(f.getAge(), s.getAge())).get();
- }
- public Astronaut getAstronaut(String name) {
- Astronaut givenName = null;
- for (Astronaut astronaut : this.data) {
- if (astronaut.getName().equals(name)) {
- givenName = astronaut;
- }
- }
- return givenName;
- }
- public String report() {
- StringBuilder sb = new StringBuilder();
- sb.append(String.format("Astronauts working at Space Station %s:", this.name));
- for (Astronaut astronaut : data) {
- sb.append(System.lineSeparator()).append(astronaut.toString());
- }
- return sb.toString().trim();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement