-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFetch.java
More file actions
29 lines (22 loc) · 749 Bytes
/
Fetch.java
File metadata and controls
29 lines (22 loc) · 749 Bytes
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
public class Fetch {
String[] fetchedItems = {"Ball", "Dead Bird", "Stick"};
int fetchedCounter = 0;
String name = "Pirate";
public void goFetch() {
String[] fetchedItems = {"Ball", "Dead Bird", "Stick"};
int fetchedCounter = 0;
this.fetchedCounter = (this.fetchedCounter + 1) % 3; // 1/3=0 R1 | 2/3=0 R2 | 3/3=0 R0
String item = this.fetchedItems[this.fetchedCounter];
System.out.println(this.name + " fetched a " + item + "."); //assume dogs name is "fido"
}
}
//assume mainclass calls the instance method of dog three times
// dog.goFetch();
// dog.goFetch();
// dog.goFetch();
/**
* output is:
* fido fetched a Dead Bird.
* fido fetched a Stick.
* fido fetched a Ball.
*/