>> JAVA Programming
We developed a StringLog ADT. It represents a "log" that holds objects of class String. Suppose that instead of restricting ourselves to strings, we decided to create a "log" that holds objects of type Object. Describe the changes you would have to make to each of the following classes to implement such a change.
a. Change StringLogInterface to ObjectLogInterface
b. Change ArrayStringLog to ArrayObjectLog
c. Change ITDArrayStringLog to ITDArrayObjectLog
d. Change LLStringNode to LLObjectNode
e. Change LinkedStringLog to LinkedObjectLog
Write a class Array that encapsulates an array and provides bounds-checked access. The private instance variables should be int index and inarray. The public members should be a default constructor and methods (signatures shown below) to provide read and write access to the array.
void insert(int location, int value);
void retrieve(int location);
If the location is within the correct range for the array, the insert method should set that location of the array to the value. Likewise, if the location is within the correct range for the array, the retrieve method should return the value at that location--the approach taken by the library before Java 5.0. In either case, if location is not within the correct range, the method should throw an exception of class ArrayOutOfBoundsException. Write an application that helps you test your implementation. Your application should assign values to the array by using the insert method, then use the retrieve method to read these values back from the array. It should also try calling both methods with illegal location values. Catch any exceptions thrown by placing the "illegal" calls in a try block with an appropriate catch. Share your code with classmates and compare and discuss the various implementations.
UML Exercise: Automated Teller Machine (ATM)
Brief Statement of Purpose:
An ATM is an electronic device designed for automated dispensing of money. A user can withdraw money quickly and easily after authorization. The user interacts with the system through a card reader and a numerical keypad. A small display screen allows messages and information to be displayed to the user. Bank members can access special functions such as ordering a statement
Brief Summary of Requirements:
The ATM is required:
1. To allow authorized card holders to make transactions
1. Card holders shall view and/or print account balances
<!--[if !supportLists]-->2. <!--[endif]-->Card holder shall make cash withdrawals
<!--[if !supportLists]-->3. <!--[endif]-->Card holder shall make cash or check deposits
4. Card holder shall quit session
2. To allow bank members to access additional, special services
1. A bank member shall be able to order a statement
2. A bank member shall be able to change security details (e.g. PIN number)
3. To allow access to authorized bank staff
1. Authorized staff can gain access to re-stock the machine
2. Authorized staff are able to carry out routine servicing and maintenance
4. To keep track of how much money it contains and alert bank staff when stocks are getting low.
Users shall be able to access the ATM by punching in their account number and PIN. Once the system has verified that the account is active and the PIN matches with the account number, the system offers the users four choices. Users can withdraw money, deposit money, check balance or quit the session.
The user must have a minimum of $100 in his / her account. At the end of any transaction a printed copy of the transaction is provided to the user. A transaction could be - withdraw money, deposit money or check balance. Once the user has completed a transaction, the system offers the user the same four choices, until the user decides to quit.
The system shall interface with the device to dispense cash, the device to accept cash or check and the printer. Since we have not studied databases in this course, the system will keep all the information in two RandomAccess files. One file will hold the passwords and the other account balances.
- Identify and list the actors
- Identify and list the uses cases
- Draw the top level Use-Case diagram
- Give a detailed Use-Case analysis for one use case. Your analysis should contain a brief description of the use case, the basic and alternative flows, pre and post conditions.
- Identify and list nouns of the system to assist in developing initial Class diagram
- Draw initial Class diagram
- Draw Sequence diagram
1. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!. For example, if the input is 4, the output could be:
4! = 4!
= 4 * 3!
= 4 * 3 * 2!
= 4 * 3 *2 * 1!
= 4 * 3 * 2 * 1 * 0!
2. Explain the relationship between dynamic storage allocation and recursion.
3. Based on the Queue ADT specification, an application programmer has two ways to check for an empty queue. Describe them and discus when one approach might be preferable to the other approach.
4. Discuss the relative efficiency of the enqueue and dequeue operations for fixed-front and floating-front approaches to an array-based implementation of a queue.
5. This discussion is based on The Card Game of War application case study in Chapter 5. Implement the program and answer the following:
a. Can a game of War end in a tie? If not, why not? If so, explain how, and describe what our War program would do in that case.
b. When you play cards, you normally shuffle the deck several times before playing. Yet the shuffling algorithm used in our program walks through the array of cards only once. Explain the difference between these two situations.
c. Suppose only four cards are dealt in a game of War, two to each player. Describe a deck of four cards, such that when dealt, will result in a game of War that continues forever.
d. In the play method of the WarGame class, what is the effect of removing the shuffle method invocation?
1. Suppose we have a Rectangle class that includes length and width attributes of type int, both set by the constructor. Create a compareTo method for this class so that rectangle objects are ordered based on their a) Perimeter, and b) Area.
2. Give examples from the "real world" of unsorted lists, sorted lists, indexed lists, lists that permit duplicate elements, and lists that do not permit duplicate elements.
3. Someone suggests that, instead of shifting list elements to the left when an object is removed, the array location holding that object should just be set to null. Discuss the ramifications of such an approach for each of our three list types.
4. Can the linear search algorithm be encoded using recursion? If not, why not? If so, outline an approach and discuss its advantages and disadvantages. Share your thoughts with others in the class.
5. Expand the RefUnsortedList class (section 6.7) with a public method endInsert, which inserts an element at the end of the list. Do not add any instance variables to the class. The method signature is:
public void endInsert(T element)