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.

Part A –

Don't use plagiarized sources. Get Your Custom Essay on
Java Program: While Loop Not Exiting, NROWS And NCOLS Issue, And EnterData Method Update
Just from $13/Page
Order Essay

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 

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:

  • Total Score (run) of batsman (player)
  • Average run rate of batsman

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

What Will You Get?

We provide professional writing services to help you score straight A’s by submitting custom written assignments that mirror your guidelines.

Premium Quality

Get result-oriented writing and never worry about grades anymore. We follow the highest quality standards to make sure that you get perfect assignments.

Experienced Writers

Our writers have experience in dealing with papers of every educational level. You can surely rely on the expertise of our qualified professionals.

On-Time Delivery

Your deadline is our threshold for success and we take it very seriously. We make sure you receive your papers before your predefined time.

24/7 Customer Support

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.

Complete Confidentiality

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.

Authentic Sources

We assure you that your document will be thoroughly checked for plagiarism and grammatical errors as we use highly authentic and licit sources.

Moneyback Guarantee

Still reluctant about placing an order? Our 100% Moneyback Guarantee backs you up on rare occasions where you aren’t satisfied with the writing.

Order Tracking

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.

image

Areas of Expertise

Although you can leverage our expertise for any writing task, we have a knack for creating flawless papers for the following document types.

Areas of Expertise

Although you can leverage our expertise for any writing task, we have a knack for creating flawless papers for the following document types.

image

Trusted Partner of 9650+ Students for Writing

From brainstorming your paper's outline to perfecting its grammar, we perform every step carefully to make your paper worthy of A grade.

Preferred Writer

Hire your preferred writer anytime. Simply specify if you want your preferred expert to write your paper and we’ll make that happen.

Grammar Check Report

Get an elaborate and authentic grammar check report with your work to have the grammar goodness sealed in your document.

One Page Summary

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.

Plagiarism Report

You don’t have to worry about plagiarism anymore. Get a plagiarism report to certify the uniqueness of your work.

Free Features $66FREE

  • Most Qualified Writer $10FREE
  • Plagiarism Scan Report $10FREE
  • Unlimited Revisions $08FREE
  • Paper Formatting $05FREE
  • Cover Page $05FREE
  • Referencing & Bibliography $10FREE
  • Dedicated User Area $08FREE
  • 24/7 Order Tracking $05FREE
  • Periodic Email Alerts $05FREE
image

Our Services

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.

  • On-time Delivery
  • 24/7 Order Tracking
  • Access to Authentic Sources
Academic Writing

We create perfect papers according to the guidelines.

Professional Editing

We seamlessly edit out errors from your papers.

Thorough Proofreading

We thoroughly read your final draft to identify errors.

image

Delegate Your Challenging Writing Tasks to Experienced Professionals

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!

Check Out Our Sample Work

Dedication. Quality. Commitment. Punctuality

Categories
All samples
Essay (any type)
Essay (any type)
The Value of a Nursing Degree
Undergrad. (yrs 3-4)
Nursing
2
View this sample

It May Not Be Much, but It’s Honest Work!

Here is what we have achieved so far. These numbers are evidence that we go the extra mile to make your college journey successful.

0+

Happy Clients

0+

Words Written This Week

0+

Ongoing Orders

0%

Customer Satisfaction Rate
image

Process as Fine as Brewed Coffee

We have the most intuitive and minimalistic process so that you can easily place an order. Just follow a few steps to unlock success.

See How We Helped 9000+ Students Achieve Success

image

We Analyze Your Problem and Offer Customized Writing

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.

  • Clear elicitation of your requirements.
  • Customized writing as per your needs.

We Mirror Your Guidelines to Deliver Quality Services

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.

  • Proactive analysis of your writing.
  • Active communication to understand requirements.
image
image

We Handle Your Writing Tasks to Ensure Excellent Grades

We promise you excellent grades and academic excellence that you always longed for. Our writers stay in touch with you via email.

  • Thorough research and analysis for every order.
  • Deliverance of reliable writing service to improve your grades.
Place an Order Start Chat Now
image

Order your essay today and save 30% with the discount code Happy