-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFortuneCookieDriver.java
More file actions
30 lines (25 loc) · 1.07 KB
/
FortuneCookieDriver.java
File metadata and controls
30 lines (25 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
class FortuneCookie {
private String message;
public FortuneCookie(String message) {
this.message = message;
}
public String getMessage() {
return message;
}
}
public class FortuneCookieDriver {
public static void main(String[] args) {
// Create an array of five FortuneCookies
FortuneCookie[] cookies = new FortuneCookie[5];
// Instantiate the FortuneCookies with different messages
cookies[0] = new FortuneCookie("If you have something good in your life, don't let it go");
cookies[1] = new FortuneCookie("People are naturally attracted to you");
cookies[2] = new FortuneCookie("Your hard work will pay off soon");
cookies[3] = new FortuneCookie("Your shoes will make you happy");
cookies[4] = new FortuneCookie("Good things come to those who wait");
// Iterate through the array, calling getMessage() on each FortuneCookie and printing out the String returned
for (FortuneCookie cookie : cookies) {
System.out.println(cookie.getMessage());
}
}
}