-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileCow.java
More file actions
53 lines (46 loc) · 1.73 KB
/
FileCow.java
File metadata and controls
53 lines (46 loc) · 1.73 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
import java.io.FileInputStream;
import java.util.Scanner;
public class FileCow extends Cow
{
private static String filename;
// public FileCow(String name, String filename) throws RuntimeException("MOOOOO!!!!!!");
// {
// //Constructor; creates a new FileCow object with the given name and an image loaded from filename.
// //If the file cannot be loaded, it should throw a new RuntimeException with the message "MOOOOO!!!!!!".
// //This should be the only public constructor for the FileCowclass!
// super(name);
// super(getImage(setImage(filename)));
// }
public FileCow(String name, String filename)
{
//Constructor; creates a new FileCow object with the given name and an image loaded from filename.
//If the file cannot be loaded, it should throw a new RuntimeException with the message "MOOOOO!!!!!!".
//This should be the only public constructor for the FileCowclass!
super(name);
this.filename = filename;
try
{
FileInputStream inStream = new FileInputStream(filename);
Scanner fileScanner = new Scanner(inStream);
image = "";
while (fileScanner.hasNextLine())
{
image += fileScanner.nextLine() + "\n";
}
inStream.close();
}
catch (RuntimeException ee)
{
throw new RuntimeException("MOOOOO!!!!!!");
}
catch (Exception e)
{
System.out.println(e);
}
}
public void setImage()
{
//Should immediately throw a new RuntimeExceptionwith the message "Cannot reset FileCow Image".
throw new RuntimeException("Cannot reset FileCow Image");
}
}