Lab 07

Bicycle Builder

 

 

Objective:

Practice object-oriented principles by building a bicycle out of multiple objects and test it with the tester.

 

Lab Solution

 

Requirements: 

[Wheel] Diameter <<Wheel’s Diameter>> Width: <<Wheel’s Width>>

Where values in “<<>>” correspond to the instance variable values.

[Frame] Size: <<Frame’s Size>> Type: <<Frame’s Type>>

Where values in “<<>>” correspond to the instance variable values.

[Bicycle] Make: <<Bicycle’s Make>> Front Wheel <<Bicycle’s Front Wheel>> Back Wheel <<Bicycle’s Back Wheel>> Frame: <<Bicycle’s Frame>>

Where values in “<<>>” correspond to the instance variable values.

 

Example Dialog:

 

---------------------------------

Welcome to the Bicycle Builder Tester!

---------------------------------

First we will create a "Default" Bicycle

Printing the Bicycle's data

Bicycle's make: none

Bicycle's front wheel: Diameter 16.0 Width: 1.0

Bicycle's back wheel: Diameter 16.0 Width: 1.0

Bicycle's frame: Size: 18.5 Type: diamond

 

Testing the toString method

[Bicycle] Make: none Front Wheel: [Wheel] Diameter: 16.0 Width: 1.0 Back Wheel: [Wheel] Diameter: 16.0 Width: 1.0 Frame: [Frame] Size: 18.5 Type: diamond

 

Setting invalid values for the default bike's wheels and frame

[Bicycle] Make: none Front Wheel: [Wheel] Diameter: 16.0 Width: 1.0 Back Wheel: [Wheel] Diameter: 16.0 Width: 1.0 Frame: [Frame] Size: 18.5 Type: diamond

 

Creating another bike using the parameterized constructor

[Bicycle] Make: Big Wheel Front Wheel: [Wheel] Diameter: 55.0 Width: 2.5 Back Wheel: [Wheel] Diameter: 18.0 Width: 2.0 Frame: [Frame] Size: 60.0 Type: Penny-Farthing

 

Creating another bike using the parameterized constructor with invalid values

[Bicycle] Make: none Front Wheel: [Wheel] Diameter: 16.0 Width: 1.0 Back Wheel: [Wheel] Diameter: 16.0 Width: 1.0 Frame: [Frame] Size: 18.5 Type: diamond

 

Checking the "equals" method

Does the first and third bicycles have different memory addresses? true

Does the first and third bicycles have the same properties? true

 

---------------------------------

Tests Complete! Goodbye

---------------------------------

Solution Tests:

  1. Is your name written as a comment in all source files?
  2. Does the solution compile (no syntax errors)?

3.      Does your output match the example dialog?

 

Lab Report

  1. Create a section named “Problem” and describe this lab’s problem in your own words. (10pts).
  2. Create a section named “Solution Description” and describe how the code solves the problem in your own words. (10pts).
  3. Create a section named “Problems Encountered” and describe the various syntax, run-time, and logic errors that were encountered while implementing the solution. (10pts).
  4. Explain the purpose of accessors (“getters”). (10pts).
  5. Explain the purpose of mutators (“setters”). (10pts).
  6. Describe when it is most appropriate to use the “equals” method for comparing objects. (10pts).
  7. Describe when it is most appropriate to use the “==” operator for comparing objects. (10pts).

 

For questions 8, 9, and 10 refer to the code below.

  1. What will the code snippet below print to the console? (10pts)

  1. What will the code snippet below print to the console? (10pts).

  1. What will the code snippet below print to the console? (10pts).

 

Finally:

Upload the source code (.JAVA File Extension) and written lab report (.DOC, .DOCX, or .PDF file extension) to the CSCE Dropbox.