-
Notifications
You must be signed in to change notification settings - Fork 2
/
SOLID_S.java
56 lines (49 loc) · 1.4 KB
/
SOLID_S.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
import java.util.*;
import java.io.*;
class Journal
{
private ArrayList<String> entries = new ArrayList<String>();
private int count = 0;
public void addEntry(String text)
{
++count;
entries.add(count + ".) " + text);
}
public void removeEntry(int index)
{
entries.remove(index);
}
@Override
public String toString()
{
return String.join(System.lineSeparator(), entries);
}
}
class Persistence
{
public void saveToFile(Journal journal, String filename, Boolean overwrite) throws FileNotFoundException
{
if(overwrite || new File(filename).exists())
{
try(PrintStream out = new PrintStream(filename))
{
out.println(journal.toString());
}
}
}
}
class Solid_S
{
public static void main(String[] args) throws FileNotFoundException
{
Journal xoxojournal = new Journal();
xoxojournal.addEntry("The Debut of New Idol Group.");
xoxojournal.addEntry("The best stuff you should try for your project.");
// System.out.println(xoxojournal);
Persistence persistence = new Persistence();
String filenamewithoutextension = "journal_SOLID_S";
String fileextension = "txt";
String filename = filenamewithoutextension + "." + fileextension;
persistence.saveToFile(xoxojournal, filename, true);
}
}