我是一只小小鸟-------请教一道JAVA题
本人初学 J Builder,现遇一英文原题,望高手赐教,
beckshan@sina.com
You are required to design and implement a menu-based Java program called NumberListManager.java to:
• Process a list of at most 20 unique integer numbers with values in the range 1 to 10,000.
• Demonstrate the use of a Sort algorithm.
• Demonstrate the use of files for input and output.
• Demonstrate the use of Binary Search techniques.
The main method of NumberListManager must provide the following menu facilities:-
• Initialise list
Initialises the list as empty.
• Generate random list
Generates a user specified number of unique random numbers in the range 1 to 10,000. The user is requested to specify the number of values to generate ( a minimum of 1 – a maximum of 20 ).
Once the values are generated the list must be sorted into ascending numerical order.
• Display list
Displays the contents of the list indicating the values contained together with their index position within the list.
• Load list
Sets the list to the values contained in a file called:
Numbers.dat
The file is read using a Read-Ahead method based on a while construct. The numbers are terminated by a –1 value and you may assume there will only be a maximum of 20 numbers, all unique, stored in ascending order followed by the terminating –1.
• Save list
Saves the contents of the list to a file called:
Numbers.dat
All active values are output followed by a terminating –1 value.
• Search list
Searches the list using a Binary Search algorithm.
The progress of the algorithm must report the lower bound, upper bound, mid-point and the values being compared during each probe of the list.
The outcome of the search must report a successful or unsuccessful outcome together with the number of probes performed.
• Add
Permits the user to enter a number to be included in its correct place within the current list.
Attempting to add a number when the list is already full or to add a number which already exists in the list must be prohibited and reported in a suitable manner.
The addition MUST NOT be achieved by simply appending the new number to the end of the list, incrementing the count of numbers in the list and then sorting the list.
• Remove
Permits the user to specify a number to be removed from the list.
Attempting to remove a number when the list is presently empty or to remove a number which does not exist in the list must be prohibited and reported in a suitable manner.
The removal of a list entry may be achieved by moving any subsequent entries forward/up one position in the list e.g. removal of an entry at position 3 in the list ( with many further entries ) is achieved by copying the entry at position 4 into position 3 followed by copying the entry at position 5 into position 4 ………. until the last entry has also been brought forward. The count of numbers in the list is then decremented to reflect the change in list size.
• Exit
Terminates the program.
Each option is selected by entry of a specified single character e.g. 0, 1, 2 etc. An exit is selected by entering an E or e.
The logic/code associated with each option is to be provided in suitable static methods within the NumberListManager class.
One third of the available marks are associated with the testing of the implementation. You are required to consider:
• an erroneous user selection;
• an erroneous user entered value denoting the number of values to generate e.g. 21 or even -1;
• attempts to add additional values to an already full list;
• attempts to add duplicating values;
• attempts to remove values which do not exist within the list;
• attempts to remove values from an already empty list;
• the various forms the numerical list can have during the execution of the program i.e. the list may be empty, contain many numbers or even be full when an option is selected. The logic/code associated with each option should be robust and able to handle extreme list states e.g. searching an empty list, sorting a full list, loading an empty list.
• The various tests required when searching a list for:
• The first value in a partially full list;
• The last value in a partially full list;
• The last value in a full list;
• The first and only value in a single entry list;
• A non-existent value lower in value than the first list entry;
• A non-existent value greater in value than the last list entry;
• A non-existent value greater in value than the first list entry and lower in value than the last list entry.
The terms first value and last value can be determined at run-time by displaying the contents of the list prior to searching i.e. the first value is whatever was randomly generated for the first entry.
These represent a number of suggestions but show that the program should continue to function correctly under various diverse states. There are other states which should be considered.