On this page:
Lab 1 Description
Warmup
Shapes
Mobiles
Version: 5.2.1

Lab 1

Lab 1 Description

Start by setting up a project in your favorite IDE and dowloading all the libraries we will use into some folder on your computer.

Warmup

Add to your project the file ExamplesCircleShape.java, add the tester.jar to the classpath, and run the program.

Read the code and see how the examples and test cases are designed.

The running of the tests is invoked in the main method as

Tester.runReport(e, true, true);

The first boolean argument indicates that we want to see a pretty-print display of all data defined in the Examples class. The second boolean argument indicates that we want to see the display of all test results, successful and failed ones as well.

In most cases we only show the failed test results. Also, if the Examples class defines a large number of sample data, we may choose not to display the data.

Shapes

The starter files:

Add to your project the one of these files. Add to the project the tester.jar library file and run the project from the main method in the class Examples....

Think what would be needed to test the second method without having the tester library.

Mobiles

Start a new project. You can try to start from the scratch, or use the partially built program to speed up the work. Your goal is to design a representation of a mobile and design some methods that will help the designer of the physical objects. Because we want to see the drawing of the mobile, we add the libraries worldcanvas.jar, worldimages.jar, and colors.jar to the classpath. (The code already has the necessary import statements.)

The starter files:

Design the data representation of a mobile. A mobile is either a simple ball (we know its color and weight) hanging on a thin line of some length, or it is a thin line of some length that has at the end a horizontal strut (we know the length of the left and right part from the place where it is suspended) with a mobile hanging from each end of the strut.

Import javalib.colors and define colors as new Black(), new White(), new Red(), new Blue(), new Green(), or new Yellow().

Here are some examples:

Simple mobile:   Complex mobile:

 

     |                   |

     |               ----+------

     20              |         |

    blue            30         |

                    red     ---+---

                            |     |

                            10    10

                          green  red

Design the following methods for your mobiles:

Think what would be needed to test the second and the third method without having the tester library.