cranford07
03-03-2006, 02:05 PM
import apcslib.*;
import chn.util.*;
import java.util.* ;
import java.io.*;
public class Address
{
String peoplename,streetAddress, city, state;
private int zipCode;
FileOutput outFile = new FileOutput("database.txt");
ConsoleIO k = new ConsoleIO();
//-----------------------------------------------------------------
// Sets up this Address object with the specified data.
//-----------------------------------------------------------------
public Address()
{
System.out.print("Profile: ");
String filename = k.readLine();
System.out.print("Name: ");
String name = k.readLine();
System.out.print("Street: ");
String street = k.readLine();
System.out.print("City: ");
String town = k.readLine();
System.out.print("State: ");
String st = k.readLine();
System.out.print("Zip: ");
int zip = k.readInt();
peoplename = name;
streetAddress = street;
city = town;
state = st;
zipCode = zip;
FileOutput outFile = new FileOutput(filename+".txt");
outFile.println(peoplename);
outFile.println(streetAddress);
outFile.println(city);
outFile.println(state);
outFile.println(zipCode);
outFile.close();
}
//-----------------------------------------------------------------
// Returns this Address object as a string.
//-----------------------------------------------------------------
public static void main(String[] args)
{
ConsoleIO k = new ConsoleIO();
String ans2= "";
ArrayList address = new ArrayList();
do
{
System.out.print("1. New Account\n2. Existing Account\n3. View account\n4. Exit\n");
String ans = k.readToken();
if (ans.equals("1"))
{
Address P = new Address();
address.add(P);
}
else if (ans.equals("2"))
{
Address Q = new Address();
Q.update();
}
else if (ans.equals("3"))
{
System.out.print("\nProfile name: ");
String file = k.readLine();
FileInput inFile = new FileInput(file+".txt");
System.out.println("Name: " + inFile.readLine());
System.out.println("Address: " + inFile.readLine());
System.out.println("City: " + inFile.readLine());
System.out.println("State: " + inFile.readLine());
System.out.println("Zip: " + inFile.readLine());
}
System.out.print("Do you want to exit? ");
System.out.println();
ans2 = k.readToken();
}while (ans2.equalsIgnoreCase("n"));
}
}
did I create this in the right way or is there a more effective way. would I just let the user search for their txt profile and print it out so that they can update their information.
import chn.util.*;
import java.util.* ;
import java.io.*;
public class Address
{
String peoplename,streetAddress, city, state;
private int zipCode;
FileOutput outFile = new FileOutput("database.txt");
ConsoleIO k = new ConsoleIO();
//-----------------------------------------------------------------
// Sets up this Address object with the specified data.
//-----------------------------------------------------------------
public Address()
{
System.out.print("Profile: ");
String filename = k.readLine();
System.out.print("Name: ");
String name = k.readLine();
System.out.print("Street: ");
String street = k.readLine();
System.out.print("City: ");
String town = k.readLine();
System.out.print("State: ");
String st = k.readLine();
System.out.print("Zip: ");
int zip = k.readInt();
peoplename = name;
streetAddress = street;
city = town;
state = st;
zipCode = zip;
FileOutput outFile = new FileOutput(filename+".txt");
outFile.println(peoplename);
outFile.println(streetAddress);
outFile.println(city);
outFile.println(state);
outFile.println(zipCode);
outFile.close();
}
//-----------------------------------------------------------------
// Returns this Address object as a string.
//-----------------------------------------------------------------
public static void main(String[] args)
{
ConsoleIO k = new ConsoleIO();
String ans2= "";
ArrayList address = new ArrayList();
do
{
System.out.print("1. New Account\n2. Existing Account\n3. View account\n4. Exit\n");
String ans = k.readToken();
if (ans.equals("1"))
{
Address P = new Address();
address.add(P);
}
else if (ans.equals("2"))
{
Address Q = new Address();
Q.update();
}
else if (ans.equals("3"))
{
System.out.print("\nProfile name: ");
String file = k.readLine();
FileInput inFile = new FileInput(file+".txt");
System.out.println("Name: " + inFile.readLine());
System.out.println("Address: " + inFile.readLine());
System.out.println("City: " + inFile.readLine());
System.out.println("State: " + inFile.readLine());
System.out.println("Zip: " + inFile.readLine());
}
System.out.print("Do you want to exit? ");
System.out.println();
ans2 = k.readToken();
}while (ans2.equalsIgnoreCase("n"));
}
}
did I create this in the right way or is there a more effective way. would I just let the user search for their txt profile and print it out so that they can update their information.