Question: Java Only. 1. Design and implement a Temperature class able to handle temperatures in either Fahrenheit or Celsius. Include appropriate constructors (including a copy constructor),

Java Only.

1. Design and implement a Temperature class able to handle temperatures in either Fahrenheit or Celsius. Include appropriate constructors (including a copy constructor), getters and setters, toString, and belowFreezing methods. (5 pts.)

2. For your Temperature class (from problem 1), implement an appropriate equals method. Provide examples to demonstrate the use of your equals method. (3 pts.)

3. Give example use of objects of type Temperature (from problem 1) for each of the three means of object access discussed in class (and given in the lecture slides). Include sufficient code to demonstrate its use. (3 pts.) The three means of object access are

1. By Composition (object contains a data member which itself is an object)

2. By Parameter Passing (passing of an object to a method of a given object)

3. By Local Declaration (object declared within a method of a given object)

4. Give sufficient code to demonstrate how a class can be designed such that it maintains how many instances of itself exist at any given point in time. (3 pts.)

5. Assume that there is a Java interface named Measurable. The only method in the interface is method getMeasure(), which returns a string describing an objects measurement (if of type Measurement). Assume that there are three classes of type Measureable: Rectangle (with measurement height and width, in inches), Package (with measurement of weight in lbs and ounces), and WindSpeed (with measurement in miles per hour). Give sufficient code to demonstrate the use of polymorphism involving objects of each of these three types. (6 pts.)

6. Declare an interface named Sized, containing only one method, getSize, that returns a string. Assume that there exist a number of classes declared of type Sized in a particular application, specifically, StudentRecords (where size is the number of records), SemesterSchedule (where size it the number of credits taking), Department (where size is the number of faculty in a particular department), and Building (where size is the total number of square feet). (10 pts.)

Also declare a checked exception named UnsizedException.

Create a class named Measurements that contains just one static method named getSize that takes as an argument an object of any type (and returns a string type) and does the following:

If the object is of type String or StringBuffer, then returns a string of the form 16 characters

If the object is of type Sized, and also of type

StudentRecords, then returns a string of the form

SemesterSchedule, then returns a string of the form 16 credits

Department, then returns a string of the form 28 faculty members

Building, then returns a string of the form 8560 square feet

Otherwise, an UnsizedException is thrown.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!