StudentShare
Contact Us
Sign In / Sign Up for FREE
Search
Go to advanced search...
Free

Development of Simple Menu-Driven Program - Assignment Example

Summary
The assignment "Development of Simple Menu-Driven Program" focuses on the critical analysis and characteristics of the development of a simple menu-driven program. When the program is first run and menu item 2 is selected, the result given is four zeros in three rows…
Download full paper File format: .doc, available for editing
GRAB THE BEST PAPER94.3% of users find it useful

Extract of sample "Development of Simple Menu-Driven Program"

Part A – Code Comprehension 1. When the program is first run and menu item 2 is selected the result given is four zeros in three rows. This is so because the data has not been entered. 2. In the program provided, the display of menu and response processing is excited by the use of while loop and Boolean expression finished. The program runs until the option 4 is selected by user. userOptionSelected has the value 4[0x4] when the program finishes. This is because 4 has been assigned to constant EXIT. In the line userOptionSelected = m.getsel(scan); the variable userOptionSelected of type integer has been assigned the values of m.gtsel(scan) which is the value entered by the user. Variable userOptionSelected will therefore store the int value entered by the user. 3. The reserved word break is used in the switch-statement to manage the menu selection. If you remove the break statement in Case 1, the program will execute Case 2 immediately all the data is entered; this means that displayData() in Case 2 is executed without user selecting option 2. Break statement therefore assist in managing menu selection to allow the user select what is required rather that the system execution on its own. 4. Currently, if the user enters an incorrect menu selection the system returns an error message which is “Please enter valid option: 1,2 or 3” This is an error handling procedure that controls what is entered in the system in order to ensure the right type and range of data is entered; without error trapping, the system may crash or behave unpredictably. The line of code responsible for this error message is the default option under switch (userOption) which gives this:- “Default: System.out.println ("Please enter valid option: 1, 2 or 3"); return 0; Proper error handling makes the work of the user easy and is able to continue even after an error occurs. When data that is not in the range or type of data provided during programming, error handling intercepts the error and tells the program how to handle the error. 5. While loop is a control structure that allows you to repeat a task a certain number of times. The alternative looping structure that could have been used for the main ‘while loop’ is ‘do while Loop’. Do While Loop is just like the ‘while loop’, however ‘do while loop’ must at least execute once. 6. Boolean variable finished The while loop syntax takes the form “while(Boolean_expression)”. The purpose of the boolean variable finished is program has been used as a boolean expression. The program here checks whether the boolean expression result is either true or false in order to execute the actions in the while loop. If the result is true, the action will be executed as long as the result is true. 7. The two lines of code that have been used to create the array to store the scores for each competitor are:- 1. int data[][] = new int[NROWS][NCOLS]; 2. data[i][j] = in.nextInt(); The array data is a 2 dimensional array that stores data for both rows and columns. The array has 3 rows and 4 columns. in this program each judge awards ratings for every competitor, there are three competitors and four judges. 8. When the code in the while loop is changed to ‘while (finished=true);’ the program still execute well without any problem. This therefore means that the code ‘while (finished=true);’ and while (!finished) works in the same way. This has been facilitated by the fact that finished was initialized as false. 9. Currently, menu item one prompts the user for data for up to 3 rows of data and 4 values in each row. This can be change for it to take 6 rows of data, with 4 values on each row by simply changing the values assigned to the constants NROWS from 3 to 6 and that assigned to NCOLS maintained at 4. Therefore the code will be :- 10. the code provided can be re-designed to output for menu selection 2 as indicated in the table below:- Option 2 Selected This is achieved by re-writing the code for displayData() method as follows: 11. The nested for-loop in the enterData() method can be altered so that the user can specify how many rows and how many columns of data to enter for each particular run with a maximum number of columns and rows. This can be achieved by re-writing the code in the enterData() method as follows:- PART B.: Program Specification This program will is designed to manage sports completion among various teams. The program is menu driven, therefore it provides the user will several options to select from based on the action to be undertaken. The menus available will be:- Option 1 Data Capture Enter team numbers Enter Number of Judges Scores entry Option 2: Generate reports Display all the raw data Display total score per team. Option 3: Show reports Calculate and show the average score for each team Calculate the average score awarded by each judge. Calculate the highest score and best team Option 4: Exit The program has been designed in such a way that the organizers need not be sure of the judges to be recruited not the teams to participate, the team therefore stats by providing a menu foe the user to select the task to perform. The system then asks for the number of judges available and the number of teams available. This number is store in the system as two dimensional arrays. Judges Teams Ken John Janet Total Team 1 7 6 10 23 Team 2 7 10 6 23 Team 3 10 8 7 25 Team 4 8 6 10 24 Total 32 30 33 95 Moreover, due to field capacity, the system has a maximum number of teams that can participate and also judges, therefore in as much as the system allows the organizers to enter any number of teams or judges; the system has a maximum limit to this number. Each of the teams will be given a name under which the judge will use to enter their scores. Judges will be guided by the system and cannot enter scores for non existing teams; the number of teams available will therefore be fixed. Once the competition is done, the organizers need to reward the best performers, this will be facilitated by the system given that all the scores entered can be printed out, sorted and presented in the best format. The scores are summarized s follows:- Total scores for each team. Average score for each team. Average score for each judge. Maximum score awarded Raw data of the final scores. The program will be designed to verify all data entered in order to ensure valid data is entered into the system; this will also facilitate sorting, report generation and fail score awards. The judges therefore will be reminded by the system whenever they make a mistake capturing scores in to the system. Part C and D: (in the Java code attached) The program has been tested and is running fine. Read More
sponsored ads
We use cookies to create the best experience for you. Keep on browsing if you are OK with that, or find out how to manage cookies.
Contact Us