Advertisement
Guest User

Untitled

a guest
Mar 29th, 2020
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.87 KB | None | 0 0
  1. class Office {
  2.     private int amount;
  3.     private String[] people;
  4.     private String location;
  5.  
  6.     public Office(String location, int n){
  7.         amount=0;
  8.         if(n<0){
  9.             people = new String[0];
  10.         }
  11.         else if(n>0){
  12.             people = new String[n];
  13.         }
  14.         this.location=location;
  15.     }
  16.  
  17.     public String getLocation(){
  18.         return location;
  19.     }
  20.  
  21.     public String[] getPeople(){
  22.         return people;
  23.     }
  24.  
  25.     public void addPerson(String p){
  26.         if(amount > people.length){
  27.            throw new ArrayIndexOutOfBoundsException();
  28.         }
  29.         people[amount]=p;
  30.         amount++;
  31.     }
  32.  
  33.     public void replacePerson(String replace, String with){
  34.         for(int i=0;i<amount;i++){
  35.             if(people[i].compareTo(replace) == 0){
  36.                 people[i]=with;
  37.             }
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement