CS302 Lecture 5 Home Page
Announcements | Course Information | Assignments | Examples | Review

Instructor: Lisa Torrey
Office: 1306 Computer Sciences
Phone: 262-6601
Email: ltorrey (at) cs.wisc.edu


Class times: MWF 2:25 - 3:15 pm
Classroom: 342 Noland
Office hours: 3:30-4:30 Mon, 11-12 Thurs, and by appointment
Lab hours: 2-4pm Thurs in CS 1370

ANNOUNCEMENTS

  • The final exam is on Sunday 12/14 at 10am in 2080 Grainger.

COURSE INFORMATION

  • This is the Lecture 5 homepage. The overall CS302 website contains resources for all CS302 students.

  • The Lecture 5 information sheet talks about course textbooks, types of coursework, exams, grading, policies, and computer labs.

  • There are three copies of the course textbook on reserve at Wendt Library.

  • Here are the instructions that tell you how to register for CodeLab.

  • If you decide that you want to work with one other student on a programming assignment, review the Collaboration policy page and print out a permission form to get signed by your instructor. You must do this before you start working together.

  • Note on course drop deadlines: 9/10 is the last day to drop a class without getting a DR on your transcript, 10/31 is the last day to drop at all if you're an undergraduate, and 11/21 is the last day to drop if you're a grad student.

ASSIGNMENTS

This area will show all your coursework on a week-by-week basis. (Weeks will be added on as the semester goes by.) You are responsible for checking here to find out about readings, CodeLabs, assignments, and exams. Please remember that no late work will be accepted!

Week 1: 9/2 - 9/5
 Readings  Chapter 0, Chapter 1, and the course websites
 Assignments  1. Get the course textbook.
 2. Register for CodeLab.
Week 2: 9/8 - 9/12
 Readings  Chapter 2
 Assignments  1. Go to CS 1370 for class on Wednesday 9/10.
Week 3: 9/15 - 9/19
 Readings  Chapter 3, sections 1-8
 Assignments  1. Assignment 0: done
 2. CodeLab: Chapter 2 done
Week 4: 9/22 - 9/26
 Readings  Chapter 4, sections 1-4
 Assignments  1. CodeLab: Chapter 3 done
Week 5: 9/29 - 10/03
 Readings  Chapter 4, sections 5-7
 Assignments  1. Assignment 1: done
 2. CodeLab: Chapter 4 done
Week 6: 10/6 - 10/10
 Readings  Chapter 5, sections 1-6
 Assignments  1. MIDTERM 1: Tuesday, 10/7, from 7:15 PM - 9:15 PM
Week 7: 10/13 - 10/17
 Readings  Chapter 6, sections 1-3, 6, 7
 Assignments  1. Assignment 2: done
 2. Assignment 3 Design: done
 3. CodeLab: Chapter 5 done
Week 8: 10/20 - 10/24
 Readings  Chapter 9, sections 1-2, 5-6
 Webpage on Iterators
 Assignments  1. Assignment 3 Design: done
 3. CodeLab: Techniques section done
Week 9: 10/27 - 10/31
 Readings  Optional: chapter 7
 Assignments  1. Assignment 3 Code: done
 2. CodeLab: Chapter 6 done
Week 10: 11/3 - 11/7
 Readings  Chapter 8, sections 1-5
 Webpage on Java Exceptions (example file EchoSquared.java)
 Assignments  1. Assignment 4: due on Monday 11/17 by 2:25pm
 2. CodeLab: Chapter 9 done
Week 11: 11/10 - 11/14
 Readings  Webpage on Java IO
 Example files FileEcho.java and FileIO.java
 Assignments  1. MIDTERM 2: Tuesday, 11/11, from 7:15 PM - 9:15 PM
 2. Assignment 4: done
Week 12: 11/17 - 11/21
 Readings  Chapter 10, sections 1-6
 Assignments  1. Assignment 4: done
 2. Assignment 5 design: done
