Homework 7 (Personality Test) FAQ
-
Q: Where do I start?
-
A: Try to break the problem into pieces. First try to read a record (a name and its answers) from the file. Then try to count the A and B answers. Look at the diagram of the arrays on the HW7 spec for inspiration. If you aren't very familiar with arrays, perhaps try looking at practice problems about them first until you feel comfortable.
-
Q: How do I read two lines at a time?
-
A: Well, the thing that you do to read one line at a time.... do that twice in a row.
-
Q: How do I examine the letters of the line to see which answer they are (A or B)?
-
A: Look at section 4.4 in the textbook about Text Processing, and look over section 7 problems about text processing. The
String
class'scharAt
method is useful. -
Q: Why are my percentages SLIGHTLY off?
-
A: Usually that's because you didn't round correctly or used the wrong type somewhere (
int
vsdouble
). -
Q: I have a lot of repetitive code. How do I make it less redundant?
-
A: You must work especially hard on this assignment to eliminate redundancy. Use techniques we've practiced in the past, such as factoring common code out of an
if/else
statement, or creating a helping method to hold common code. Look at the "Sections" program from lecture or at Chapter 7's case study to learn how to write good methods that use arrays as parameters/returns.