Colorado State University

Recitation R4 - Java: Sets and Functions
Summer 2016

CS160: Foundations in Programming


In this recitation we will:

Phase 1: Getting Started on P5

The setup for P5 is complex enough that you won't want to do it on your own, so the TA will help you to get started. P5 requires an additional Java file for the graphical user interface, in addition to several image and maze files. As usual, use Eclipse to create a p5 project and associated P5 class in Copy the image files and maze files into ../P5, and the source file to ../P5/src/.

A tree view of the P5 directory should look like this:
├── Chihiro.png
├── Haku.png
├── Yubaba.png
├── Success.png
├── Maze1.txt
├── Maze2.txt
├── Maze3.txt
├── Maze4.txt
├── Maze5.txt
├── bin/
└── src/

Copy the following code to the main method in

public class P5 {

	// Class variables
	public static Maze maze;
	public static int mazeWidth;
	public static int mazeHeight;

	public static void main(String[] args) {

		// Create maze
		String fileName = args[0];
		System.err.println("Maze name: " + fileName);

		// Get dimensions
		maze = new Maze(fileName);
		mazeWidth = maze.getWidth();
		mazeHeight = maze.getHeight();
		System.err.println("Maze width: " + mazeWidth);
		System.err.println("Maze height: " + mazeHeight);

		// Add code to move around maze

Once all files are in place, follow these steps:
  1. Modify the run configuration to pass Maze1.txt to the program.
  2. Test your program by calling maze.moveRight() to make the student move right one square.
  3. The maze object has similar methods to move down, left, and up, try calling each of them.
Note: The initial version of you wrote in this lab is just enough to get you started, you will need to do more work to complete the assignment.

Practice Problems

Sets and Functions

Sets and Functions Worksheet

Once you have have set up P5, completed the Hackerrank activities, and finished the worksheet you are finished. Recitation will be graded via the Hackerrank problems and attendance.

© 2016 CS160 Colorado State University. All Rights Reserved.