You are on page 1of 19

Project 5

In Project 5, you will complete one program together with a black-box test plan and white-box
test program:
● Gender Pay Gap: Write a program that allows the user to learn more about the gap
between salaries earned by men and women in the United States.

Deadlines
On-time Submission: July 13, 11:45 PM.
Late Submission (-10 points): July 14, 11:45 PM.

Learning Outcomes
The following is a list of outcomes that are covered in this assignment:
● Apply classic problem-solving techniques to simple computational and information-
management problems, specifically: breaking large problems into smaller ones,
sequential analysis of solution steps.
● Evaluate an arithmetic expression using order of operations, promotion from integer to
floating-point types, and integer division.
● Use a programming language to write a loop.
● Use a programming language to write code that selects one of several alternatives
based on more than one predicate.
● Correct syntax errors and distinguish between them and runtime errors or errors in logic.
● Verify and validate programs using white- and black-box testing.
● Write and document programs that adhere to specific coding and documentation
standards (e.g., javadoc for documentation; conventions regarding the naming of
classes and methods, definition of constants, indention, etc.).
● Use the Java system classes to do text-based input and output.
● Construct and use arrays.

Academic Integrity
You must work on the project by yourself and only receive help from:
● the current CSC 116 instructors
● the current CSC 116 TAs
Do not work with another student on the project, help another student with the project, or
ask another student for help. Do not turn in code that you completed in a previous
semester of CSC 116. Doing so may result in your being charged with an academic integrity
violation.
Do not post this project description online. Doing so is a very serious offense and will
result in serious consequences.
Please see the syllabus for your section for more information about academic integrity as
related to the projects.

Software Development Phases


Throughout this project writeup, you will notice several icons related to phases of software
development. There are five fundamental phases in any software development process.

Software Lifecycle
Description
Phase

requirements

design

implementation

testing: unit testing & system


testing

deployment

Style and Documentation


Follow the course Style Guidelines when writing and documenting your programs. Provide
proper Javadoc comments for all of your classes and methods! Do not use magic numbers!
An Automated Style Checker is also available to you. We suggest using the style checker on
your code to help avoid losing style points. Keep in mind that it is not perfect, for example, it
may identify magic numbers that are OK to use, so be sure to compare its output to the
guidelines found in this project specification.
Gender Pay Gap Program Overview
Tasks

1. Read the Software Requirements


Familiarize yourself with the provided salary data for various positions as well as the
menu-based user interface and options.

2. Design Your Software


Your software must include and use the getJobList(), getAllJobs(), searchByJob(),
searchBySalaryRange(), and searchByPercentage() methods.

3. Implement Your Software


Implement the software that stores salary information for each job and then continually
allows the user to choose a menu option.

4. Test Your Software


Use your completed black-box test plan and white-box test program to test your
program.

5. Submit Your Software


Follow the submission instructions.

Your Project5 directory should contain the following directories with the given contents:

-> Project5
-> src
-> Job.java
-> PayGap.java
-> test
-> PayGapTest.java
-> lib
-> junit-4.12.jar
-> hamcrest-core-1.3.jar
-> bin
-> Job.class
-> PayGap.class
-> PayGapTest.class
-> test-files
-> (All of your test files, e.g., salaries.csv, three_jobs.csv, etc.)
-> project_docs
-> BlackBoxTestPlan_PayGap.pdf
Your `lib` (library) directory must contain the JUnit jar (Java archive) files: junit-4.12.jar,
hamcrest-core-1.3.jar

You will use the following commands to compile the source files (.java files) and run
your PayGap program from the Project5 directory:
csc$ javac -d bin src/Job.java
csc$ javac -d bin -cp bin src/PayGap.java
csc$ java -cp bin PayGap test-files/filename

