Repository navigation
Expand file tree
/
Copy pathGameHistory.java
More file actions
55 lines (50 loc) · 1.46 KB
/
Copy pathGameHistory.java
File metadata and controls
55 lines (50 loc) · 1.46 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
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
import java.io.FileWriter; // Import the FileWriter class
import java.io.IOException; // Import the IOException class to handle errors
/**
* Write a description of class GameHistory here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class GameHistory
{
// instance variables - replace the example below with your own
FileWriter fileWriter;
/**
* Constructor for objects of class GameHistory
*/
public GameHistory(String name)
{
try{
fileWriter = new FileWriter("robin.txt");
} catch (IOException exception) {
System.out.println("An error occurred when creating file");
exception.printStackTrace();
}
}
/**
* An example of a method - replace this comment with your own
*
* @param y a sample parameter for a method
* @return the sum of x and y
*/
public void writeHistory(String content)
{
content = content + "\n";
try{
System.out.println(content);
fileWriter.write(content);
}catch(IOException e){
System.out.println("An error occurred when writting content to file");
e.printStackTrace();
}
}
public void closeWriter(){
try{
fileWriter.close();
}catch(IOException e){
System.out.println("An error occurred when closing file");
e.printStackTrace();
}
}
}