Looking for Help with Assignments?
-RUCats has 80 hours of tutoring available online and in-person. Check the tutoring tab in Canvas!
-Instructors and Lead TAs have a combined 10 hours of Office Hours, open to all sections. See times/locations here.
-Piazza (found in the Canvas sidebar) provides fast support from Course Staff and other Students. Be sure to search to see if someone has asked a similar question!
-If you need a computer to complete work on, iLab machines can be found in the CSL (Hill 252) and surrounding rooms.
Sort Solver - 10 Course Points
The purpose of this assignment is to practice using the Java Debugger, to investigate elementary sorts as they are randomly chosen to sort lines of an input file.
Make sure you install all required VSCode extensions and remove any unnecessary ones before starting. View the Course FAQ page for more info
You can download and submit the project files via Autolab.
What is Debugging?
Writing code is prone to bugs (mistakes), and when bugs do occur we need an efficient way to pinpoint where they are coming from. Often, when programs have mistakes they show a Compiler Error (red squiggily underline on VSCode), or throw an Exception, which is a Runtime Error, and crash the program. These both tell you their direct cause, allowing you to fix them.- Compiler error: VSCode shows you a red squiggly underline. Basically like a grammar/spelling issue.
- Runtime error: Java shows you the call stack and which lines generated the exception. This is an error which signals an issue with the program while it’s running.
Using the Java Debugger
As with the rest of the course, we will be working within VSCode for this Lab. Make sure you’ve installed all required extensions and removed any unnecessary ones, as stated on our Course FAQ page. So far, you have most likely been running your programs using either the commands line (with compile commands), or using the VSCode run button. Now, you can use the drop down menu on the Run Button and select “Debug Java” to run the program in Debug mode instead.

Breakpoints
Breakpoints allow you to define certain lines for the program to pause running at, while running in debug mode. This is extremely useful, as it allows you to investigate specific edge cases, or specific parts of the bugged code. You can place a breakpoint by clicking to the left of the line number you want to pause at. Breakpoints are represented by a red circle.







Debugger Toolbar
After the program pauses at a breakpoint, we want to be able to control it from there, and execute any number of lines, or continue running until the end. To do this, we can use the Debugger Toolbar. The debugger toolbar appears when running a program (even in non-debug mode). For any program that is actively running (for example, when you have the Driver open), the toolbar will appear as follows:





Memory Viewer
Also while the program is paused, you can use the Memory Viewer to inspect variable values. The memory viewer can be accessed through the left sidebar, under the “Run and Debug Menu”




Debug Console
The final tool you will need to debug is the Debug Console. The Debug Console is a special terminal, which can be accessed with Ctrl + Shift + Y (for Mac, use Command instead of Ctrl). The debug console allows you to write and run singular lines of code, and print their output. For example, you can simply enter primitive values, and it will print those values back to you.

Overview
To complete this Lab, you will not need to write ANY code. Instead, you will run the Driver.java class and use it with the debugger to generate your submitted file.- The Driver class asks for your netID, then immediately starts sorting the lines of the input file. Enter your correct netID (ex: abc123, not your 9-digit RUID).
- For each line of the file, a random sort is chosen (based on your netID)
- After sorting the file, you will be asked a series of random questions about your sorting simulation. Your netID + answers will print to an answers.out file.
- This “answers.out” file is the one you submit.
- Similarly to Lab 3, this is a sort of “scavenger hunt” using the debugger. Your job is to find or track specific values, to answer your given questions
Provided Classes
You are provided a number of supporting classes which comprise the game. The sorting package contains the simulation itself. Question.java contains the possible questions. Sorts.java contains four random sorts (and their required helper methods), anonymously labeled. These will be randomly called by SortSolver.java. SortSolver.java is where the simulation happens, and the input file is read & randomly sorted. This gets called by the Driver. Driver.java is the file you run. It contains a small window which allows you to enter your netID, and run the simulation. You can then input your answers into the driver, and click a button to print your answers.out file. StdIn.java, StdOut.java, and StdRandom.java are used for input, output, and random generation respectively. Do not modify or remove any of these classes.Directions
You MUST use your own NetID when submitting answers.out, or you will receive a zero on the Lab.- DO NOT add new import statements.
- DO NOT add any new class attributes
- DO NOT change any of the method’s signatures.
- DO NOT modify the given constructor.
- DO NOT modify any code related to game behavior.
- Modifying program behavior may cause you to find different answers than Autolab.
- You may mainly add if-statements to check logic for print statements. Do not use break, continue, return, or other similar keywords.
To Run: Run in Debug Mode through VSCode, ensuring you open the correct innermost SortSolver directory.

Driver
The Driver class will prompt you for your netID (abc123 form NOT your 9-digit RUID). After you enter it, the simulation will automatically run. The sorts will instantly simulate, and end. After this, the driver will ask you a series of random questions about the program. You must use the debugger to find the answers to these questions, then enter them in the driver. NOTE: You must use the “Continue” or “Step Out” buttons to continue past ALL breakpoints after starting the game with your netID. While you are paused at any breakpoint, you will not be able to interact with the Driver. You will not be able to exit out of the Driver while at a break point, use the red square button in the debug toolbar to exit out instead. After all questions are answered, the driver will print them to an “answers.out” file in your project directory. This is the file you will submit. Make sure to save your answers somewhere when you rerun, so they don’t get overwritten.Question Help
Question 1: Which sort number is #?- Free Question:
- 1: Insertion Sort
- 2: Selection Sort
- 3: Merge Sort
- 4: Quick Sort
- Look in Sorts.java. Only some sorts have helper methods, but some may have one or more.
- Look in SortSolver.java. Set a breakpoint in the constructor, where the sort # methods are called, then run in debug mode. Use continue and count how many times you hit the breakpoint.
- Look in SortSolver.java constructor. Set a breakpoint on the four sort method calls. Run, and see which breakpoint gets hit first.
- Look in SortSolver.java constructor. Set a breakpoint on the four sort method calls. Run, and use the continue button to see which breakpoint gets hit on the corresponding line number.
- This question is asking about a specific line number of the input file (there are 15 lines total). If your line number is 7, you will have to hit continue six times after pausing at the first sort.
Before submission
DO NOT MODIFY THE answers.out FILE. You MUST print this file using the Driver.
You MUST use your own NetID when running the simulation, or you will receive a zero on the lab.
Collaboration policy. Read our collaboration policy on our course syllabus.
Submitting the assignment. Submit your answers.out file separately via the web submission system called Autolab.
Getting help
If anything is unclear, don’t hesitate to drop by office hours or post a question on Piazza.
- Find instructors and Lead TA office hours here
- Find tutors office hours on Canvas -> Tutoring
- In addition to office hours we have the Coding and Social Lounge (CSL) , a community space staffed with ilab assistants which are undergraduate students further along the CS major to answer questions.
By Colin Sullivan