-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCharacter.java
234 lines (218 loc) · 8.03 KB
/
Character.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
/**
* Character.java
* Assignment: Final Project
* Purpose: To let us have some experience with actual coding, rather than
* just systematically fulfilling assignments through which we are
* walked step by step.
* @version 05/18/15
* @author Sierramatice Karras
*/
import java.awt.*;
import java.io.*;
import java.util.*;
public class Character extends Story {
private String gender;
private int age;
private String name;
private String eyes;
private String hair;
private String skin;
private String personality;
private String job;
private String height;
private String genre;
private String type;
private String species;
private String superpower;
/* @param a String containing the gender of the character (e.g. male, female, either)
* @return nothing
* constructs a Character with the given gender
*/
public Character(String gender, String genre, String type) throws FileNotFoundException{
this.gender = gender;
this.genre = genre;
this.type = type;
name();
age(genre);
eyes();
hair();
height();
skinTone();
personality = super.personality();
occupation(genre);
species(genre, type);
if (genre.equals("superhero")) {
superpowers();
}
}
public String superpowers() throws FileNotFoundException{
Scanner superInfo = new Scanner(new File("superpowers.txt" ));
ArrayList<String> powers = textToArray(superInfo);
this.superpower = randomize(powers);
return this.superpower;
}
/* @param nothing
* @return a String with a randomly selected skin tone from the text file
* uses the textToArray and randomize methods to pick a random skin tone from the file
*/
public String skinTone() throws FileNotFoundException {
Scanner skinInfo = new Scanner(new File("SkinTone.txt" ));
ArrayList<String> skin = textToArray(skinInfo);
this.skin = randomize(skin);
return this.skin;
}
/* @param a String containing the genre
* @return a randomly selected age
* computes and returns a random number (based on the genre) for age
*/
public int age(String genre) {
if(genre.equals("sci-fi")) {
this.age = (int)(Math.random() * 200 + 5);
}
else if (genre.equals("historical")){
this.age = (int) (Math.random() * 31 + 5);
}
else {
this.age = (int)(Math.random() * 90 + 5);
}
return age;
}
/* @param nothing
* @return a randomly selected String for name (based on the gender)
* picks the text file based on given gender, then picks and returns a random name from it,
* uses the textToArray and randomize methods
*/
public String name () throws FileNotFoundException {
String file = "eitherGenderNames.txt";
if (gender.equalsIgnoreCase("male")) {
file = "maleNames.txt";
}
else if (gender.equalsIgnoreCase("female")) {
file = "femaleNames.txt";
}
String firstName = randomize(textToArray(new Scanner(new File(file))));
//file has names all lower case
firstName = firstName.substring(0, 1).toUpperCase() + firstName.substring(1);
String lastName = randomize(textToArray(new Scanner(new File("surnames.txt"))));
//file has names all upper case
lastName = lastName.substring(0, 1) + lastName.substring(1).toLowerCase();
this.name = firstName + " " + lastName;
return this.name;
}
/* @param nothing
* @return a String with the eye color of the character
* uses the textToArray and randomize methods to pick a random eye color from the file
*/
public String eyes() throws FileNotFoundException{
Scanner eyesInfo = new Scanner(new File("EyeColors.txt" ));
ArrayList<String> eyes = textToArray(eyesInfo);
this.eyes = randomize(eyes);
return this.eyes;
}
/* @param nothing
* @return a randomly selected String with the hair color of the character
* uses the textToArray and randomize methods to pick a random hair color from the file
*/
public String hair() throws FileNotFoundException {
Scanner hairInfo = new Scanner(new File("HairColor.txt" ));
ArrayList<String> hairs = textToArray(hairInfo);
this.hair = randomize(hairs);
return this.hair;
}
/* @param nothing
* @return a String with two randomly selected personality traits
* uses textToArray and randomize methods to pick two random personality traits from the file
*/
//public String personality() throws FileNotFoundException{
// Scanner personality = new Scanner(new File("PersonalityTraits.txt" ));
// ArrayList<String> traits = textToArray(personality);
// this.personality = randomize(traits) + ", " + randomize(traits);
// return this.personality;
//}
/* @param a String containing the genre
* @return a String with a randomly selected occupation based off genre
* uses textToArray and randomize methods to pick a random job from the file, with the file
* decided based on the genre
*/
public String occupation(String genre)throws FileNotFoundException {
String txt;
if(genre.equals("sci-fi")) {
txt = "scifiJobs.txt";
}
else if (genre.equals("fantasy")) {
txt = "FantasyJobs.txt";
}
else {
txt = "occupations.txt";
}
Scanner input = new Scanner(new File(txt));
if(age > 15) {
ArrayList<String> jobs = textToArray(input);
this.job = randomize(jobs);
}
else {
this.job = "child - no job"; //what about historical, where children did work?
}
return this.job;
}
/* @param nothing
* @return a randomly selected height in feet and inches (based on age)
* computes height taking into account age ad returns it
*/
public String height() {
int feet = (int)(Math.random() * 3);
if(age > 10) { // maybe not as exact as it could be, if you have extra time
feet += 4;
}
else {
feet += 2;
}
int inch = (int)(Math.random() * 11);
this.height = feet + "'" + inch + "\"";
return this.height;
}
/* @param a String with the genre, a String with the type (human/creature)
* @return the species of the character based on genre
* uses the textToArray and randomize methods if genre is fantasy and the type creature,
* otherwise returns a basic species based on type and genre
*/
public String species(String genre, String type) throws FileNotFoundException{
if(!type.equals("human")){
if (genre.equals("sci-fi")){
Scanner aliens = new Scanner(new File("scifiSpecies.txt" ));
ArrayList<String> ufo = textToArray(aliens);
this.species = randomize(ufo);
}
else
if(genre.equals("fantasy")){
Scanner mythology = new Scanner(new File("creatures.txt" ));
ArrayList<String> mythos = textToArray(mythology);
this.species = randomize(mythos);
}
else {
Scanner all = new Scanner(new File("scifiSpecies.txt" ));
ArrayList<String> allCreature = textToArray(all);
addToArray(new Scanner(new File("creatures.txt" )), allCreature);
this.species = randomize(allCreature);
}
}
else {
this.species = "human";
}
return this.species;
}
/* @param nothing
* @return a String with all the fields in it
* turns all the fields and their names into a long String, which it returns
*/
public String toString() {
String text = "Name: " + this.name + "\n Age: " + this.age + "\n Appearance: " +
"\n Eye Color: " + this.eyes + "\n Hair Color: " + this.hair + "\n Height: "
+ this.height + "\n Personality: " + this.personality + "\n Occupation: " +
this.job + "\n Species: " + this.species;
if(genre.equals("superhero")) {
text += "\n Superpower: " + this.superpower;
}
return text;
}
}