This lab is adapted from this assignment in Evan Peck’s list of Ethical CS modules for CS 1.
For this lab, you will use IntelliJ IDEA to write and run your code. This IDE (integrated development environment) is a place for you to write your code and comes with great tools to make your life easier! You are welcome to use other IDEs if you are more comfortable with them (such as VS Code), however you may have to do some googling as my setup instructions are always for IntelliJ.
Download IntelliJ for your proper operating system here.
Install Java if you have not yet here.
Retrieve the files provided for this lab using the Github Classroom link. You can clone the project however you like (command line, Desktop application, etc). If you'd like IntelliJ to be connected to Github, follow the instructions here.
Configuring your Base Code: To setup lab 1 part 1, open the assignment in IntelliJ.
Open IntelliJ and select 'open'. A finder / file explorer window should appear. Navigate to the 203Lab1_Part1
repo and open it.
Checking Settings: Select File->project structure->project and make sure the SDK is selected and matches the version of Java you installed.
In the image above, the No SDK
should be changed to the version of Java you installed.
Next, look at the project structure on the left hand side. You should see Part 1 with a 'src' folder nested inside:
We need to check the src folders are labeled properly so IntelliJ knows how to compile and run your code. Right click on src, go to 'Mark Directory as...' and make sure it is marked as the sources root. (If there is an option for 'unmark as sources root' do not select it...this confirms your src folder is marked properly).
Important: For this lab, we will be using JUnit to help us test the correctness of our code. To have IntelliJ add it to your project for you, open the TestCases.java
file in the 'src' folder. Right click on the red @Test
on line 11 and select, 'Show Context Actions'.
JUnit
to the classpath if that option pops up.
If selecting 'showContextActions' doesn't give you the option to 'add Junit
to classpath', but does say 'Add Library to Classpath', select that instead. You should then have the option to select Junit 5.4
(or another 5 version).
If the option to add JUnit doesn't appear, you can add it manually - instructions can be found at jetbrains.com. If you are not using IntelliJ you will want to look up how to setup JUnit on your other IDE.
Finally, once JUnit is added, you can right click on each red assert statement and select: 'Show Context Actions' -> 'import static method ...' and select the one for JUnit 5.4 (or another 5 version).
Aside: What’s JUnit? JUnit lets us make assertions about what our code should do. You can think of them as statements of expectations—for example, if we wrote a program to do addition, then we can expect that 2 + 2 = 4
and that -1 + 3 = 2
. As a project grows over time, these assertions (“tests”) grow along with it, giving us a “safety net” of checks that can assure us that our program is doing what we expect.
Running Tests: Finally, to finish setup let's make sure your tests can run. If everything is setup properly, green play buttons should appear by the line number marking the line that says public class TestCases
. Press the play buttons and select to run the test cases. You should be failing most of them (after you fill in the code for part 1 they should be passing!). Now you can get started on the lab (part 2 setup will follow the same steps).
This lab allows you to practice Java syntax related to collections and control (Part 1) and basic class structure and methods (Part 2). Those already familiar with Java should finish the lab and then offer to help others. An overview of the assignment and specific steps are given below.
Imagine you are working for Moogle, a well-known tech company that receives tens of thousands of job applications from graduating seniors every year. Since the company receives too many job applications for the Human Resources Department (HR) to individually assess in a reasonable amount of time, you are asked to create a program that algorithmically analyzes applications and selects the ones most worth passing onto HR. Your job is to build an algorithm that helps determine the order which job applicants will be called in for an interview. This is a real scenario playing out every day and will likely impact you as an applicant someday.
To make it easier for their algorithms to process, Moogle designs their application forms to get some numerical data about their applicants’ education. Applicants must enter the grades they receive from their 5 core CS courses, as well as their overall non-CS GPA at the university. For your convenience, this will be stored in a Java array or list that you can access. For example, a student who received the following scores…
…would result in the following list:
100, 95, 89, 91, 75, 83] [
That is, you can assume that index 0 is always Intro to CS, 1 is always Data Structures, and so on.
In the provided part1
subdirectory, edit each of the given files to complete the implementations and tests. Comments in each file will direct the edits that you are expected to make. Look up any classes you don’t know how to use (such as Map) in the Java Standard Library.
It is recommended that you use the order of the unit tests in TestCases.java
as a guide for the order in which to complete the methods. This order corresponds to the increasing complexity of the methods. A good process to follow would be to read the first group of tests in TestCases.java
, which happen to be testAnalyzeApplicant
, testAnalyzeApplicant2
, and testAnalyzeApplicant3
. Edit the corresponding class and method to make the code pass the tests (starting with the class SimpleIf
and the method analyzeApplicant
). Run the tests to make sure they now pass. Add the required additional test case. Run the tests again. Then move on to the next group.
The output for a failed test is incredibly verbose (a stack trace is printed). You can see the specific error at the numbered line above each stack trace. As you fix the code one file at a time, re-run the code to make sure that the number of errors is decreasing!
Setup: copy the file SimpleIf.java
from your part 1 folder to your part 2 folder. Once you have done that, you can set up your part 2 similarly to how you did part 1 in IntelliJ.
For this part, you will implement a simple class (named Applicant
) representing a job applicant and their resume. Do this by creating a file named Applicant.java
and put in all the code specified below. This class must support the following operations (including a single constructor).
public Applicant(String name, List<CourseGrade> grades)
— Constructor.public String getName()
— Returns the applicant’s name.public List<CourseGrade> getGrades()
— Returns the applicant’s list of scores.public CourseGrade getGradeFor(String course)
— Returns the CourseGrade that was asked for. The course
parameter can be one of the courses as defined here. That is, getGradeFor("Intro to CS")
will return the CourseGrade
at index 0, getGradeFor("DataStructures")
will return the CourseGrade
at index 1, and so on.Once this class is created, look at the TestCases.java
file in the part2
directory—complete the test cases or add new ones as appropriate.
Creating your own filter
You’ve now written and seen the effect of 3 different analyses. It’s time to create your own.
You will decide what you think is the most fair way to filter applications. You shouldn’t just use what we’ve created so far. Come up with something better. Be sure to think about who you would be excluding based on your filter and if this is ethical.
So far, our Applicant
only has a name and course grades. Do you want to take more information into account while deciding whether or not to accept the applicant? Add the appropriate fields to the Applicant
class.
Then, in the SimpleIf
class, create a new function: * public static boolean analyzeApplicant2(Applicant applicant)
And implement your new filtering mechanism. In a JavaDoc comment for analyzeApplicant2
, explain in plain English your rationale for this new applicant filter.
Finally, write tests in TestCases.java
to ensure that your new filter is working correctly.
Important note: Make sure when you update your Applicant
class, that you overload the constructor. Make sure you still have a constructor with just the following parameters and then add another constructor if needed: public Applicant(String name, List<CourseGrade> grades)
Both part 1 and part 2 are due by 11:59pm on the due date listed on canvas.
Your part 1 and some of part 2 will be tested via autograder. Submit via git. Your Part 2 filter code will be graded by hand.
Code submitted after the deadline will not be counted for full credit. If it is turned in a day late, you will have the 1 day late scaling applied. Autograde will run on the late day as well.
If you submit a lab more than 1 day late, there is no autograder set up to run - you will need to push your code and then email or piazza post me to inform me you'd like to submit the late work.
Autograder will run every 4 hours (starting at midnight) until 8pm, when it will run every hour. You can check your results by looking at the 'issues' tab on your project repo.