Week 13: 11/24 - 11/26
 Readings  Chapter 13, sections 1-6
 Assignments  1. Assignment 5 design: done
Week 14: 12/1 - 12/5
 Readings  Optional: skim chapters 11 and 15
 Assignments  
Week 15: 12/8 - 12/12
 Readings  Review for exam
 Assignments  1. Assignment 5 code: done
Final Exam: 12/14
 Exam  10:05am-12:05pm on Sunday 12/14


Assignment 0

This assignment, due on Friday 9/19 by 4:00pm, has two parts. Part one will introduce you to CodeWarrior, and part two will give you practice designing systems with objects. You don't have to write any code of your own for this assignment, and therefore no formal collaboration is allowed. (This means that you can discuss the written part informally with each other, but each person needs to write his or her own individual answers.)
  • Part one: CodeWarrior Tutorial. Begun in class on Wednesday 9/10, and completed on your own. Follow the instructions in the tutorial to hand in four Java files electronically by 4:00pm on the due date. (Extended due date: 8:00am on Monday 9/22.)
  • Part two: Design Exercise. Answer four questions about how to design a program that models the city bus system. Turn in your answers on paper (either hand-written or typed is fine) either in class or at my office (1306 CS) by 4:00pm on the due date. Since the instructions for this part are a little confusing, here are some answers to frequently asked questions about the design exercise.(No extended due date for this part.)
Here are some other things you should read:

Assignment 1

