BallWorlds

  1. CSSE 120 - Fundamentals of Software Development 1
  2. Rose-Hulman Institute of Technology
  3. Computer Science & Software Engineering

Designing and implementing multiple classes: inheritance and interfaces

Part 3: Dud

Learning objectives

After completing all the parts of this lab, you should ...

... Be able to Explain the following concepts:

... Be able to Do the following:

Items in bold above are learning objectives for this part of the lab.

Instructions:

Pair Programming

Lab report

Time limit

Getting Started

What you should learn

What you should do

Getting started

  1. Skim through this document. Then return to this point.
  2. Open your BallWorlds, Part 3 report (on Angel)
  3. Question: Who is your partner for this report?
  4. Question: About how many minutes do you think it will take you to complete Part 3 of BallWorlds?
  5. Question: What time is it now? (Later we will ask you how long you spent on Part 3 of BallWorlds.)

    Reminder: Each time that you see a question in this document prefaced by

    "Question: yada yada ..."
    put your answer in your BallWorlds report (on Angel) at that time.
  6. Close all your open projects, so that you can focus on the project that you are about to import.
  7. Inside Eclipse: Switch to the SVN Repository Exploring perspective.
  8. Right-click in the SVN Repository view and select New ~ Repository Location...
  9. In the Add SVN Repository dialog box, enter:
  10. Eclipse should bring up this location in the SVN Repository view. If not, get help now.
  11. Right-click on BallWorlds and select Check Out As Project .
  12. To work on the project, go back to the Java perspective (choose Window ~ Open perspective ~ Java).
  13. Compile and run BallWorlds. You should see no error messages, except that no Balls can be created yet by the BallButtons.

Studying the UML

What you should learn

Resources

Reading a UML class diagram should be familiar territory to you by now.

If not,

What you should do

Understanding Dud from BallWorld's UML class diagram

  1. Briefly review the specifications of the BallWorlds project.
  2. Briefly review the UML class diagram for the BallWorlds project.

    Note its color-coding:

    • The six yellow classes are the six classes that you will eventually implement.
    • Those yellow classes extend the abstract Ball class, which in turn implements the three blue interfaces. Thus, your classes must implement those three blue interfaces.
    • The Ball class, and hence each of your classes which extends Ball, have the grey BallEnvironment object.
    • Some of your Ball classes may want to refer to instances of the green classes.

    So the only part of the UML class diagram relevant to what you will implement are the colored items listed above.

  3. Question: According to the above UML class diagram, what class must a Dud extend?
  4. Question: According to the above UML class diagram, what three interfaces must a Dud implement?
  5. Question: According to the above UML class diagram, how many methods must you put in any class that implements the Animate interface? What are the names of those methods?
  6. Question: According to the above UML class diagram, how many methods must you put in any class that implements the Drawable interface? What are the names of those methods?
  7. Question: According to the above UML class diagram, how many methods must you put in any class that implements the Relocatable interface? What are the names of those methods?
  8. A note in BallWorld's UML class diagram indicates that every Ball must have a constructor that:

    Question: Looking at the above UML class diagram, what is the only object that a Ball has? What method does that object have that will be helpful to a Ball?

If any of the above questions are still confusing to you, ask your instructor or an assistant for help NOW -- you will be unable to complete the rest of this exercise without understanding the answers to the above questions.

Thinking Before Doing

What you should learn

Resources

Reading a method's signature should be familiar territory to you by now, but here is an example as a reminder. Consider the following signatures of methods in the Component class:

    Component getComponentAt(int x, int y)
    boolean contains(Point p)

The first signature says that the getComponentAt method takes two int variables and returns a Component.

The second signature says that the contains method takes a Point object and returns a boolean value (i.e., either true or false).

Make notes to yourself as needed about any of the above that is unfamiliar to you.


Constructing a new object should be familiar territory to you by now, but here is an example as a reminder. Consider the following two expressions:

    new JButton("Eat me")
    new Point2D.Double(45.3, 22.2)

The first expression creates a new JButton whose label is the given String.

The second expression creates a new Point2D.Double object whose x and y coordinates are the numbers given.

Make notes to yourself as needed about any of the above that is unfamiliar to you.


You should be familiar with how to look up a class in the Java API specification.

If not,

What you should do

Thinking about a Dud

Now that you know what methods you must implement, let's investigate how you should implement them.

  1. Question: A Dud is a Ball that the system draws. That's it -- that is all a Dud does. With that in mind: Of the 7 methods that you must implement in the Dud class, which can remain do-nothing stubs and which must have an actual, do-something implementation?
  2. Question: It might make sense to have some fields in the Dud class. However, are fields absoutely necessary for the Dud class? That is, could you implement a Dud that has no fields?
  3. Question: The getColor method returns what type of object?
  4. Question: Using the following fact:
    The Color class has a constructor that takes three integers -- the amount of red, green and blue in the constructed Color. Each integer should be an integer between 0 and 255.

    write an expression that would construct a new Color object that has some red and green but no blue.

  5. Question: The getShape method returns what type of object?
  6. Question: Look up the Shape class in the Java API specification. Is Shape a class or an interface? Explain why the following does not make sense (and will NOT construct a Shape object):
        new Shape()
    
    
  7. Question: The Java API specification for the Shape class lists many implementing classes for Shape. Find one that looks promising for a ball's (round) shape and write an expression that constructs a new object of that Shape.

If any of the above questions are still confusing to you, ask your instructor or an assistant for help NOW -- you will be unable to complete the rest of this exercise without understanding the answers to the above questions.

Implementing Dud

What you should learn

Resources

Some questions/issues to consider throughout this exercise are: Some notes/reminders from BallWorld's UML class diagram to consider throughout this exercise are:

What you should do

Implementing a Dud

As you do this part of the exercise:

  1. Keeping in mind the above:

    Augment your BallWorlds project to include a Dud class that extends Ball and implements Animate, Drawable, Relocatable.

    A Dud should do nothing except appear in the World.

    • It can appear wherever you wish, with any reasonable size and color.

Wrapping Up

What you should do

Summary

Perhaps the most important ideas that you saw in this part of BallWorlds are:

  • How to implement a class from its UML class diagram
  • How to construct new objects
  • How to read the Java API specification of a class and apply what you learn
  • The meaning of the keyword this
  • How to use one object to do work on behalf of another object
  1. Commit your changes back to your SVN repository. Be sure to add Dud.java to the repository (by checking the correct check box).
  2. Question: How many minutes did it actually take you to complete this part of BallWorlds?
  3. Question: Compute the ratio of the time you ACTUALLY TOOK to complete this part of this lab to the time you ESTIMATED that you would take. Choose the ratio in the report that is closest to your ratio.
  4. Submit your report for this part of BallWorlds.