-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathZooFileWriter.java
More file actions
66 lines (49 loc) · 2.28 KB
/
ZooFileWriter.java
File metadata and controls
66 lines (49 loc) · 2.28 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
56
57
58
59
60
61
62
63
64
65
66
import java.io.FileWriter;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class ZooFileWriter {
public static String padLeft(String str, int leng, String stringpadVal) {
for (int i = str.length(); i <= leng; i++)
str = stringpadVal + str;
return str;
}
public static String padRight(String str, int leng, String stringpadVal) {
for (int i = str.length(); i <= leng; i++)
str = str + stringpadVal;
return str;
}
public static void createZooFile() {
try{
String entermore = "Y";
FileWriter fw=new FileWriter("zoodata.txt");
BufferedReader reader =
new BufferedReader(new InputStreamReader(System.in));
String animalName,trackNumber,animalType,animalSubType,eggs,Nurse;
do
{
System.out.println("Track Number: ");
trackNumber = reader.readLine();
trackNumber = padLeft(trackNumber, 6,"0");
System.out.println("Enter Animal Name: ");
animalName = reader.readLine();
animalName = padRight(animalName, 15," ");
System.out.println("Enter Animal Type: ");
animalType = reader.readLine();
animalType = padRight(animalType, 15," ");
System.out.println("Enter Animal Sub-type: ");
animalSubType = reader.readLine();
animalSubType = padRight(animalSubType, 15," ");
System.out.println("Enter Number of Eggs: ");
eggs = reader.readLine();
System.out.println("Enter 1 if Nursing, 0 if not: ");
Nurse = reader.readLine();
fw.write(trackNumber+" "+animalName+" "+animalType+" "+animalSubType+" "+eggs+" "+Nurse);
System.out.println("Enter more data? (Y for yes)");
entermore = reader.readLine();
}
while (entermore == "Y");
fw.close();
}catch(Exception e){System.out.println(e);}
System.out.println("The file has been successfully created...");
}
}