This assignment requires you to write a main class, which you will hand in electronically, and to answer some written questions. In order to avoid having people miss class to finish the assignment, both parts are due by 2:25pm on Friday 10/3, even though the official deadline is 4pm. Get to the assignment description through the Assignments page on the general course website. Here are some notes (these may change periodically to answer people's questions, so check here if you have a question):

  • Start by making a new project in CodeWarrior, as you've done before, and choose the A1 stationery instead of A0. If you do this, your project will automatically have all the classes you need in the Classes folder (including Plane and FlightSim), automatically have FlightSimMain.java in the Sources folder, and automatically have the Java Target set to FlightSimMain. All you will need to do is write your code in the FlightSimMain.java file, and then compile and run it to debug your code.

  • Remember to follow the Commenting and Style rules (listed below). You will get points taken off this time if you don't.

  • Please do NOT use JOptionPane for input and output. Use a BufferedReader with System.in for input, and use System.out for output. (This will make grading a whole lot easier.)

  • Remember to use the electronic handin program to hand in your FlightSimMain.java file! The instructions for the handin program are here.
And here are some resources:

Assignment 2

This assignment requires you to write main and instantiable classes, and to answer some questions, all of which you will hand in electronically. Both parts are due by 4:00pm on Tuesday 10/14. Get to the assignment description through the Assignments page on the general course website.

Here are some notes (check here periodically):

  • Start by making a new project in CodeWarrior and choosing the A2 stationery.

  • A lot of the program is already done for you. You're supposed to write two instantiable classes, Bumper and BumperCar, and fill in a piece of a third instantiable class, BCDerby. You are not writing a main class for this assignment.

  • For the driveNorth(), driveEast(), etc. methods in BumperCar, you need to change the Location object of the BumperCar. (Location is pretty much like a Point.) Look at the API for the Location class to find a mutator method. Remember that (0,0) is at the upper left corner of the arena, so :
    • East is when x increases (right)
    • West is when x decreases (left)
    • South is when y increases (down)
    • North is when y decreases (up)

  • If you get the above methods wrong, two things might happen: everything stops moving in the arena and the console says "OutofBoundsException", or the cars get stuck going back and forth along one side of the arena. Make sure you do enough testing to be sure that these things aren't happening.

  • All directions (east, west, south, north) are represented by class constants in the BumperCarArena class (their values are the ints 0, 1, 2, 3).

  • In the BCDerby class, you're supposed to give the cars random directions. Basically, this means you have to generate a random int between 0 and 3. Also in the BCDerby class, you're supposed to give bumpers and cars random locations. This means you have to generate a random int x between 0 and BumperCarArena.FIELD_WIDTH, and a random int y between 0 and BumperCarArena.FIELD_HEIGHT, and create a Location object with them. Hint: there's a method in the Math class that will generate a random double between 0 and 1.

  • Notice that you have to generate at least 15 random Locations and at least 5 random directions overall. These are things you need to do repeatedly, in exactly the same way each time. Remember what we always say about repeated code, and make sure you do this efficiently (i.e., do not repeat a block of code 15 times in BCDerby.java!).
And here are some resources:

Assignment 3

This assignment requires you to write a thorough design for a program, which you will hand in on Wednesday 10/22 in class, and then to write the code by Friday 10/31 at 2:25pm. Get to the assignment description through the Assignments page on the general course website.

Here are some notes (check here periodically):

  • When you create your AntFarmContainer object, you'll get some error about the Windows registry. Ignore that error; it has to do with the graphics part. Note that your first print statement after that (probably one asking about colony size) might end up printing before or inside that error, so you might have to hunt for it.

  • It seems that the AntQueen objects don't show up right away, even when you've correctly added them to the AntFarmContainer. They should show up after you do one move operation, though.

  • Handling bad input: handle bad ranges, but don't worry about bad types. For example, if you're inputting an int, deal with integers that are too high or too low, but don't worry about what happens if they enter a double.

  • The isWall method (which is given to you) lets you ask your AntFarmContainer object whether a particular location contains a wall or not. It seems to have a bug in it: if you pass it a location that is outside the bounds of the farm, you'll get an error called an ArrayOutOfBoundsException. So when you create an ant's new location, if you use isWall to make sure it's legal, make sure you check that it's in bounds first.

  • Note that the Location class has a useful equals method.

  • The food should all be at in the top row (that's where y=0) and the queens should all be at the bottom row (that's where y=AntFarmContainer.CONTAINER_HEIGHT-1).

  • When an ant is carrying food, the food should change location so that it's always on top of the ant-- until it reaches the ant's queen, at which point it should disappear and a new food piece should appear randomly at the top. (So an ant needs to somehow keep track of the food piece it's carrying, and move the food whenever it moves itself.)

  • Ants, food, and queens can be on top of each other at any time, and it's fine. (If it looks like you have too few food pieces, it might just be that two are in the same spot.)
The usual resources:

Assignment 4

This assignment requires you to write a full program, without any classes provided for you, that implements a simple type of encryption. Get to the assignment description through the Assignments page on the general course website.

Here are some notes (check here periodically):

  • Some of you found that you did a lot of extra work on A3 because you started programming without paying much attention to your design. You don't have to hand in a design this time, but do one for yourself anyway. Plan what data members your two instantiable classes will have, and which methods will handle which exceptions.

  • Remember that characters can be treated just like integers.

  • Use the webpages on Java IO and Java Exceptions, and feel free to copy and paste from the examples.

  • HOWEVER, the examples all use BufferedReaders wrapped around FileReaders so that you can read a line at a time, and you don't want that since you're translating on a character-by-character basis. You should probably just have a FileReader and use its read() method, which gets one character (actually an integer) at a time.
The usual resources:

Assignment 5

This is a BIG assignment that has you design and write a computer game called Alien Invaders. The design, which will be similar to your A3 design (but better!), is due in class on Wednesday 11/26. The code is due on Friday 12/12, which is the last day of classes. Get to the assignment description through the Assignments page on the general course website.

Here are some notes (check here periodically):

  • If you start early on the coding, you might be able to avoid the lab rush that happens during the last week of classes...
The usual resources:
EXAMPLES

Note: Indentation in these files may or may not look right when you look at them online or download them. It seems to depend on the browser and the operating system. If you're in doubt, look at the book for the correct indentation style. It is important that you follow that style, because it makes your code much easier to read. (It's also part of your "style" grade for any assignment.)
REVIEW
Last Updated: 12/13/03