For this assignment you are required to specify, design, implement and test a menu driven program of your own design. You are to imagine that you are developing a prototype for entering the initial records of a system and providing reports from that system. For example you could design a program that supports entering membership details of a club or entering records of student grades within a class or any system you can imagine involving storing personal details in a two dimensional array. You are provided with incomplete sample starter code that you can modify and build upon. You are expected to fully comment the provided code as well as your own code.
Part A –
Code Comprehension Sample code has been provided in Moodle. Use the sample code provided to answer the following questions:
(1) When the program is first run and menu item 3 is selected what is displayed? Explain what has happened?
(2) When the program is run and menu item 1 is selected and then menu item 3 is selected what is displayed?
(3) If the program is run, menu item 1 is selected and the user attempts to add in 4 members what will happen and why?
(4) Explain how the loop displaying the menu and processing a response is exited. What value does userOptionSelected have when the program finishes? Describe what happens on this line: userOptionSelected = m.getsel(scan); // get a user option entered.
(5) The reserved word break is used in the switch-statement to manage the menu selection. What happens if you remove the break statement in case 3?
(6) Currently, if the user enters an incorrect menu selection (such as 5) what happens? Explain why the error message is displayed. What method and line of code is responsible and why.
(7) What alternative looping structure could have been used for the main while loop?
(8) Explain the purpose of the boolean variable finished.
(9) Briefly explain the two lines of code that have been used to create the array to store the scores for each competitor. In your explanation, provide a diagram to illustrate how the array is stored.
(10) Explain what would happen (and why) if the code in the while loop was changed to: while(finished==true)
(11) Currently, menu item one prompts the user for data for up to 3 rows of data and 4 values in each row. What change would you have to make to the code so that the data contains 8 rows of data, with 8 values on each row? 12. The design of the output for menu selection 2 needs to be changed so that it displays the data as per the following:
Row 1: Smith,Bruce 22 1 12.00
============================================
Row 2: Brown,Peter 24 2 12.00
============================================
Row 3: Maison,Mark 38 3 6.00
============================================
Provide the changes to the code that you need to make to do this.
Part B – Program Requirements
The first part of the assignment is to describe the requirements of your program to be developed. This should provide enough details so that another programmer would be able to design and implement the program. Your program should present the user with a menu that provides at least the following functionality:
(1) Input the number of members, students, etc
(2) Input values to fill your two-dimensional array
(3) View reports – at least two different reports (e.g. list members with a particular member level, list members who owe more than a certain amount)
(4) Quit the system Your requirements should allow your program to conform to the design constraints listed above. A basic example of “program requirements” has been provided for you to refer to (see page 6 of this document for the Example Specification
Part C –
Analysis and Design a program for the task you have specified in Part B. You should include:
(1) A description of the methods used to address the program requirements
(2) High level pseudo-code for each menu option and associated method
(1) It will display “The average age of all members is NaN”. It displays only because user did not enter any data.
(2) It will display the average age of all members which are entered after selection of option 1.
(3) It will throw exception ArrayIndexOutOfBoundsException because rows can up to 3 only.
(4) After selecting 4th option, program exits. The userOptionSelected has value 4.
userOptionSelected = m.getsel(scan);
The value is assigned to userOptionSelected. The getsel() Function gives the value which is selected by user.
(5) If there is no break statement in case 3, program will jump to default case. After printing default case, it will print menu.
(6) There is message which suggests the user to enter valid option, if invalid option is entered. This is default case.
(7) do-while loop
(8) The ‘while loop’ is handled by ‘finished’ Boolean variable.
(9) String memberData[][] = new String[NROWS][NCOLS];
The above statement is used to create to store data. It is 2-dimentional array having 3 rows and 4 columns.
(10) There will not any way to exit from while loop, if there is such statement because while loop condition is always true.
(11) Change NROWS to 8 and NCOLS to 8, the problem will solve.
(12) We have to add something in enterData() method.
Update Code
void enterData(Scanner in) {
System.out.println(“How many rows ? (up to “+ NROWS + “)”);
numMembers = in.nextInt();
System.out.println(“How many cols ? (up to ” + NCOLS + “)”);
int cols = in.nextInt();
for(int i=0; i< numMembers;i++){
System.out.println(“Row” + i + “: “);
memberData[i][NAME] = in.next();
memberData[i][AGE] = in.next();
memberData[i][MEMBERLEVEL] = in.next();
memberData[i][FEES] = in.next();
}
}
Updated code is highlighted.
Part B:
Basic requirements of program:
Program menu option:
(1) Enter data
(2) Display data
(3) Display report
(4) Exit
General Program Requirement:
Report:
Part C:
(1) Method Description:
(2) Pseudo-code
displayMenu() Function
Display menu
End displayMenu() Function
getSel() Function
get user input
return user input
End getSel() Function
processSelection()Function
switch case
case 1:
enterData()
case 2:
displayData()
case 3:
showReport()
End switch case
End processSelection() Function
enterData( ) Function
INPUT run for each batsman one by one
End enterData( ) Function
displayData( ) Function
PRINT run of each batsman
End displayData( ) Function
showReport( ) Function
Calculate the total run rate of each batsman
Calculate the average run rate of each batsman
Display total run rate of each batsman
Display average run rate of each batsman
End showReport( ) Function
main() Function
Initialize local variable
while loop
displayMenu()
getSel()
processSelection()
End while loop
End main() Function
We provide professional writing services to help you score straight A’s by submitting custom written assignments that mirror your guidelines.
Get result-oriented writing and never worry about grades anymore. We follow the highest quality standards to make sure that you get perfect assignments.
Our writers have experience in dealing with papers of every educational level. You can surely rely on the expertise of our qualified professionals.
Your deadline is our threshold for success and we take it very seriously. We make sure you receive your papers before your predefined time.
Someone from our customer support team is always here to respond to your questions. So, hit us up if you have got any ambiguity or concern.
Sit back and relax while we help you out with writing your papers. We have an ultimate policy for keeping your personal and order-related details a secret.
We assure you that your document will be thoroughly checked for plagiarism and grammatical errors as we use highly authentic and licit sources.
Still reluctant about placing an order? Our 100% Moneyback Guarantee backs you up on rare occasions where you aren’t satisfied with the writing.
You don’t have to wait for an update for hours; you can track the progress of your order any time you want. We share the status after each step.
Although you can leverage our expertise for any writing task, we have a knack for creating flawless papers for the following document types.
Although you can leverage our expertise for any writing task, we have a knack for creating flawless papers for the following document types.
From brainstorming your paper's outline to perfecting its grammar, we perform every step carefully to make your paper worthy of A grade.
Hire your preferred writer anytime. Simply specify if you want your preferred expert to write your paper and we’ll make that happen.
Get an elaborate and authentic grammar check report with your work to have the grammar goodness sealed in your document.
You can purchase this feature if you want our writers to sum up your paper in the form of a concise and well-articulated summary.
You don’t have to worry about plagiarism anymore. Get a plagiarism report to certify the uniqueness of your work.
Join us for the best experience while seeking writing assistance in your college life. A good grade is all you need to boost up your academic excellence and we are all about it.
We create perfect papers according to the guidelines.
We seamlessly edit out errors from your papers.
We thoroughly read your final draft to identify errors.
Work with ultimate peace of mind because we ensure that your academic work is our responsibility and your grades are a top concern for us!
Dedication. Quality. Commitment. Punctuality
Here is what we have achieved so far. These numbers are evidence that we go the extra mile to make your college journey successful.
We have the most intuitive and minimalistic process so that you can easily place an order. Just follow a few steps to unlock success.
We understand your guidelines first before delivering any writing service. You can discuss your writing needs and we will have them evaluated by our dedicated team.
We write your papers in a standardized way. We complete your work in such a way that it turns out to be a perfect description of your guidelines.
We promise you excellent grades and academic excellence that you always longed for. Our writers stay in touch with you via email.