Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Assignment #8
- Due Date
- Friday, November 1st, at 7pm.
- Important: This is an individual assignment. Please do not collaborate.
- Minimal Submitted Files
- You are required, but not limited, to turn in the following source files:
- Assignment8.java(More code need to be added)
- Customer.java(given by the instructor, it needs to be modified for this assignment)
- CustomerParser.java(given by the instructor)
- Bank.java(from assignment 4, it needs to be modified for this assignment)
- BankParser.java(given by the instructor)
- Address.java(from assignment 4, it needs to be modified for this assignment)
- Sorts.java
- BankSystem.java
- Requirements to get full credits in Documentation
- The assignment number, your name, StudentID, Lecture number/time, and a class description need to be included at the top of each file/class.
- A description of each method is also needed.
- 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 (download .ppt file of the figure):
- Customer
- The Customer class implements the "Comparable" interface. (The Comparable interface is defined in the "java.lang" package.) In addition to the attributes and methods constructed already in the given file, the following method must be defined:
- public int compareTo(Object other)
- If the current object has the last name lexicographically less than that of the argument, an int less than zero is returned. If the current object has the last name greater than that of the argument, an int greater than zero is returned. If the both objects have the same last Name, their first names should be compared.
- The Customer class also implements the "Serializable" interface so that its object can be stored. (The Serializable interface is defined in the "java.io" pakcage.)
- Address
- The Address class implements the "Comparable" interface. In addition to the attributes and methods constructed from the previous assignment, the following method must be defined:
- public int compareTo(Object other)
- If the current object has the state lexicographically less than that of the argument, an int less than zero is returned. If the current object has the state greater than that of the argument, an int greater than zero is returned. If the both states are same, their cities should be compared lexicographically. If the current city is larger, it should return a positive integer. If the current city is smaller, it should return a negative integer. If the cities are same (and the states are same), then it should return 0.
- The Address class also implements the "Serializable" interface so that its object can be stored.
- Bank
- The Bank class implements the "Comparable" interface. In addition to the attributes and methods constructed from the previous assignment, the following method must be defined:
- public int compareTo(Object other)
- If the current object has the bank name lexicographically less than that of the argument, an int less than zero is returned. If the current object has the bank name greater than that of the argument, an int greater than zero is returned. If the both objects have the same bank name, their bank id should be compared. should be compared using the compareTo method of the Address class. If the both objects have the same bank name and id, then their address should be compared using the compareTo method of the Address class.
- The Bank class also implements the "Serializable" interface so that its object can be stored.
- Sorts
- The Sorts class is a utility class that will be used to sort the customer list and the bank list. 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)
- Your sort method utilizes the compareTo method of objects to be sorted. You can use one of Insertion Sort, Merge Sort, or Quick Sort.
- BankSystem
- The BankSystem class has a list of customers and a list of banks that can be organized at the bank system. The bank system will be a fully encapsulated object. The BankSystem class implements the Serializable interface.
- It has the following attributes:
- Attribute name Attribute type Description
- customerList ArrayList or Vector A list of customers in the bank system
- bankList ArrayList or Vector A list of banks in the bank system
- The following public methods should be provided to interact with the bank system:
- Method Description
- BankSystem() A Constructor of the BankSystem class. The ArrayLists/Vectors of customerList and bankList are instantiated.
- int customerExists(String) Search for a customer by customer ID and return the index of the object if found. Return -1 if not found. The parameter is the customer ID of a customer.
- boolean addCustomer(String) Add a customer to the customer list. Return true if the customer was added successfully. Return false if the customer with the same customer ID already exists (the customer is not added). The parameter is the string to be parsed by the CustomerParser.
- boolean removeCustomer(String) Remove a customer from the customer list. Return true if the customer was removed successfully. Return false if the customer with the given customer ID does not exist. The parameter is the customer ID of a customer.
- void sortCustomers() Sort the list of customers by last name from A to Z. If more than one customer have the same last name, compare their first names. This method calls the sort method defined in the Sorts class.
- String listCustomers() List all customers in the customer list. The returned string is the concatenation of each customer object information in the list. Hint: you can utilize customer's toString method to help you complete this method. If there is no customer in the list, This method should return the string containing "no customer\n".
- int bankExists(String bankName, int bankID, String city, String state) Search for a bank in the bank list. Return the index of the bank object if the bank object of the same bank name, id, city, and state is found. Return -1 if not found. The parameters are the bank name (String), the id (int), the city (String), and the state (String) of the bank to be searched.
- boolean addBank(String) Add a bank to the bank list. Return true if the bank was added successfully. Return false if the bank already exists based on the criteria in the bankExists method (the bank is not added in this case). The parameter is the string to be parsed by the BankParser.
- boolean removeBank(tring bankName, int bankID, String city, String state) Remove a bank from the bank list. Return true if the bank of the given bank name, id, city and state was removed successfully. Return false if the bank does not exist. The parameters are the bank name (String), the id (int), the city (String), and the state (String) of the bank to be removed.
- void sortBanks() Sort the list of banks. If more than one bank have the same bank name, compare their id. If they have the same id, compare address. This method calls the sort method defined in the Sorts class.
- String listBanks() List all banks in the bank list. The returned string is the concatenation of each bank object information in the list. Hint: you can utilize bank's toString method to help you complete this method. If there is no bank in the list, it should return the string containing "no bank\n"
- void closeBankSystem() Closes the bank system by making all lists empty. This can be done by using clear() method of the ArrayList.
- No input/output should occur in the bank system. User interaction should be handled only by the driver class. Customers will be uniquely identified by their customer ID, banks will be uniquely identified by the combination of their bank name, id, city, and state. This might not 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 Customer\n
- B\t\tAdd Bank\n
- D\t\tSearch for Customer\n
- E\t\tSearch for Bank\n
- L\t\tList Customers\n
- M\t\tList Banks\n
- O\t\tSort Customers\n
- P\t\tSort Banks\n
- Q\t\tQuit\n
- R\t\tRemove Customer\n
- S\t\tRemove Bank\n
- T\t\tClose BankSystem\n
- U\t\tWrite Text to File\n
- V\t\tRead Text from File\n
- W\t\tSerialize BankSystem to File\n
- X\t\tDeserialize BankSystem 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 Customer
- Your program should display the following prompt:
- Please enter the customer information to add:\n
- Read in customer information and parse it using the CustomerParser class, if the customer object with the same customer ID is not in the customer list, then add it into the customer list and display:
- customer added\n
- Otherwise, display:
- customer exists\n
- Add Bank
- Your program should display the following prompt:
- Please enter the bank information to add:\n
- Read in the information and parse it using bank parser. If the bank already exists, display the following message:
- bank exists\n
- Otherwise, add the object to the bank list and display the following:
- bank added\n
- Search for Customer
- Your program should display the following prompt:
- Please enter the customerID of a customer to search:\n
- Read in the string and look up the customer list, if there exists a customer object with the same customer ID, then display the following:
- customer found\n
- Otherwise, display this:
- customer not found\n
- Search for Bank
- Your program should display the following prompt:
- Please enter the bank's name to search:\n
- Read in the bank name, then display the following prompt:
- Please enter the bank's id to search:\n
- Read in the id, then display the following prompt:
- Please enter the bank's city to search:\n
- Read in the city, then display the following prompt:
- Please enter the bank's state to search:\n
- Read in the state, and search the bank list based on these information. If there exists a bank with the bank name, the id, the city, and the state, then display the following:
- bank found\n
- Otherwise, display this:
- bank not found\n
- Sort Customers
- Your program should sort the customers list alphabetically by the last name (A to Z) and output the following:
- customers sorted\n
- If there are multiple customer objects with the same last name in the customer list, they should be sorted by the first name. If both last name and first name are same, their order after sorting should be the same as the order before sorting.
- Sort Banks
- Your program should sort the bank list alphabetically by bank name (A to Z and 0 - 9) and output the following:
- banks sorted\n
- If there are multiple bank objects with the same bank name in the bank list, they should be sorted by their id. If they have the same bank name and the id, then they should be sorted by their address.
- Remove Customer
- Your program should display the following prompt:
- Please enter the customerID to remove:\n
- Read in the string. If the customer object can be found in the customer list, then remove it from the list, and display the following:
- customer removed\n
- If there is no such customer object in the customer list, display:
- customer not found\n
- Reminder:
- Once again, customers will be uniquely identified by the customer ID. In another words, there does NOT exist more than one customer object in the customer list, that have the same customer ID.
- Remove Bank
- Your program should display the following prompt:
- Please enter the bank's bank name to remove:\n
- Read in the bank name and display the following prompt:
- Please enter the bank's id to remove:\n
- Read in the id, and display the following prompt:
- Please enter the bank's city to remove:\n
- Read in the city, and display the following prompt:
- Please enter the bank's state to remove:\n
- Read in the state, and use those information to remove that the bank object from the bank list. If the bank cannot be found, then display the following:
- bank not found\n
- Otherwise, remove successfully, then display:
- bank removed\n
- List Customers
- Each customer information in the customer list should be displayed in the following format:
- \nFirst name:\t\tBarack\n
- Last name:\t\tObama\n
- Customer ID:\t\t000-00-0000\n
- Cash amount:\t\t$2,000.00\n\n
- If there is no customer object in the customer list, display:
- no customer\n
- A real example is looked like this (suppose there are only 2 customer objects in the customer list):
- What action would you like to perform?
- First name: Barack
- Last name: Obama
- Customer ID: 234-56-7890
- Cash amount: $20.00
- First name: George
- Last name: Bush
- Customer ID: 000-00-0000
- Cash amount: $30.00
- List Banks
- Each bank information in the bank list should be displayed in the following format:
- \nBank name:\t\tBank of Arizona\n
- Bank ID:\t\t1005\n
- Bank address:\t\tTempe,AZ\n\n
- If there is no bank object in the bank list, display:
- no bank\n
- A real example is looked like this (suppose there are only 2 bank objects in the bank list):
- What action would you like to perform?
- Bank name: Bank Arizona
- Bank ID: 1
- Bank address: Phoenix,AZ
- Bank name: Bank Nevada
- Bank ID: 5
- Bank address: Las Vegas,NV
- Close BankSystem
- Delete all customers and banks. Then, display the following:
- bank system 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 BankSystem 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 BankSystem 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 BankSystem 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 BankSystem object from that file. Note that there is only one BankSystem object in the Assignment8 class, and the first object read from the file should be assigned to the BankSystem 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.
- Test cases:
- hw8testcases.jar All test case files are in this file. To extract each file:
- jar xf hw8testcases.jar
- OR, you can download each file individually:
- Input
- The following files are the test cases that will be used as input for your program (Right-click and use "Save As"):
- Test Case #1
- Test Case #2
- Test Case #3
- Test Case #4
- Output
- The following files are the expected outputs of the corresponding input files from the previous section (Right-click and use "Save As"):
- Test Case #1
- Test Case #2
- Test Case #3
- Test Case #4
- Error Handling
- Your program is expected to be robust to pass all test cases.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement