Lab 06

Apple Maker

 

Objective:

 

Write a program that creates a class Apple and a tester to make sure the Apple class is crisp and delicious.

 

Lab Solution

 

Requirements:

 

Type: <<apple’s name>> Weight <<apple’s weight>> Price <<apple’s price>>

 

 

 

Example Dialog:

 

Welcome to the apple tester

 

Creating a default apple

Printing the default apple's value

Type: Gala Weight: 0.0 Price: 0.0

 

Creating another apple

Setting the new apple's values to the following, valid values

"Granny Smith 0.75 0.99"

Printing the new apple's values

Type: Granny Smith Weight: 0.75 Price: 0.99

 

Creating another defult apple

Then setting the new apple's values to the following, invalid values "iPad 2.5 -200"

Printing the newest apple's values which should not have changed from the default values

Type: Gala Weight: 0.0 Price: 0.0

 

Checking if the first and last apple have the same values.

True

 

Solution Tests:

  1. Is your name written as a comment in all source files?
  2. Does the solution compile (no syntax errors)?
  3. Have all the requirements for the class Apple been fulfilled?
  4. Have all the requirements for the class AppleTester been fulfilled?

 

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. In your own words describe what a class is used for.
  5. In your own words describe encapsulation as it relates to object-oriented programming.
  6. What is the reserved word used to create an object in memory?
  7. What is the purpose of a constructor and how is it different from other methods?
  8. The code snippet below seems to have an error on the Default Constructor. What is the error (or errors) and how can it be fixed?

  1. The code snippet below is an Accessor for a class, but it does not seem to work. How can this accessor be rewritten to work?

  1. The following code snippet keeps resulting in a “NullPointerException” run-time error. How can the code be altered to avoid this kind of error?

 

Finally:

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