Java Program: While Loop Not Exiting, NROWS And NCOLS Issue, And EnterData Method Update

Part A

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.

Save Time On Research and Writing
Hire a Pro to Write You a 100% Plagiarism-Free Paper.
Get My Paper

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?

Save Time On Research and Writing
Hire a Pro to Write You a 100% Plagiarism-Free Paper.
Get My Paper

(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 

Part B

============================================

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:

  • Input 10 batsmen score (run)
  • Take 10 match series
  • Score can be 1 to N
  • Display the raw data which is entered

Report:

Part C: 

(1) Method Description:

  • displayMenu(): It will display menu.
  • getSel(): It will use to enter the user selection the menu option.
  • processSelection(): It will process the program according to user selection.
  • enterData(): With help of this method, user can input the 10 batsmen runs for 10 matches.
  • displayData(): It displays the data which is entered by user.
  • showReport(): It shows report of batsmen. It shows total run rate and average run rate of each batsman in 10 matches.
  • main(): This is method where program starts. It calls other method to process the program.

(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

Calculate your order
Pages (275 words)
Standard price: $0.00
Client Reviews
4.9
Sitejabber
4.6
Trustpilot
4.8
Our Guarantees
100% Confidentiality
Information about customers is confidential and never disclosed to third parties.
Original Writing
We complete all papers from scratch. You can get a plagiarism report.
Timely Delivery
No missed deadlines – 97% of assignments are completed in time.
Money Back
If you're confident that a writer didn't follow your order details, ask for a refund.

Calculate the price of your order

You will get a personal manager and a discount.
We'll send you the first draft for approval by at
Total price:
$0.00
Power up Your Academic Success with the
Team of Professionals. We’ve Got Your Back.
Power up Your Study Success with Experts We’ve Got Your Back.