Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help writing and implementing a method containing a for loop. PROMPT: Step 1 - Write the listAll() Method This method will cycle through

I need help writing and implementing a method containing a for loop.

PROMPT:

Step 1 - Write the listAll() Method

This method will cycle through all salaries in order. To allow reading to be easier, you should call prettyPrint(int) on every major. It is useful to know that calling data.size() will return the total number of majors that are being tracked in the salary data. If you have 27 majors, it will return 27, even though you should loop from 0 to 26.

Step 2 - Write the listAll() Method Signature

listAll() is a method that is public non-static that returns nothing and has no parameters. Dont forget your beginning and ending curly braces! It should look something like this:

public void listAll() 

When a method is non-static you do not include a static or non-static keyword after public.

Step 3 - Implement the listAll() Method

First, print out getHeader() with a new line so when you run listAll() the user will see a key to the info displayed. This will look like:

DataID. Major Avg. Male Salary Avg. Female Salary Avg. White Salary Avg. PoC Salary Salary Male % Female % White % PoC % 

Now, write a for loop to start at the beginning of our collection of elements called data, stop at the end of data and increments one at a time.

Collection of data is a new topic we are lightly introducing now (we will go over it more later) so to help you out data.size() will return the length of data. This return value is very similar to .length() for Strings. Keep in mind that length is not zero based so a collection of 5 elements will return 5, not 4 (the last index).

NOTE: data does not need to be re-declared since it is a class variable which can be used anywhere in the program with having to be passed as a parameter.

For each iteration of the for loop(inside the for loop) you will simply call prettyPrint() with your for loop variable as the parameter.

prettyPrint() takes an int that represents which individual salary the method will print to the console.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Databases 28th British National Conference On Databases Bncod 28 Manchester Uk July 2011 Revised Selected Papers Lncs 7051

Authors: Alvaro A.A. Fernandes ,Alasdair J.G. Gray ,Khalid Belhajjame

2011th Edition

3642245765, 978-3642245763

More Books

Students also viewed these Databases questions

Question

Apply interpersonal-related tactics for effective team play.

Answered: 1 week ago

Question

What are the stages of project management? Write it in items.

Answered: 1 week ago