Programming and Problem Solving with Java

(やまだぃちぅ) #1

CASE STUDY


312


// Set up input file
BufferedReader in; // Input stream for strings
// Instantiate in using System.in
in = newBufferedReader(newInputStreamReader(System.in));

// Set up output file
PrintWriter outFile;
outFile = newPrintWriter(newFileWriter("Entries"));

System.out.println("Quit entered for the first name ends the " +
"application.");
// Prompt for and read first name
System.out.print("Enter first name: ");
first = in.readLine();

while(first.compareTo("Quit") != 0 )
{
// Prompt for and read the rest of the name
System.out.print("Enter last name: ");
last = in.readLine();
System.out.print("Enter middle name: ");
middle = in.readLine();
name = newName(first, last, middle);

// Prompt for and read the address
System.out.print("Enter street address: ");
street = in.readLine();
System.out.print("Enter city: ");
city = in.readLine();
System.out.print("Enter state: ");
state = in.readLine();
System.out.print("Enter ZIP code: ");
zip = in.readLine();
address = newAddress(street, city, state, zip);

// Prompt for and read the phone number
System.out.print("Enter areaCode: ");
areaCode = Integer.parseInt(in.readLine());
System.out.print("Enter number: ");
number = Integer.parseInt(in.readLine());
phone = newPhone(areaCode, number);

// Instantiate and output entry
entry = newEntry(name, address, phone);
entry.writeToFile(outFile);
// Prompt for and read first name
Free download pdf