You will use the following commands to compile and run your PayGapTest program from
the Project5 directory:
csc$ javac -d bin -cp bin:lib/* test/PayGapTest.java
csc$ java -cp bin:lib/* org.junit.runner.JUnitCore PayGapTest

NOTE: To compile and run the test program on a Windows cmd prompt terminal
window or a Git Bash command line program, you must use a semicolon instead of a
colon between the directories and enclose the combination in quotes, as shown below:
csc$ javac -d bin -cp "bin;lib/*" test/PayGapTest.java
csc$ java -cp "bin;lib/*" org.junit.runner.JUnitCore PayGapTest

Read the Software Requirements

Studies have shown that women tend to make less money than men when doing the
same job, which results in a "gender pay gap." See The Simple Truth about the Gender
Pay Gap for one such study.

For this project, you will write a program named PayGap that allows the user to examine
average female and male salaries for a variety of jobs based on 2015 salary data.

The project is based on an assignment created by Emily Cao, Student, Harvey Mudd
College, and Eleanor Rackoff, Research Assistant, Caltech, and uses data obtained
from the Information is Beautiful website.

File Format
The salary data is provided in a comma-separated values (CSV) file. Each line of the file
contains the following information, with a comma between the values:

● Job description, which may consist of one or more words


● Female salary
● Male salary

The file containing the data, which will be stored in the test-files directory, will be
specified as a command-line argument to the program. For example,
csc$ java -cp bin PayGap test-files/salaries.csv

If there is not exactly one argument on the command line, then the following usage
message shall be displayed and the program will immediately exit. For example,
csc$ java -cp bin PayGap
Usage: java -cp bin PayGap filename

If the file on the command line cannot be accessed, then the following message shall be
displayed and the program will immediately exit. For example,
csc$ java -cp bin PayGap test-files/junk.csv
Unable to access input file: test-files/junk.csv

The file salaries.csv contains the job and salary data used in the examples given below.
However, your program must work for any properly formatted file of job and salary data.
Another file, three_jobs.csv, is also provided. Be sure to download and work with these
files as text files.

Header
Your program must display a header that lists the name of the application and provides
instructions about using the program.

Input/Error Handling
The program shall continually prompt the user with the following menu until they desire
to quit.
Gender Pay Gap Information - Please enter an option below.

D - Display all jobs


J - Search by job
S - Search by salary range
P - Search by percentage
Q - Quit the program
Option:

The program shall accept and use both upper and lower case letters for the options. If
the user enters an invalid option, the program shall output an error message and
redisplay the menu. For example,
Gender Pay Gap Information - Please enter an option below.

D - Display all jobs


J - Search by job
S - Search by salary range
P - Search by percentage
Q - Quit the program

Option: display
Invalid option

Gender Pay Gap Information - Please enter an option below.

D - Display all jobs


J - Search by job
S - Search by salary range
P - Search by percentage
Q - Quit the program

Option:

Sample input/output for each of the options is provided below:

D - Display all jobs


Gender Pay Gap Information - Please enter an option below.

D - Display all jobs


J - Search by job
S - Search by salary range
P - Search by percentage
Q - Quit the program

Option: d
Female Male
Job Description Salary Salary
--------------- ------ ------
Accountants and auditors 51948 64272
Advertising sales agents 45292 54132
Architecture and engineering occupations 60216 73476

. . .
. . .
. . .
Waiters and waitresses 21580 26052
Web developers 51376 64740
Wholesale and retail buyers (except farm products) 41912 50440

Gender Pay Gap Information - Please enter an option below.

D - Display all jobs


J - Search by job
S - Search by salary range
P - Search by percentage
Q - Quit the program

Option:

J - Search by job
Gender Pay Gap Information - Please enter an option below.

D - Display all jobs


J - Search by job
S - Search by salary range
P - Search by percentage
Q - Quit the program

Option: J
Job (contains/is): teach
Female Male
Job Description Salary Salary
--------------- ------ ------

Elementary and middle school teachers 49712 56992


Other teachers and instructors 40144 56992
Postsecondary teachers 59436 73268
Secondary school teachers 51168 57616
Special education teachers 51324 56056
Teacher assistants 25688 30160
Gender Pay Gap Information - Please enter an option below.

D - Display all jobs


J - Search by job
S - Search by salary range
P - Search by percentage
Q - Quit the program

Option: j
Job (contains/is): middle school
Female Male
Job Description Salary Salary
--------------- ------ ------

Elementary and middle school teachers 49712 56992

Gender Pay Gap Information - Please enter an option below.

D - Display all jobs


J - Search by job
S - Search by salary range
P - Search by percentage
Q - Quit the program

Option: j
Job (contains/is): xyz
Female Male
Job Description Salary Salary
--------------- ------ ------

Gender Pay Gap Information - Please enter an option below.

D - Display all jobs


J - Search by job
S - Search by salary range
P - Search by percentage
Q - Quit the program

Option: J
Job (contains/is): cashiers
Female Male
Job Description Salary Salary
--------------- ------ ------

Cashiers 20124 21424


Gender Pay Gap Information - Please enter an option below.

D - Display all jobs


J - Search by job
S - Search by salary range
P - Search by percentage
Q - Quit the program

Option:

S - Search by salary range


If the user enters a value that cannot be read as an int, a maximum value that is less
than the minimum value, or a negative value, output "Invalid value".
Gender Pay Gap Information - Please enter an option below.

D - Display all jobs


J - Search by job
S - Search by salary range
P - Search by percentage
Q - Quit the program

Option: s
Minimum salary: 45000
Maximum salary: 55000
Female Male
Job Description Salary Salary
--------------- ------ ------

Advertising sales agents 45292 54132


Arts/design/entertainment/sports/media occupations 45240 53248
First-line supervisors of non-retail sales workers 45656 52208
Purchasing agents (except wholesale/retail/farm products) 46644 54808

Gender Pay Gap Information - Please enter an option below.

D - Display all jobs


J - Search by job
S - Search by salary range
P - Search by percentage
Q - Quit the program
Option: S
Minimum salary: -5
Invalid value

Gender Pay Gap Information - Please enter an option below.

D - Display all jobs


J - Search by job
S - Search by salary range
P - Search by percentage
Q - Quit the program

Option: s
Minimum salary: 92500
Maximum salary: 85000
Invalid value

Gender Pay Gap Information - Please enter an option below.

D - Display all jobs


J - Search by job
S - Search by salary range
P - Search by percentage
Q - Quit the program

Option: S
Minimum salary: 51000
Maximum salary: 51100
Female Male
Job Description Salary Salary
--------------- ------ ------

Gender Pay Gap Information - Please enter an option below.

D - Display all jobs


J - Search by job
S - Search by salary range
P - Search by percentage
Q - Quit the program

Option:

P - Search by percentage
Displays all jobs in which the female salary is less than the given percentage of the
male salary. If the user enters a value that cannot be read as an int or a value that is
less than 1 or greater than 100, output "Invalid value".
Gender Pay Gap Information - Please enter an option below.

D - Display all jobs


J - Search by job
S - Search by salary range
P - Search by percentage
Q - Quit the program

Option: P
Percentage (1-100): 65
Female Male
Job Description Salary Salary
--------------- ------ ------

Legal occupations 52052 91780


Personal financial advisors 52208 85124
Physicians and surgeons 64792 104104

Gender Pay Gap Information - Please enter an option below.

D - Display all jobs


J - Search by job
S - Search by salary range
P - Search by percentage
Q - Quit the program

Option: p
Percentage (1-100): 0
Invalid value

Gender Pay Gap Information - Please enter an option below.

D - Display all jobs


J - Search by job
S - Search by salary range
P - Search by percentage
Q - Quit the program

Option: P
Percentage (1-100): 105
Invalid value

Gender Pay Gap Information - Please enter an option below.


D - Display all jobs
J - Search by job
S - Search by salary range
P - Search by percentage
Q - Quit the program

Option: p
Percentage (1-100): 20
Female Male
Job Description Salary Salary
--------------- ------ ------

Gender Pay Gap Information - Please enter an option below.

D - Display all jobs


J - Search by job
S - Search by salary range
P - Search by percentage
Q - Quit the program

Option:

Q - Quit the program


Gender Pay Gap Information - Please enter an option below.

D - Display all jobs


J - Search by job
S - Search by salary range
P - Search by percentage
Q - Quit the program

Option: Q

Goodbye!

<Program Exits>
Design Your Software

Your program will create and use an array of Job class objects. The Job class is
provided for you in the file, Job.java. See the Job API for information about the Job
constructor and methods. Do not change this file, but use it as is. Place it in the same
directory as your PayGap.java file. You will need to compile both files.

The program must contain and use the completed version of the following methods:
getJobList(), getAllJobs(), searchByJob(), searchBySalaryRange(), and
searchByPercentage(). The method headers are listed below. You MUST use these
exact method headers in your program so that we can automate the testing of your
program. You must replace the comments below with proper Javadoc documentation!
You are welcome to use code from class, but you must note it in the Javadoc for the
given method.

//Create a Scanner for the given file and read through the file

//once counting the number of lines (jobs)

//Create an array of Job objects of the correct size

//Create another Scanner for the file and read through the file again

//reading the information for each job and storing it in the Job array

//Return the Job array

//If a FileNotFoundException occurs, throw an IllegalArgumentException

//with the message, "Unable to access input file: <filename>", for example,

//"Unable to access input file: test-files/junk.txt"

//The IllegalArgumentException should be caught by the calling method --

//see the Implementation section for how to do this

public static Job[] getJobList(String filename) {

//Return a String with the name, female salary, and male salary for

//each job as shown above.


//HINT: Use the Job toString() method which will provide the correct
formatting

public static String getAllJobs(Job[] jobs) {

//Return a String with the name, female salary, and male salary for each job

//that contains or is the same as the given String, disregarding case

//If no jobs contain the String, an empty string is returned

//HINT: Use the Job toString() method which will provide the correct
formatting

public static String searchByJob(String job, Job[] jobs) {

//Return a String with the name, female salary, and male salary for each job

//whose female and male salaries are greater than or equal to the minimum
value and

//less than or equal to the maximum value

//If none of the jobs have salaries that fall in the range, an empty string is
returned

//HINT: Use the Job toString() method which will provide the correct
formatting

//Throw an IllegalArgumentException with the message "Invalid min/max value"


if

//the min or max is negative or if max is less than min

public static String searchBySalaryRange(int min, int max, Job[] jobs) {

//Return a String with the name, female salary, and male salary for each job
//whose female salary is less than the given percentage of the male salary

//If none of the jobs have salaries that meet the criteria, an empty string is
returned

//HINT: Use the Job toString() method which will provide the correct
formatting

//Throw an IllegalArgumentException with the message "Invalid percentage


value" if

//the percentage is less than 1 or greater than 100

public static String searchByPercentage(int percentage, Job[] jobs) {

Implement Your Software

● You should read each line of the file, create a Scanner for the line, and set the
delimiter for the line scanner to a comma, as follows:
Scanner scan = new Scanner(line);

scan.useDelimiter(",");

You can then use the line scanner with the usual methods.

● Define and use class constants instead of magic numbers in your program. You
may use the numbers 0, 1, and 100 without defining them as constants. Since
the column titles are used in multiple options, it may also be helpful to create a
constant for the column titles.
● Your program must work for any correctly formatted input file. We will likely use a
different job salary input file than the ones that are provided when grading your
program.
● Do NOT use throws clause(s) in the method headers in your program. Instead,
use try/catch blocks inside of your method(s).
● It may be helpful to have a userInterface method for all input from the user
(e.g., options, job, min, max, percentage). If you have a userInterface method, it
would be the only method that would need a Scanner for the console.
● For min and max read in from the user, if the user enters a value that cannot be
read as the correct type, a negative value, or a maximum value that is less than
the minimum value, output "Invalid value".
● For percentage read in from the user, if the user enters a value that cannot be
read as the correct type or a value that is less than 1 or greater than 100, output
"Invalid value".
● In the getJobList() method, you will be catching any FileNotFoundException's
that occur and throwing an IllegalArgumentException. Here is an example of
how to do this:
try {

in = new Scanner(new File(filename));

catch (FileNotFoundException e) {

throw new IllegalArgumentException("Unable to access input file: " +


filename);

}
● The calling method (most likely the main() method) must catch the
IllegalArgumentException thrown from the getJobList() method, display the
message, and exit. Here is an example of how to do this:
try {
jobs = getJobList(args[0]);
}
catch (IllegalArgumentException e) {
System.out.println(e.getMessage());
System.exit(1);
}

● Use the Job toString() method to create the Strings returned by most of the
methods. You will need to add a newline after the String for each Job. Use the
provide white-box test program to be sure your returned Strings are correctly
formatted as we will be using automated grading to test the methods!
● If you read a whole line after reading a token, you may need to call nextLine() to
get past the newline character first. For example,

String token = console.next();

console.nextLine();

String line = console.nextLine();


● You must store the data from the file into an array of Job objects. Store the data
in the array BEFORE interacting with the user. Here is some sample code that
illustrates how to create and use an array of Job objects followed by the output
produced by the code:
//Create Job array with room for 3 Job objects
Job[] jobs = new Job[3];

//Create and add 3 Job objects to the jobs array


jobs[0] = new Job("Butcher", 34200, 36575);
jobs[1] = new Job("Baker", 29800, 30450);
jobs[2] = new Job("Candlestick maker", 34080, 39896);

//Output each job, female salary, and male salary


for (int i = 0; i < jobs.length; i++) {
System.out.println("Job: " + jobs[i].getJob() + "\tFemale Salary: "
+
jobs[i].getFemaleSalary() + "\tMale Salary: " +
jobs[i].getMaleSalary());
}
OUTPUT:

Job: Butcher Female Salary: 34200 Male Salary: 36575


Job: Baker Female Salary: 29800 Male Salary: 30450
Job: Candlestick maker Female Salary: 34080 Male Salary: 39896

Test Your Software


You will also deliver a suite of black-box test cases and a white-box test program as described
below:

Black-Box Test Plan

Complete the provided black-box test plan - see the directions below about how to
access it. It makes use of the files salaries.csv and three_jobs.csv for some of the test
cases, which are already provided for you. You will add eight test cases. You will also
run all of the test cases and fill in the actual results, which should match the expected
results.
The Black Box Test Plan is provided as a Google Document, which you will submit as a
pdf document when you have completed your testing.

● In order to access the document, you must be logged into your NCSU Google
account
● Open BlackBoxTestPlan_PayGap
● File > Make a copy and save it in My Drive (your Google Drive)
● Rename the file to BlackBoxTestPlan_PayGap
● When you are ready to submit: File > Download as > PDF

White-Box Test Program

Complete the provided white-box test program, PayGapTest.java by adding the


specified 5 valid, non-redundant, specific test cases. Be sure to consider basis path
testing, equivalence classes, and boundary value analysis when designing your test
cases.

For the white-box testing, you will need to create another csv file for testing, especially
for testing the getJobList method. This new csv file should be named my_jobs.csv.

It is OK to have magic numbers in the test program. Be sure to add your name to the
provided @author tag and remove the //TODO comments after you have completed each
item.

● Your implementation should work for an input file with no jobs (empty file).
● For Teaching Staff WBT, the strings produced by your methods need to have the
same contents and formatting.
○ You should run the test program that you were given to make sure the
strings returned by your methods are correct.

Submit Your Software


Before you submit your work, make sure the program:
● behaves as specified in this document. Be sure to consider what results should be
displayed for each major scenario.
● is thoroughly tested.
● satisfies the rubric for this assignment.

Submit via Moodle :


● LivingWage.java
● LivingWageTest.java
● BlackBoxTestPlan_LivingWage.pdf
● my_states.csv
Do not attempt to submit .class files.

You might also like