UW Home     CSE Home   Announcements    Message Board    Contact Info 

 
 

CSE 142 Wi04 Project 1 - Ski Resorts and the Skiers who use them

Due: Monday, February 9 at 9:00 pm. No late assignments will be accepted.

You should work with your assigned partner on this project using the pair-programming style discussed in class. While you certainly can think about the project and try out ideas on your own, it works best if the actual code you write in the final project is written by both of you sitting at a computer and trading off the keyboard regularly.

You and your partner should turn in a single set of files under one person's name with the other person's information on the turnin form. After the project code is done, each of you will write an individual report describing the project. Details about that will be provided later.

Grading: You and your partner will receive the same scores for the programming part of the project. Programs are evaluated both for how well the code works (code operation) and how well it is written (code quality and readability). Be sure to include appropriate JavaDoc and other comments in your code, use meaningful names, indent sensibly, provide toString() methods where appropriate, and so forth.

Keep track of the major design decisions, algorithms, and tests you perform to verify that your code is working. You will be asked to discuss these issues in your final report.

Overview

For this project you will develop several classes to implement the fundamental objects needed to simulate a ski resort and the trails and lifts it includes.

The basic relationships between objects are shown in this diagram.


(click here to open the image on a separate page if it is too wide for your browser.)

The overall operation of the program is as follows.

A SkiWeekend object creates a SkiResort and fills in the details of how the resort is organized by building Lifts and Trails and adding them to the SkiResort. The SkiWeekend object has two methods saturday and sunday that create a number of Skier objects, and then use the methods of the SkiResort to move them up and down the slopes. The Skiers can have varying degrees of skill and the Trails can have varying degrees of difficulty, so problems may ensue causing a Skier to crash. The SkiWeekend prints messages as the events take place, recording who went on which trail with what result.

For example, a simple SkiWeekend might produce the following output:

    >SkiWeekend event = new SkiWeekend();
    >event.sunday()
    This event is taking place at Party Summit
    Sending skier Tom [b,0/0] out on trail Golf [difficulty: 0, lift: rope]
    Tom is swooping down a trail.
    Result: Tom [b,0/1]
    Sending skier Tom [b,0/1] out on trail Roller Derby [difficulty: 4, lift: chair]
    Tom is swooping down a trail.
    Tom crashed!
    Result: Tom [b,1/2]
    Sending skier Mary [a,0/0] out on trail Roller Derby [difficulty: 4, lift: chair]
    Mary is swooping down a trail.
    Result: Mary [a,0/1]
    >

What to Do

The steps to accomplish this project include the following.

1. Download the project 1 zip file (r1). It source file Skier.java, and the javadoc specifications for all the classes. (Rev 1 changes the specification for SkiResort.java so that the class, the constructor and all methods are public.) Unzip the file to the disk drive where you will be doing the work.

2. Take some time to look at the javadoc in the specifications folder (start with index.html). These files describe each of the classes and methods in this project.

3. Open the Skier.java source file with DrJava and look at the code. Notice the private instance variables at the beginning of the file. There are several get and set methods (accessors/mutators) and a toString method.

4. Consider the drawing on the previous page. The SkiWeekend stores a reference to the SkiResort object where the events of the weekend will take place. The SkiResort object stores references to the Trails at the resort. Each Trail stores one reference to the Lift that is used to get to the top of the Trail. Although it is tempting to dive in and try to write SkiWeekend first, it is hard to do it that way because none of the classes that it needs are defined yet. So it is best to start by understanding, designing, writing and testing the Lift class, then the Trail class, then the SkiResort, then finally the SkiWeekend.

5. The Lift class is pretty simple. The constructor takes a String description of the lift (values like "rope" or "chair" are expected). The constructor remembers the description for later use by storing it in a String instance variable. The zoom method is used to move a Skier object to the top of the Trail that this Lift serves. The zoom method calls the setAtTop method on the given Skier object in order to indicate that the move has taken place. The toString method just returns a String that contains what little information there is about this Lift, namely the description.

6. The Trail class is a little more complex. The constructor takes a name, a difficulty level, and a Lift object and stores them in instance variables for later use. There are a couple of accessor methods and a toString method. There are also some methods that other objects can call in order to zoom a Skier up to the top of the Trail, swoop a Skier down to the bottom of a Trail, or both (a roundTrip). Zooming to the top isn't hard, you just check to see if the Skier is already at the top (using the isAtTop method), and then use the Lift method zoom to move the Skier up. Swooping down requires a little more work because you need to determine if the Skier can actually deal with the Trail difficulty. Read the javadoc carefully to understand how to set the various counters and determine if there is a crash, and what to do when one occurs.

7. The SkiResort class holds information about the resort (name, advertising) and the three Trails that are available for skiing. The constructor takes a list of parameters including all these elements, and stores them in instance variables for later use. There are some getters and setters and a toString method. The getEasyTrail and getHardTrail use a few "if" statements to determine which of the three Trails is easiest or hardest by comparing their difficulty levels and returning the Trail with the lowest or highest value.

8. The SkiWeekend class actually runs an event by creating a SkiResort and several Skiers and then running them up and down the mountain sides, crashing right and left. The SkiWeekend constructor does not take any arguments. It creates several Lifts and Trails, then creates a SkiResort using those Trails. The new SkiResort object is stored in an instance variable for use in the two methods, saturday() and sunday(). The two methods create as many new Skiers as you like, and then get easy and hard Trails from the SkiResort and send the Skiers out on the Trails. These methods should use System.out.println to print information about events as they occur in each method.

9. Implement the SkiWeekend constructor and the methods saturday and sunday with enough activities to show that your methods are working correctly. Use the saturday method to do basic testing of your classes. You should do at least the following:

a. In the constructor, create a SkiResort that has trails with different names and different levels of difficulty so that it will be clear which trail is the easiest and which trail is the hardest.

b. In saturday() use System.out.println to show that the SkiResort methods getName, getTagline, setTagline work correctly.

c. In saturday() use System.out.println to show that the SkiResort methods getEasyTrail and getHardTrail work correctly (ie, they select and return the correct Trail objects).

d. In saturday() use getEasyTrail or getHardTrail to get a Trail object. Then use System.out.println to show that the Trail methods getName, getDifficulty, and toString work correctly.

10. Use the sunday() method to implement a skiing holiday. Use your imagination in creating the Skiers and directing them to zoom and swoop on the trails of your resort.

a. In sunday(), create several Skiers with varying skill levels.

b. In sunday(), get the easy and hard trails from the SkiResort. Use the Trail methods zoomUp, swoopDown, and roundTrip to move your Skiers around. Make sure that you mix the Skiers and the Trail difficulty levels so that some of the Skiers make it down and some crash. Use System.out.println to display what the Skiers are doing, and verify that the swoop counts and crash counts are being updated correctly.

What to Turn In

Use this online turnin form to turn in the Java source files that make up your project. You can either select the files individually, or create an archive containing your files (zip or other common archive file format) and turn that in. Remember that you should only turn in one project for both you and your partner. (However, you can turn the project in multiple times as you add features. We will grade the last version that you turn in.