SHARE
TWEET

sPACEsTATIONrEQUIRMENT

a guest Oct 23rd, 2019 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ASTRONAUT
  2. package spaceStationRecruitment;
  3.  
  4. public class Astronaut {
  5.     public String name;
  6.     public int age;
  7.     public String country;
  8.  
  9.     public Astronaut(String name, int age, String country) {
  10.         this.name = name;
  11.         this.age = age;
  12.         this.country = country;
  13.     }
  14.  
  15.     public String getName() {
  16.         return name;
  17.     }
  18.  
  19.     public void setName(String name) {
  20.         this.name = name;
  21.     }
  22.  
  23.     public int getAge() {
  24.         return age;
  25.     }
  26.  
  27.     public void setAge(int age) {
  28.         this.age = age;
  29.     }
  30.  
  31.     public String getCountry() {
  32.         return country;
  33.     }
  34.  
  35.     public void setCountry(String country) {
  36.         this.country = country;
  37.     }
  38.  
  39.     @Override
  40.     public String toString() {
  41.  
  42.  
  43.         return String.format("Astronaut: %s, %d (%s)",this.name,this.age,this.country) ;
  44.     }
  45. }
  46. SPACESTATION
  47. package spaceStationRecruitment;
  48.  
  49. import java.util.LinkedList;
  50. import java.util.List;
  51.  
  52. public class SpaceStation {
  53.     public String name;
  54.     public int capacity;
  55.     public List<Astronaut> data;
  56.  
  57.     public SpaceStation(String name, int capacity) {
  58.         this.name = name;
  59.         this.capacity = capacity;
  60.         this.data = new LinkedList<>();
  61.     }
  62.  
  63.     public String getName() {
  64.         return name;
  65.     }
  66.  
  67.     public int getCapacity() {
  68.         return capacity;
  69.     }
  70.  
  71.     public int getCount() {
  72.         return data.size();
  73.     }
  74.  
  75.     public void add(Astronaut astronaut) {
  76.         if (this.capacity != 0) {
  77.             this.data.add(astronaut);
  78.             this.capacity--;
  79.         }
  80.     }
  81.  
  82.     public boolean remove(String name) {
  83.         return this.data.removeIf(astronaut -> astronaut.getName().equals(name));
  84.     }
  85.  
  86.     public Astronaut getOldestAstronaut() {
  87.         return data.stream().max((f, s) -> Integer.compare(f.getAge(), s.getAge())).get();
  88.     }
  89.  
  90.     public Astronaut getAstronaut(String name) {
  91.         Astronaut givenName = null;
  92.         for (Astronaut astronaut : this.data) {
  93.             if (astronaut.getName().equals(name)) {
  94.                 givenName = astronaut;
  95.  
  96.             }
  97.         }
  98.         return givenName;
  99.     }
  100.  
  101.     public String report() {
  102.         StringBuilder sb = new StringBuilder();
  103.         sb.append(String.format("Astronauts working at Space Station %s:", this.name));
  104.         for (Astronaut astronaut : data) {
  105.             sb.append(System.lineSeparator()).append(astronaut.toString());
  106.         }
  107.         return sb.toString().trim();
  108.     }
  109.  
  110. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top