Kodomo

Пользователь

Учебная страница курса биоинформатики,
год поступления 2010

   1 package lesson2;
   2 
   3 public class OfficeLife
   4 {
   5         public static void main(String[] args)
   6         {
   7                 Boss boss = new Boss("Alfred", "Lee");
   8                 // candidates for secretary position
   9                 Secretary[] secretary_candidates = new Secretary[3];
  10                 secretary_candidates[0] = 
  11                         new Secretary("Marie", "Johnson", (int) (Math.random() * 40)+1);
  12                 secretary_candidates[1] = 
  13                         new Secretary("Kate", "Smith", (int) (Math.random() * 40)+1);
  14                 secretary_candidates[2] = 
  15                         new Secretary("Lydia","Ferr",(int)(Math.random()*40)+1); 
  16                 
  17                 // secretary that works in the office in the current period of time
  18                 Secretary secretary=null;
  19                 
  20                 // the cycle of office life
  21                 for(int day_num=1;;day_num++)
  22                 {
  23                         System.out.println(day_num+" day.");
  24                         if(boss.isSleeping())
  25                         {
  26                                 // boss is sleeping and can't do anyting
  27                                 continue;
  28                         }
  29                         // when boss has some job for a secretary he checks if he has one
  30                         if(!boss.checkSecretaryAvailability())
  31                         {
  32                                 // if Boss have no engaged secretary 
  33                                 // he try to engage one of the candidates
  34                                 secretary = boss.chooseAndAppointSecretary(secretary_candidates);
  35                                 // if no secretary was appointed the life cycle ends
  36                                 if(secretary==null)
  37                                 {
  38                                         System.out.println(
  39                                                 "There are no secretaries to be engaged."
  40                                                 + " Boss have to print the documents himself.");
  41                                         break;
  42                                 }
  43                                 System.out.println("Secretary "+secretary.getFullName()+
  44                                 " with "+secretary.getNailsLength()+
  45                                 " mm nails was engaged.");
  46                         }
  47                         // Boss ask his secretary to print the documents, 
  48                         if(boss.secretaryToPrintDocuments())
  49                         {
  50                                 // if the secretary succeeds Boss thanks her kindly
  51                                 boss.speak("Thank you "+secretary.getName()+
  52                                         "! Oh, your nails are so beautiful! " +
  53                                         "Do you want to spend this weekend in the Alps?..");
  54                         }
  55                         else
  56                         {
  57                                 // if the secretary fails Boss discharges her
  58                                 boss.dischargeSecretary();
  59                         }
  60                         // and this story repeats again and again while there are appropriate candidates...
  61                 }
  62         }
  63 }