-
Notifications
You must be signed in to change notification settings - Fork 1
/
Journal.java
133 lines (107 loc) · 3.36 KB
/
Journal.java
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
//Journal.java
//grace nguyen
//april 4, 2022
import java.io.*;
import java.util.*;
public class Journal extends Book implements Serializable {
//attribtes
Queue<String> content;
String currentDayLog;
Integer day;
public static void main(String[] args) {
Journal grace = new Journal();
grace.logWater("grakamoli");
grace.logFertilizer("grakamoli");
grace.nextDay();
grace.logFungicide("grakamoli");
grace.nextDay();
grace.logCure("grakamoli", "mealybugs");
grace.nextDay();
grace.nextDay();
grace.listContent();
} //end main
//constructors
public Journal() {
super("Journal");
content = new LinkedList<String>();
currentDayLog = "";
day = 1;
} //end constructor
//getters and setters
public String getCurrentDayLog() {
return(this.currentDayLog);
} //end getLog
public Integer getDay() {
//get the day attribute
return(this.day);
} //end getDay
//listing method
public void listContent() {
//print all of the content attributes
//take into account that journalDate works properly ONLY if the current day is greater than 3
int journalDate = 0;
if(this.day > 3) {
journalDate = this.day - 3;
}else{
journalDate = 1;
} //end if
for(String dayLog : this.content) {
System.out.println("# Day " + journalDate);
journalDate++;
System.out.println(dayLog);
} //end for-each
//and print the current day!
System.out.println("# Day " + this.day + "\n" + this.currentDayLog);
} //end listContent
//adder methods
public void addLog(String action) {
//add action to todays' log (currentDayLog)
this.currentDayLog = this.currentDayLog + "- " + action + "\n";
} //end addLog
public void logFertilizer(String plantName) {
//add fertilizer log to today's string
String log = "Fertilized " + plantName;
this.addLog(log);
} //end logFertilizer
public void logWater(String plantName) {
//add water log to today's log
String log = "Watered " + plantName;
this.addLog(log);
} //end logWater
public void logInsecticide(String plantName) {
//add insecticide log to today's log
String log = "Treated " + plantName + " with insecticide";
this.addLog(log);
} //end logInsecticide
public void logFungicide(String plantName) {
//add fungicide log
String log = "Treated " + plantName + " with fungicide";
this.addLog(log);
} //end logFungicide
public void logRepot(String plantName) {
String log = "Repotted " + plantName;
this.addLog(log);
} //end logRepot
public void logCure(String plantName, String diseaseName) {
String log = plantName + " was cured of " + diseaseName;
this.addLog(log);
} //end logCure
public void logBuy(String bought, String cost) {
String log = bought + " was bought for $" + cost;
this.addLog(log);
} //end logBuy
//passing-of-time methods
public void nextDay() {
//add total day log to content attribute
this.content.add(this.currentDayLog);
this.currentDayLog = "";
//increase the day attribute by 1 to signify a new day
this.day++;
//get rid of the head if length is greater than 3
//only storing the past 3 days' worth of information
Integer length = this.content.size();
if(length > 3) {
this.content.poll();
} //end if
} //end nextDay
} //end class def