Colorado State University

Recitation R10 - Methods and Data
Spring 2015

CS160: Foundations in Programming

The goal of this lab is:

Phase 1: Getting Started on P6

The setup for P6 is complex enough that you won't want to do it on your own, so the TA will help you to get started. P6 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 P6 project and associated P6 class in P6.java. Copy the image files and maze files into ../P6, and the Maze.java source file to ../P6/src/.

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

Copy the following code to the main method in P6.java:
		// Create maze
		String fileName = args[0];
		Maze maze = new Maze(fileName);
		System.err.println("Maze name: " + fileName);

		// Get dimensions
		int mazeWidth = maze.getSize();
		int mazeHeight = maze.getSize();
		System.err.println("Maze width: " + mazeWidth);
		System.err.println("Maze height: " + mazeHeight);
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 P6.java you wrote in this lab is just enough to get you started, you will need to do more work to complete the assignment.

Phase 2: Methods and Data

Create a McDonalds project and class, and copy the following code into it.
  1. Create a new project in Eclipse called McDonalds.
  2. Define a new class called McDonalds.java.
  3. Copy the code in McDonalds.java.
  4. Your TA will explain the code that you are given, including the constructor.
  5. All places you must fill in are marked by comments with !!!.
  6. Define the following as private class instance (non-static) data in McDonalds.java:
        private SodaFlavor sodaFlavor;
        private SodaSize sodaSize;
        private Sandwich sandwich;
        private SideOrder side;
        
  7. Define and implement the chooseDrink and chooseMeal methods to set the corresponing instance variables.
  8. Implement the calculateCost method to get the price of a meal, based on the following pricing:
  9. Implement the toString method to print the meal as in the example shown below:
        Drink Flavor: Coke
        Drink Size: Medium
        Sandwich Type: QuarterPounder
        Side Order: OnionRings
        Cost of Order: $6.67
        
  10. Note: You can use the enumeration to print the drink flavor, sandwich type, etc.
  11. Note: You can tell I haven't been to McDonalds in a long time!

Submit your McDonalds.java program to R10 on the Checkin tab for automated grading.

© 2015 CS160 Colorado State University. All Rights Reserved.