Question: in JAVA: Create the following class. Read the entire question first! Write a class Distance with the following specifications: Class variables: a private static integer

in JAVA:

Create the following class. Read the entire question first!

Write a class Distance with the following specifications:

Class variables:

a private static integer called INCHES_IN_A_FOOT with a value 12;

a private static float called FEET_IN_A_METER with a value of 0.3048f;

Instance variables:

Two integer instance variables: feet and inches;

Constructors:

a no argument constructor to initialize a Distance with zero feet, zero inches.

a two argument constructor that will accept two positive integers and for feet and inches. An IllegalArgumentException is thrown if the number of inches is more than 11.

Get/Set methods:

get methods for the instance variables;

set methods for instance variables.

Public methods:

1. a method add() that adds another Distance object to itself.

That is,

w1 = new Distance(4,9);

w2 = new Distance (3,6);

w1.add(w2); // w1 becomes 8 feet, 3 inches

2. a method metricDistance() that will return (as a float) the number of meters in the distance represented by the object.

That is, for w1 above, w1.metricDistance() returns 1.4478f

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!