java 2
assignment8/.DS_Store
__MACOSX/assignment8/._.DS_Store
assignment8/assignment8.docx
Minimal Submitted Files
You are required, but not limited, to turn in the following source files:
Requirements to get full credits in Documentation
1. The assignment number, your name, StudentID, Lecture number/time, and a class description need to be included at the top of each file/class.
2. A description of each method is also needed.
3. Some additional comments inside of methods(especially for the "main" method) to explain code that are hard to follow should be written.
You can look at the Java programs in the text book to see how comments are added to programs.
Skills to be Applied
In addition to what has been covered in previous assignments, the use of the following items, discussed in class, will probably be needed:
Vector/ArrayList Sorting Searching Aggregate Objects Interfaces Serialization File read/write
Program Description
Class Diagram:
ZipInfo
The ZipInfo class implements the "Serializable" interface so that its object can be stored. (The Serializable interface is defined in the "java.io" package.)
ZipcodeComparator
The ZipcodeComparator class implements the "Comparator" interface (The Comparator interface is in "java.util" package.). It needs to define the following method which was an inherited abstract method from Comparator interface:
public int compare(Object first, Object second)
(Note that you can also define: public int compare(ZipInfo first, ZipInfo second) instead by making the class implements Comparator<ZipInfo>.
If the first argument object has a smaller zipcode than that of the second argument, an int less than zero is returned. If the first argument object has a larger zipcode than that of the second argument, an int greater than zero is returned. If the both are same, 0 should be returned.
The Address class also implements the "Serializable" interface so that its object can be stored.
CityStateComparator
The CityStateComparator class implements the "Comparator" interface (The Comparator interface is in "java.util" package.). It needs to define the following method which was an inherited abstract method from Comparator interface:
public int compare(Object first, Object second)
(Note that you can also define: public int compare(ZipInfo first, ZipInfo second) instead by making the class implements Comparator<ZipInfo>.
If the first argument object has a state name lexicographically less than that of the second argument, an int less than zero is returned. If the first argument object has a state name lexicographically larger than that of the second argument, an int greater than zero is returned. If the both states are same, their city names should be compared. If they have same state and city, then 0 should be returned.
Sorts
The Sorts class is a utility class that will be used to sort a list of ZipInfo objects. Sorting algorithms are described in the algorithm note posted under Notes section of the course web site. These algorithms sort numbers stored in an array. It is your job to modify it to sort objects stored in an array list (or a vector). The Sorts class object will never be instantiated. It must have the following methods:
public static void sort(ArrayList objects, Comparator<ZipInfo>)
Your sort method utilizes the compare method of the parameter Comparator object to sort. You can use one of Selection sort or Insertion Sort.
PostOffice
The PostOffice class has a list of ZipInfo object that can be organized at the post office. The post office will be a fully encapsulated object. The PostOffice classimplements the Serializable interface. It has the following attributes:
|
Attribute name |
Attribute type |
Description |
|
zipcodeList |
ArrayList or Vector |
A list of ZipInfo objects in the post office |
The following public methods should be provided to interact with the post office:
|
Method |
Description |
|
PostOffice() |
A Constructor of the PostOffice class. The ArrayLists/Vectors of zipcodeList is instantiated. |
|
int zipcodeExists(int zipcode) |
Search for a ZipInfo object by zipcode and return the index of the object if found. Return -1 if not found. The parameter is the zipcode of a ZipInfo object. |
|
int cityStateExists(String city, String state) |
Search for a ZipInfo object by city and state and return the index of the object if found. Return -1 if not found. The parameters are city and state of a ZipInfo object. |
|
boolean addZipInfo(String city, String state, int zipcode) |
Add a ZipInfo object to the zipcode list. Return true if such object was added successfully. Return false if an object with the same zipcode already exists (the new object is not added). |
|
boolean removeZipcode(int zipcode) |
Remove a ZipInfo object from the zipcode list. Return true if the object was removed successfully. Return false if the object with the given zipcode does not exist. |
|
boolean removeCityState(String city, String state) |
Remove a ZipInfo object from the zipcode list. Return true if the object was removed successfully. Return false if the object with the given city and state does not exist. |
|
void sortByZipcode() |
Sort the list of ZipInfo objects by zipcode. This method calls the sort method defined in the Sorts class, using an object of ZipcodeComparator class as its second parameter. |
|
void sortByCityState() |
Sort the list of ZipInfo objects by cities and states. This method calls the sort method defined in the Sorts class, using an object of CityStateComparator class as its second parameter. |
|
String listZipcode() |
List all ZipInfo objects in the zipcode list. The returned string is the concatenation of each ZipInfo object information in the list. Hint: you can utilize ZipInfo's toString method to help you complete this method. If there is no object in the list, This method should return the string containing "\nno zipcode\n\n". |
|
void closePostOffice() |
Closes the post office by making the list empty. This can be done by using clear() method of the ArrayList. |
No input/output should occur in the post office. User interaction should be handled only by the driver class. ZipInfo object will be uniquely identified by zipcode, city, and state. This might not be a realistic assumption, but it will make the project easier to implement.
You may add other methods to the class in order to make your life easier.
Assignment8
All input and output should be handled in Assignment8 class. The main method should start by displaying this updated menu in this exact format:
Choice\t\tAction\n ------\t\t------\n A\t\tAdd Zipcode\n D\t\tSearch for Zipcode\n E\t\tSearch for City and State\n L\t\tList Zipcode\n O\t\tSort by Zipcode\n P\t\tSort by City and State\n Q\t\tQuit\n R\t\tRemove by Zipcode\n S\t\tRemove by City and State\n T\t\tClose PostOffice\n U\t\tWrite Text to File\n V\t\tRead Text from File\n W\t\tSerialize PostOffice to File\n X\t\tDeserialize PostOffice from File\n ?\t\tDisplay Help\n\n
Next, the following prompt should be displayed:
What action would you like to perform?\n
Read in the user input and execute the appropriate command. After the execution of each command, redisplay the prompt. Commands should be accepted in both lowercase and uppercase. The following commands are modified or new.
Add Zipcode
Your program should display the following prompt:
Please enter a city to add:\n
Read in city name and prompt:
Please enter its state to add:\n
Read in state name and prompt:
Please enter its zipcode to add:\n
Read in zipcode, and if the ZipInfo object with the zipcode is not in the zipcode list, then add it into the zipcode list and display:
zipcode added\n
Otherwise, display:
zipcode exists\n
Also, if zipcode entered is not an integer, display:
Please enter an integer for zipcode. Zipcode not added\n
Search by Zipcode
Your program should display the following prompt:
"Please enter zipcode to search:\n
Read in the zipcode and look up the zipcode list, if there exists a ZipInfo object with the same zipcode, then display the following:
zipcode found\n
Otherwise, display this:
zipcode not found\n
Also, if zipcode entered is not an integer, display:
Please enter an integer for zipcode. Zipcode not found\n
Search by City and State
Your program should display the following prompt:
Please enter a city to search:\n
Read in the city name, then display the following prompt:
Please enter a state to search:\n
Read in the state, and search the zipcode list based on these information. If there exists a ZipInfo object with the city and the state, then display the following:
city and state found\n
Otherwise, display this:
city and state not found\n
Sort By Zipcode
Your program should sort the zipcode list using zipcode in their increasing order and output the following:
sorted by zipcode\n
Sort By City and State
Your program should sort the zipcode list using state names and city names in alphabetical order by comparing states first, and if they are same, comparing cities and output the following:
sorted by states and cities\n
Remove By Zipcode
Your program should display the following prompt:
Please enter zipcode to remove:\n
Read in the integer. If the ZipInfo object can be found in the zipcode list, then remove it from the list, and display the following:
zipcode removed\n
If there is no such ZipInfo object in the zipcode list, display:
zipcode not found\n
Also, if zipcode entered is not an integer, display:
Please enter an integer for zipcode. Zipcode not removed\n
Remove By City and State
Your program should display the following prompt:
Please enter a city to remove:\n
Read in the city name and display the following prompt:
Please enter a state to remove:\n
Read in the state name. If the ZipInfo object can be found in the zipcode list, then remove it from the list, and display the following:
city and state removed\n
If there is no such ZipInfo object in the zipcode list, display:
city and state not found\n
List Zipcode
Each ZipInfo object information in the zipcode list should be displayed in the following format:
Apache Junction in Arizona with zipcode of 85117\n
If there is no ZipInfo object in the zipcode list, display:
\nno zipcode\n\n
A real example is looked like this (suppose there are only 2 ZipInfo objects in the zipcode list):
Birmingham in Alabama with zipcode of 35282 Apache Junction in Arizona with zipcode of 85117
Close PostOffice
Delete all ZipInfo objects. Then, display the following:
post office closed\n
Write Text to File
Your program should display the following prompt:
Please enter a file name to write:\n
Read in the filename and create an appropriate object to get ready to read from the file. Then it should display the following prompts:
Please enter a string to write in the file:\n
Read in the string that a user types, say "input", then attach "\n" at the end of the string, and write it to the file. (i.e. input+"\n" string will be written in the file.)
If the operation is successful, display the following:
FILENAME was written\n
Replace FILENAME with the actual name of the file.
Use try and catch statements to catch IOException. The file should be closed in a finally statement.
Read Text from File
Your program should display the following prompt:
Please enter a file name to read:\n
Read in the file name create appropriate objects to get ready to read from the file. If the operation is successful, display the following (replace FILENAME with the actual name of the file):
FILENAME was read\n
Then read only the first line in the file, and display:
The first line of the file is:\n
CONTENT\n
where CONTENT should be replaced by the actual first line in the file.
Your program should catch the exceptions if there are. (Use try and catch statement to catch, FileNotFoundException, and the rest of IOException.)
If the file name cannot be found, display
FILENAME was not found\n
where FILENAME is replaced by the actual file name.
Serialize PostOffice to File
Your program should display the following prompt:
Please enter a file name to write:\n
Read in the filename and write the serialized PostOffice object out to it. Note that any objects to be stored must implement Serializable interface. The Serializable interface is defined in java.io.* package. If the operation is successful, display the following:
FILENAME was written\n
Replace FILENAME with the actual name of the file.
Use try and catch statements to catch NotSerializableExeption and IOException.
Deserialize PostOffice from File
Your program should display the following prompt:
Please enter a file name to read:\n
Read in the file name and attempt to load the PostOffice object from that file. Note that there is only one PostOffice object in the Assignment8 class, and the first object read from the file should be assigned to the PostOffice object. If the operation is successful, display the following (replace FILENAME with the actual name of the file):
FILENAME was read\n
Your program should catch the exceptions if there are.
(Use try and catch statement to catch ClassNotFoundException, FileNotFoundException, and the rest of IOException.)
See the output files for exception handling
In the file I attached them.
__MACOSX/assignment8/._assignment8.docx
assignment8/Assignment8.java
assignment8/Assignment8.java
// Assignment #: 8
// Name:
// StudentID:
// Lecture:
//
// Description: The Assignment 8 class displays a menu of choices to a user
// and performs the chosen task. It will keep asking a user to
// enter the next choice until the choice of 'Q' (Quit) is
// entered.
import
java
.
io
.
*
;
public
class
Assignment8
{
public
static
void
main
(
String
[]
args
)
{
char
input1
;
String
city
,
state
,
zipStr
;
int
zipcode
;
boolean
operation
=
false
;
int
operation2
=
0
;
String
line
;
String
filename
;
// create a PostOffice object. This is used throughout this class.
PostOffice
office1
=
new
PostOffice
();
try
{
// print out the menu
printMenu
();
// create a BufferedReader object to read input from a keyboard
InputStreamReader
isr
=
new
InputStreamReader
(
System
.
in
);
BufferedReader
stdin
=
new
BufferedReader
(
isr
);
do
{
System
.
out
.
print
(
"What action would you like to perform?\n"
);
line
=
stdin
.
readLine
().
trim
();
//read a line
input1
=
line
.
charAt
(
0
);
input1
=
Character
.
toUpperCase
(
input1
);
if
(
line
.
length
()
==
1
)
//check if a user entered only one character
{
switch
(
input1
)
{
case
'A'
:
//Add Zipcode
try
{
System
.
out
.
print
(
"Please enter a city to add:\n"
);
city
=
stdin
.
readLine
().
trim
();
System
.
out
.
print
(
"Please enter its state to add:\n"
);
state
=
stdin
.
readLine
().
trim
();
System
.
out
.
print
(
"Please enter its zipcode to add:\n"
);
zipStr
=
stdin
.
readLine
().
trim
();
zipcode
=
Integer
.
parseInt
(
zipStr
);
operation
=
office1
.
addZipInfo
(
city
,
state
,
zipcode
);
if
(
operation
==
true
)
System
.
out
.
print
(
"zipcode added\n"
);
else
System
.
out
.
print
(
"zipcode exists\n"
);
}
/************************************************************************************
*** Complete the follwing catch statement
***********************************************************************************/
catch
(
)
{
}
break
;
case
'D'
:
//Search by Zipcode
try
{
System
.
out
.
print
(
"Please enter zipcode to search:\n"
);
zipStr
=
stdin
.
readLine
().
trim
();
zipcode
=
Integer
.
parseInt
(
zipStr
);
operation2
=
office1
.
zipcodeExists
(
zipcode
);
if
(
operation2
>
-
1
)
System
.
out
.
print
(
"zipcode found\n"
);
else
System
.
out
.
print
(
"zipcode not found\n"
);
}
/************************************************************************************
*** Complete the follwing catch statement
***********************************************************************************/
catch
(
)
{
}
break
;
case
'E'
:
//Search by City and State
System
.
out
.
print
(
"Please enter a city to search:\n"
);
city
=
stdin
.
readLine
().
trim
();
System
.
out
.
print
(
"Please enter a state to search:\n"
);
state
=
stdin
.
readLine
().
trim
();
operation2
=
office1
.
cityStateExists
(
city
,
state
);
if
(
operation2
>
-
1
)
System
.
out
.
print
(
"city and state found\n"
);
else
System
.
out
.
print
(
"city and state not found\n"
);
break
;
case
'L'
:
//List Zipcodes
System
.
out
.
print
(
office1
.
listZipcode
());
break
;
case
'O'
:
// Sort by Zipcode
office1
.
sortByZipcode
();
System
.
out
.
print
(
"sorted by zipcode\n"
);
break
;
case
'P'
:
// Sort by States and Cities
office1
.
sortByCityState
();
System
.
out
.
print
(
"sorted by states and cities\n"
);
break
;
case
'Q'
:
//Quit
break
;
case
'R'
:
//Remove by Zipcode
try
{
System
.
out
.
print
(
"Please enter zipcode to remove:\n"
);
zipStr
=
stdin
.
readLine
().
trim
();
zipcode
=
Integer
.
parseInt
(
zipStr
);
operation
=
office1
.
removeZipcode
(
zipcode
);
if
(
operation
==
true
)
System
.
out
.
print
(
"zipcode removed\n"
);
else
System
.
out
.
print
(
"zipcode not found\n"
);
}
/************************************************************************************
*** Complete the follwing catch statement
***********************************************************************************/
catch
(
)
{
}
break
;
case
'S'
:
//Remove by State and City
System
.
out
.
print
(
"Please enter a city to remove:\n"
);
city
=
stdin
.
readLine
().
trim
();
System
.
out
.
print
(
"Please enter a state to remove:\n"
);
state
=
stdin
.
readLine
().
trim
();
operation
=
office1
.
removeCityState
(
city
,
state
);
if
(
operation
==
true
)
System
.
out
.
print
(
"city and state removed\n"
);
else
System
.
out
.
print
(
"city and state not found\n"
);
break
;
case
'T'
:
//Close PostOffice
office1
.
closePostOffice
();
System
.
out
.
print
(
"post office closed\n"
);
break
;
case
'U'
:
//Write Text to a File
System
.
out
.
print
(
"Please enter a file name to write:\n"
);
filename
=
stdin
.
readLine
().
trim
();
/************************************************************************************
*** ADD your code to write a text (string) to the specified file. Catch exceptions.
************************************************************************************/
break
;
case
'V'
:
//Read Text from a File
System
.
out
.
print
(
"Please enter a file name to read:\n"
);
filename
=
stdin
.
readLine
().
trim
();
/************************************************************************************
*** ADD your code to read a text (string) from the specified file. Catch exceptions.
************************************************************************************/
break
;
case
'W'
:
//Serialize PostOffice to a File
System
.
out
.
print
(
"Please enter a file name to write:\n"
);
filename
=
stdin
.
readLine
().
trim
();
/************************************************************************************
*** ADD your code to write the post office bject to the specified file. Catch exceptions.
************************************************************************************/
break
;
case
'X'
:
//Deserialize PostOffice from a File
System
.
out
.
print
(
"Please enter a file name to read:\n"
);
filename
=
stdin
.
readLine
().
trim
();
/************************************************************************************
*** ADD your code to read a post office object from the specified file. Catch exceptions.
***********************************************************************************/
break
;
case
'?'
:
//Display Menu
printMenu
();
break
;
default
:
System
.
out
.
print
(
"Unknown action\n"
);
break
;
}
}
else
{
System
.
out
.
print
(
"Unknown action\n"
);
}
}
while
(
input1
!=
'Q'
||
line
.
length
()
!=
1
);
}
catch
(
IOException
exception
)
{
System
.
out
.
print
(
"IO Exception\n"
);
}
}
/** The method printMenu displays the menu to a user **/
public
static
void
printMenu
()
{
System
.
out
.
print
(
"Choice\t\tAction\n"
+
"------\t\t------\n"
+
"A\t\tAdd Zipcode\n"
+
"D\t\tSearch for Zipcode\n"
+
"E\t\tSearch for City and State\n"
+
"L\t\tList Zipcode\n"
+
"O\t\tSort by Zipcode\n"
+
"P\t\tSort by City and State\n"
+
"Q\t\tQuit\n"
+
"R\t\tRemove by Zipcode\n"
+
"S\t\tRemove by City and State\n"
+
"T\t\tClose PostOffice\n"
+
"U\t\tWrite Text to File\n"
+
"V\t\tRead Text from File\n"
+
"W\t\tSerialize PostOffice to File\n"
+
"X\t\tDeserialize PostOffice from File\n"
+
"?\t\tDisplay Help\n\n"
);
}
}
// end of Assignment8 class
__MACOSX/assignment8/._Assignment8.java
assignment8/input1.txt
A Birmingham Alabama 35282 A Apache Junction Arizona 85117 A Anchorage Alaska 99502 D 85117 D 43522 D B3H2E8 L R 99501 L R 99502 R 85111 L W postal.dat T L X office.dat X postal.dat L Q
__MACOSX/assignment8/._input1.txt
assignment8/input2.txt
A Huntsville Alabama 35801 A Casa Grande Arizona 85122 A Tuscaloosa Alabama 35401 A Tempe Arizona 85280 A Phoenix Arizona 85001 L P L O L S Tuscaloosa Alabama R 85001 L Q
__MACOSX/assignment8/._input2.txt
assignment8/input3.txt
A San Francisco California 94102 A Seattle Washington 98104 A Denver Colorado 80202 A Houston Texas 77002 L E Rice Texas E San Francisco California E Jersey City New Jersey L O L P L A Rice Texas 75155 L E Rice Texas D 75155 E Denver Arizona L U example1.txt Writing a first line V example2.txt V example1.txt L Q
__MACOSX/assignment8/._input3.txt
assignment8/input4.txt
A Redmond Washington 98053 A Long Beach California 90802 A Bellevue Washington 98007 D H3E0A1 L P L O L A Salt Lake City Utah 84106 L S Seattle Washington L S Tempe Arizona S Redmond Oregon L R 98008 R B3H2E5 R 98007 L O L P L Q
__MACOSX/assignment8/._input4.txt
assignment8/output1.txt
Choice Action ------ ------ A Add Zipcode D Search for Zipcode E Search for City and State L List Zipcode O Sort by Zipcode P Sort by City and State Q Quit R Remove by Zipcode S Remove by City and State T Close PostOffice U Write Text to File V Read Text from File W Serialize PostOffice to File X Deserialize PostOffice from File ? Display Help What action would you like to perform? Please enter a city to add: Please enter its state to add: Please enter its zipcode to add: zipcode added What action would you like to perform? Please enter a city to add: Please enter its state to add: Please enter its zipcode to add: zipcode added What action would you like to perform? Please enter a city to add: Please enter its state to add: Please enter its zipcode to add: zipcode added What action would you like to perform? Please enter zipcode to search: zipcode found What action would you like to perform? Please enter zipcode to search: zipcode not found What action would you like to perform? Please enter zipcode to search: Please enter an integer for zipcode. Zipcode not found What action would you like to perform? Birmingham in Alabama with zipcode of 35282 Apache Junction in Arizona with zipcode of 85117 Anchorage in Alaska with zipcode of 99502 What action would you like to perform? Please enter zipcode to remove: zipcode not found What action would you like to perform? Birmingham in Alabama with zipcode of 35282 Apache Junction in Arizona with zipcode of 85117 Anchorage in Alaska with zipcode of 99502 What action would you like to perform? Please enter zipcode to remove: zipcode removed What action would you like to perform? Please enter zipcode to remove: zipcode not found What action would you like to perform? Birmingham in Alabama with zipcode of 35282 Apache Junction in Arizona with zipcode of 85117 What action would you like to perform? Please enter a file name to write: postal.dat was written What action would you like to perform? post office closed What action would you like to perform? no zipcode What action would you like to perform? Please enter a file name to read: office.dat was not found What action would you like to perform? Please enter a file name to read: postal.dat was read What action would you like to perform? Birmingham in Alabama with zipcode of 35282 Apache Junction in Arizona with zipcode of 85117 What action would you like to perform?
__MACOSX/assignment8/._output1.txt
assignment8/output2.txt
Choice Action ------ ------ A Add Zipcode D Search for Zipcode E Search for City and State L List Zipcode O Sort by Zipcode P Sort by City and State Q Quit R Remove by Zipcode S Remove by City and State T Close PostOffice U Write Text to File V Read Text from File W Serialize PostOffice to File X Deserialize PostOffice from File ? Display Help What action would you like to perform? Please enter a city to add: Please enter its state to add: Please enter its zipcode to add: zipcode added What action would you like to perform? Please enter a city to add: Please enter its state to add: Please enter its zipcode to add: zipcode added What action would you like to perform? Please enter a city to add: Please enter its state to add: Please enter its zipcode to add: zipcode added What action would you like to perform? Please enter a city to add: Please enter its state to add: Please enter its zipcode to add: zipcode added What action would you like to perform? Please enter a city to add: Please enter its state to add: Please enter its zipcode to add: zipcode added What action would you like to perform? Huntsville in Alabama with zipcode of 35801 Casa Grande in Arizona with zipcode of 85122 Tuscaloosa in Alabama with zipcode of 35401 Tempe in Arizona with zipcode of 85280 Phoenix in Arizona with zipcode of 85001 What action would you like to perform? sorted by states and cities What action would you like to perform? Huntsville in Alabama with zipcode of 35801 Tuscaloosa in Alabama with zipcode of 35401 Casa Grande in Arizona with zipcode of 85122 Phoenix in Arizona with zipcode of 85001 Tempe in Arizona with zipcode of 85280 What action would you like to perform? sorted by zipcode What action would you like to perform? Tuscaloosa in Alabama with zipcode of 35401 Huntsville in Alabama with zipcode of 35801 Phoenix in Arizona with zipcode of 85001 Casa Grande in Arizona with zipcode of 85122 Tempe in Arizona with zipcode of 85280 What action would you like to perform? Please enter a city to remove: Please enter a state to remove: city and state removed What action would you like to perform? Please enter zipcode to remove: zipcode removed What action would you like to perform? Huntsville in Alabama with zipcode of 35801 Casa Grande in Arizona with zipcode of 85122 Tempe in Arizona with zipcode of 85280 What action would you like to perform?
__MACOSX/assignment8/._output2.txt
assignment8/output3.txt
Choice Action ------ ------ A Add Zipcode D Search for Zipcode E Search for City and State L List Zipcode O Sort by Zipcode P Sort by City and State Q Quit R Remove by Zipcode S Remove by City and State T Close PostOffice U Write Text to File V Read Text from File W Serialize PostOffice to File X Deserialize PostOffice from File ? Display Help What action would you like to perform? Please enter a city to add: Please enter its state to add: Please enter its zipcode to add: zipcode added What action would you like to perform? Please enter a city to add: Please enter its state to add: Please enter its zipcode to add: zipcode added What action would you like to perform? Please enter a city to add: Please enter its state to add: Please enter its zipcode to add: zipcode added What action would you like to perform? Please enter a city to add: Please enter its state to add: Please enter its zipcode to add: zipcode added What action would you like to perform? San Francisco in California with zipcode of 94102 Seattle in Washington with zipcode of 98104 Denver in Colorado with zipcode of 80202 Houston in Texas with zipcode of 77002 What action would you like to perform? Please enter a city to search: Please enter a state to search: city and state not found What action would you like to perform? Please enter a city to search: Please enter a state to search: city and state found What action would you like to perform? Please enter a city to search: Please enter a state to search: city and state not found What action would you like to perform? San Francisco in California with zipcode of 94102 Seattle in Washington with zipcode of 98104 Denver in Colorado with zipcode of 80202 Houston in Texas with zipcode of 77002 What action would you like to perform? sorted by zipcode What action would you like to perform? Houston in Texas with zipcode of 77002 Denver in Colorado with zipcode of 80202 San Francisco in California with zipcode of 94102 Seattle in Washington with zipcode of 98104 What action would you like to perform? sorted by states and cities What action would you like to perform? San Francisco in California with zipcode of 94102 Denver in Colorado with zipcode of 80202 Houston in Texas with zipcode of 77002 Seattle in Washington with zipcode of 98104 What action would you like to perform? Please enter a city to add: Please enter its state to add: Please enter its zipcode to add: zipcode added What action would you like to perform? San Francisco in California with zipcode of 94102 Denver in Colorado with zipcode of 80202 Houston in Texas with zipcode of 77002 Seattle in Washington with zipcode of 98104 Rice in Texas with zipcode of 75155 What action would you like to perform? Please enter a city to search: Please enter a state to search: city and state found What action would you like to perform? Please enter zipcode to search: zipcode found What action would you like to perform? Please enter a city to search: Please enter a state to search: city and state not found What action would you like to perform? San Francisco in California with zipcode of 94102 Denver in Colorado with zipcode of 80202 Houston in Texas with zipcode of 77002 Seattle in Washington with zipcode of 98104 Rice in Texas with zipcode of 75155 What action would you like to perform? Please enter a file name to write: Please enter a string to write in the file: example1.txt was written What action would you like to perform? Please enter a file name to read: example2.txt was not found What action would you like to perform? Please enter a file name to read: example1.txt was read The first line of the file is: Writing a first line What action would you like to perform? San Francisco in California with zipcode of 94102 Denver in Colorado with zipcode of 80202 Houston in Texas with zipcode of 77002 Seattle in Washington with zipcode of 98104 Rice in Texas with zipcode of 75155 What action would you like to perform?
__MACOSX/assignment8/._output3.txt
assignment8/output4.txt
Choice Action ------ ------ A Add Zipcode D Search for Zipcode E Search for City and State L List Zipcode O Sort by Zipcode P Sort by City and State Q Quit R Remove by Zipcode S Remove by City and State T Close PostOffice U Write Text to File V Read Text from File W Serialize PostOffice to File X Deserialize PostOffice from File ? Display Help What action would you like to perform? Please enter a city to add: Please enter its state to add: Please enter its zipcode to add: zipcode added What action would you like to perform? Please enter a city to add: Please enter its state to add: Please enter its zipcode to add: zipcode added What action would you like to perform? Please enter a city to add: Please enter its state to add: Please enter its zipcode to add: zipcode added What action would you like to perform? Please enter zipcode to search: Please enter an integer for zipcode. Zipcode not found What action would you like to perform? Redmond in Washington with zipcode of 98053 Long Beach in California with zipcode of 90802 Bellevue in Washington with zipcode of 98007 What action would you like to perform? sorted by states and cities What action would you like to perform? Long Beach in California with zipcode of 90802 Bellevue in Washington with zipcode of 98007 Redmond in Washington with zipcode of 98053 What action would you like to perform? sorted by zipcode What action would you like to perform? Long Beach in California with zipcode of 90802 Bellevue in Washington with zipcode of 98007 Redmond in Washington with zipcode of 98053 What action would you like to perform? Please enter a city to add: Please enter its state to add: Please enter its zipcode to add: zipcode added What action would you like to perform? Long Beach in California with zipcode of 90802 Bellevue in Washington with zipcode of 98007 Redmond in Washington with zipcode of 98053 Salt Lake City in Utah with zipcode of 84106 What action would you like to perform? Please enter a city to remove: Please enter a state to remove: city and state not found What action would you like to perform? Long Beach in California with zipcode of 90802 Bellevue in Washington with zipcode of 98007 Redmond in Washington with zipcode of 98053 Salt Lake City in Utah with zipcode of 84106 What action would you like to perform? Please enter a city to remove: Please enter a state to remove: city and state not found What action would you like to perform? Please enter a city to remove: Please enter a state to remove: city and state not found What action would you like to perform? Long Beach in California with zipcode of 90802 Bellevue in Washington with zipcode of 98007 Redmond in Washington with zipcode of 98053 Salt Lake City in Utah with zipcode of 84106 What action would you like to perform? Please enter zipcode to remove: zipcode not found What action would you like to perform? Please enter zipcode to remove: Please enter an integer for zipcode. Zipcode not removed What action would you like to perform? Please enter zipcode to remove: zipcode removed What action would you like to perform? Long Beach in California with zipcode of 90802 Redmond in Washington with zipcode of 98053 Salt Lake City in Utah with zipcode of 84106 What action would you like to perform? sorted by zipcode What action would you like to perform? Salt Lake City in Utah with zipcode of 84106 Long Beach in California with zipcode of 90802 Redmond in Washington with zipcode of 98053 What action would you like to perform? sorted by states and cities What action would you like to perform? Long Beach in California with zipcode of 90802 Salt Lake City in Utah with zipcode of 84106 Redmond in Washington with zipcode of 98053 What action would you like to perform?
__MACOSX/assignment8/._output4.txt
assignment8/ZipInfo.java
assignment8/ZipInfo.java
// Assignment #: 8
// Name:
// StudentID:
// Lecture:
//
// Description:
// ZipInfo represents a combination of city, state, and zip code
public
class
ZipInfo
{
private
String
city
,
state
;
private
int
zipcode
;
//Constructor to initialize parameter values
public
ZipInfo
(
String
city1
,
String
state1
,
int
zip1
)
{
zipcode
=
zip1
;
city
=
city1
;
state
=
state1
;
}
//Accessor method for city
public
String
getCity
()
{
return
city
;
}
//Accessor method for state
public
String
getState
()
{
return
state
;
}
//Accesor method for zipcode
public
int
getZipcode
()
{
return
zipcode
;
}
//The toString method return a string containing
//the city, state, and zip code
public
String
toString
()
{
return
(
city
+
" in "
+
state
+
" with zipcode of "
+
zipcode
+
"\n"
);
}
}
//end of ZipInfo class