Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

LAB PROMPT: Lab 08 - Salary Data Analysis In this lab you will review and implement a light analysis of majors from their salary data.

LAB PROMPT:

Lab 08 - Salary Data Analysis

In this lab you will review and implement a light analysis of majors from their salary data. The purpose of this lab is to practice writing a loop and your code tracing/reading skills. In the second portion of this lab, you will identify various issues within the program and correct them yourself.

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.

*The rest of the prompt is just above fixing bugs in code that's already written, I've taken that part of the provided code out*

PROVIDED CODE:

import java.text.NumberFormat; import java.util.Locale; import java.util.Scanner;

public class SalaryAnalysis { // NO BUGS RIGHT BELOW HERE private final static NumberFormat CURRENCY_FMT = NumberFormat.getCurrencyInstance(Locale.US); // it is final because we never want to change it, so prevents that from happening

private SalaryData data = new SalaryData("salary_data.csv"); // this variable is used throughout your code to access the data. private Scanner scanner = new Scanner(System.in);

// NO BUGS UP THERE HERE ^^

/** * Use this method to test your other methods - that way you don't hav to go through the full * menu system as you develop one line at a time. In the main method, you should uncomment the call * to this before you submit your final program. (or comment out all lines in this method) * * This is purposely fairly empty - as it is for you to use. */ public void testMethod() { // NO BUGS IN HERE // Add to this method to make sure all the methods are work properly! System.out.println("Printing first major to make sure data set loads: " + data.getMajor(0)); prettyPrint(0); }

/** * This method will cycle through all salaries in order. * To allow reading to be easier, you should call {@link #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. * */ //TODO

//End TODO /** * Prints out a single line of Salary Data using a pretty print style format * The format is as follows. *

 * DataID. Major Average Male Salary Average Female Salary Average White Salary Average PoC Salary Average Salary Percent Male Percent Female Percent White Percent PoC * 

* * here is an example using Ag. Science *

 * 0. Agriculture / Animal Sciences $57,028.99 $47,437.97 $55,829.54 $47,817.34 $54,624.16 74.93% 25.07% 84.96% 15.04% * 

* * It should be noted that the spaces are actually the tab characters \t * Everything should be formatted using the Currency Formatter * * HINT: System.out.println(CURRENCY_FMT.format(data.getSalary(dataID))); (try it) * HINT: use "\t" to create the spacing above * HINT: try just printing out the dataID first, and then slowly add each line. * * @param dataID the salary you want printed from 0 - size of the data */ ***THESE NEXT FEW LINES OF CODE ARE ALL THAT HAVE TO DO WITH SALARY***

public void prettyPrint(int dataID) { // NO BUGS IN HERE System.out.print(dataID + ".\t"); System.out.print(data.getMajor(dataID) + "\t"); System.out.print(CURRENCY_FMT.format(data.getMaleSalary(dataID)) + "\t"); System.out.print(CURRENCY_FMT.format(data.getFemaleSalary(dataID)) + "\t"); System.out.print(CURRENCY_FMT.format(data.getWhiteSalary(dataID)) + "\t"); System.out.print(CURRENCY_FMT.format(data.getPocSalary(dataID)) + "\t"); System.out.print(CURRENCY_FMT.format(data.getSalary(dataID)) + "\t"); System.out.print(data.getMalePercent(dataID) + "%\t"); System.out.print(data.getFemalePercent(dataID) + "%\t"); System.out.print(data.getWhitePercent(dataID) + "%\t"); System.out.println(data.getPocPercent(dataID) + "%\t"); }

/** * Finds the dataId of the major with the highest starting salary. * * @return dataID - the id of the major with the highest salary */ public int findHighestSalary() { // NO BUGS IN HERE int dataID = 0; double salary = 0; for(int i = 0; i < data.size(); i++) { if(data.getSalary(i) > salary) { salary = data.getSalary(i); dataID = i; } }

return dataID; }

/** * Finds the dataId of the major with the highest starting male salary. * * @return dataID - the id of the major with the highest male salary */ public int findHighestMaleSalary() { int dataID = 0; double salary = 0; for(int i = 0; i < data.size(); i++) { if(data.getMaleSalary(i) > salary) { salary = data.getMaleSalary(i); dataID = i; } } return dataID; }

/** * Finds the dataId of the major with the highest starting female salary. * @return dataID - the id of the major with the highest female salary */ public int findHighestFemaleSalary() { int dataID = 0; double salary = 0; for(int i = 0; i < data.size(); i++) { if (data.getFemaleSalary(i) > salary) { salary = data.getFemaleSalary(i); dataID = i; } } return dataID; }

/** * Finds the dataId of the major with the highest starting white salary. * @return dataID - the id of the major with the highest white salary */ public int findHighestWhiteSalary() { int dataID = 0; double salary = 0; for(int i = 0; i < data.size(); i++) { if (data.getWhiteSalary(i) > salary) { dataID = data.getWhiteSalary(i); salary = i; } } return dataID; }

/** * Finds the dataId of the major with the highest starting salary for people of color. * * @return dataID - the id of the major with the highest salary for people of color */ public int findHighestPocSalary() { int dataID = 0; double salary = 0; for(int i = 0; i < data.size(); i++) { if (data.getPocSalary(i) < salary) { salary = data.getPocSalary(i); dataID = i; } } return dataID; }

/** * Finds the dataId of the major with the highest percent males in industry * * @return dataID - the id of the major with the highest percent males in industry */ public int findHighestPercentMales() { int dataID = 0; double percent = 0; for(int i = 0; i < data.size(); i++) { if (data.getMalePercent(i) > percent); percent = data.getMalePercent(i); dataID = i; } return dataID; }

/** * Finds the dataId of the major with the highest percent females in industry * * @return dataID - the id of the major with the highest percent females in industry */ public int findHighestPercentFemales() { int dataID = 0; double percent = 0; for(int i = 0; i < data.size(); i++) { if (data.getFemalePercent(i) > percent) { percent = data.getFemalePercent(i); dataID = i; } } return dataID; }

/** * Finds the dataId of the major with the highest percent whites in industry * * @return dataID - the id of the major with the highest percent whites in industry */

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

Step: 3

blur-text-image

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

Database Driven Web Sites

Authors: Mike Morrison, Joline Morrison

1st Edition

061901556X, 978-0619015565

More Books

Students also viewed these Databases questions

Question

4. Does cultural aptitude impact ones emotional intelligence?

Answered: 1 week ago