CSSE 220 – Object-Oriented Software Development

Homework 5

Objectives

Practice creating, documenting, and testing classes based on a given public interface. More graphics and loop practice.

Tasks

  1. Complete the assigned reading for the next session: The remainder of Chapter 6. (See schedule for topics to focus on.) As you read, see if you can answer all of the self-check questions. If there is something you do not understand, make note of it so you can ask about it.
  2. Edit the Big Java Review Wiki on ANGEL, adding answers to three stars worth of the review exercises from Chapter 6. Be sure to carefully follow the instructions for doing this that are posted on the Wiki.
  3. Look over the in-class work that we have done on the Fraction class. If there is anything that you do not understand, come to class prepared to ask about it.
  4. Programming (This part is due on Friday, the day after Session6 at 8:05):
    1. The first programming problem is based on Big Java exercises P3.16 and P3.17.  Your programming work for this assignment must be done in the ImplementingClasses project inside Eclipse. Check out this project. All of the work you are required do is in the three Car files, but I want to describe the other files in the project:

      1. BankAccount is code from Big Java Chapter 3, slightly modified and annotated to show how you would do the same things in Python.

      2. TestBankAccount is a collection of JUnit tests for BankAccount.

      3. The four Face files are the solution to a problem that Curt Clifton assigned in Fall, 2008-09, and provide another example of defining a class and using it to draw objects on the screen.

    2. The Car classes are taken for the book, with a slight modification (to make the window bigger):
      1. (5 points) Add an instance variable to the Car class that indicates the size of the car. I suggest that that number be the height of the body (10 in the current code).  Modify the draw() method so it draws the car at its given size. Modify the constructor so it takes the size as its third argument. Change the second  Car creation so it creates a car twice as big as the first one. The second car should still be drawn in the lower right corner of the window.
      2. (3 points) Add another instance variable that holds the Car's color. Modify the constructor and the drawing code appropriately. In paintComponent(), make the first car blue and the second one red.
      3. (5 points) Add code (nested loops) to paintComponent() to make it draw a triangular fleet of 21 cars, like the one shown here. Car sizes and spacing should be based on the window size, in such a way that the triangle occupies approximately the middle two-thirds of the vertical space in the window (don't worry about how much of the horizontal space it occupies).
      4. Extra credit challenge #1. (2 points).  Write your code in such a way that you can modify paintComponent()'s code by changing a 6 to a 5, and it will draw a triangular fleet of 15 cars (5 rows) that fills approximately the same vertical area of the window.  You should be able to replace the 6 by any reasonably small integer and get a similar effect.
      5. Extra Credit Challenge #2. (2 points).  The cars in the triangular fleet should alternate between green and orange, like what is shown here.
    3. (3 points) Complete Exercise P3.5 from Big Java. Call the class AutoMileage instead of Car, since we already have a Car class for  the previous problem. Also use JUnit to implement the required AutoMileageTest class.

      This exercise doesn’t involve graphics. You’ll just implement and test an AutoMileage class that models fuel economy. The objective is to practice with the “How To: Implement a Class” steps from Session 5.

Turn-in Instructions

We will grade your Wiki contributions using ANGEL. Turn-in your programming work by committing it to your SVN repository. Once again, the programming part of this assignment is due on Friday at 8:05 AM