Учебная страница курса биоинформатики,
год поступления 2010
1 package lesson2;
2
3 public class Secretary
4 {
5 // maximum allowable lenght of nails
6 int max_nails_length = 35;
7
8 // secretary name
9 String name;
10
11 // secretary surname
12 String surname;
13
14 // length of the secretary's nails
15 int nails_length;
16
17 // flag (mark) if the secretary is discharged
18 boolean is_discharged = false;
19
20 /**
21 * Constructor: set the values of name, surname and nails length.
22 * If nails length is to large (> max length),
23 * the nails are cut to the max allowable length
24 * @param name
25 * @param surname
26 * @param nails_length
27 */
28 Secretary(String name,String surname,int nails_length)
29 {
30 this.name = name;
31 this.surname = surname;
32 if(nails_length > max_nails_length)
33 {
34 // cut this secretary's nails to the max allowable length
35 nails_length = max_nails_length;
36 System.out.println("Nails of secretary "+name+" "+surname+" are too long."
37 + " We'll cut them off!");
38 }
39 this.nails_length = nails_length;
40
41 }
42
43 /**
44 * @return secretary's name
45 */
46 String getName()
47 {
48 return name;
49 }
50
51 /**
52 * @return full name of the secretary
53 */
54 String getFullName()
55 {
56 return name+" "+surname;
57 }
58
59 /**
60 * @return length of the secretary's nails
61 */
62 int getNailsLength()
63 {
64 return nails_length;
65 }
66
67 /**
68 * @return true if the secretary is discharged, false elsewise
69 */
70 boolean isDischarged()
71 {
72 return is_discharged;
73 }
74
75 /**
76 * Discharge the secretary: set the value of the is_discharged flag to true
77 */
78 void dischargeFromOffice()
79 {
80 is_discharged=true;
81 }
82 /**
83 * Paint nails
84 */
85 void paintNails()
86 {
87 speak("I want to paint my nails. I'm busy now!");
88 }
89
90 /**
91 * Print documents and report if the secretary succeeded in printing.
92 * @return true if documents were printed, false - in all other cases
93 */
94 boolean printDocuments()
95 {
96 // with some probability the secretary paint her nails. In this case she can't do her job
97 double nails_probability = (double) nails_length / max_nails_length;
98 double prob = Math.random();
99 if (prob < nails_probability)
100 {
101 paintNails();
102 return false;
103 }
104 // if she does'n pain her job she can print the documents
105 speak("Boss, all documents are printed!");
106 return true;
107 }
108
109 /**
110 * Print the secretary's phrase in a dialog form
111 * @param phrase
112 */
113 void speak(String phrase)
114 {
115 System.out.println(getFullName()+":\t-"+phrase);
116 }
117 }