Ask Operating System Expert

Objectives

• Construct and use Objects

• Design the public interface of a class

• Determine the instance variables necessary for a class

• Implement stubs with comments

• Implement constructors

• Implement simple methods using conditionals

• Access instance fields and local variables

Hand-in Requirements

The project folder should include the following files:

• Length.xml

• Length.java

• LengthTest.java

• the public interface as a text or Word file

Overview

write a program to construct and manipulate Length objects that can handle any of the following units: meters, inches, feet, yards, miles. In addition to modifying the methods, you will include methods for returning the number of meters, for adding two Length objects, and testing whether two Length objects are approximately equal.
Writing the New and Improved Length Class
Constants:
The following constants should be included in the Length class before the instance fields. These constants should be used by your methods. Do not use the numbers in your methods instead of the named constants.
public static final double INCHES_PER_YARD = 36;
public static final double FEET_PER_YARD = 3;
public static final double METERS_PER_YARD = 0.9144;
public static final double YARDS_PER_MILE = 1760;
public static final double EPSILON = 0.000001;

Instance fields:
myNumber - a double value representing the number of the measurement
myUnit - a String value representing the unit of the measurement
Constructors:
/* The constructor has two parameters: */
/* the number and the unit of the measurement. */
public Length(double number, String unit)

Methods:Three methods will be added, and the behavior of some methods will be changed.
The following methods should be added. The comments contain some hints.

/* getMeters returns the length in meters.
This should be implemented to calculate the appropriate conversion
based on the value of myUnit, e.g.,

if ( myUnit.equals("yards") )
meters = myNumber * METERS_PER_YARD;

If myUnit cannot be recognized, assume the unit is meters.
*/

public double getMeters( )
/* add returns a Length that is the sum of two Lengths, e.g.,
if length1 and length2 are two Length objects, then
length1.add(length2) will return a new Length object.

This can be implemented by using the getMeters method,
e.g., this.getMeters() + other.getMeters(), then returning
new Length(sum, "meters")
*/

public Length add(Length other)
/* aboutEqual returns true if the two lengths are within EPSILON
meters of each other.

First, get this.getMeters() and other.getMeters(). Then, return
true if they are close to each other (within EPSILON).
*/
public boolean aboutEqual(Length other)

The getInches, getFeet, getYards, and getMiles methods should be modified. First get the value of the getMeters method, e.g., this.getMeters(), then convert the number of meters to the desired unit using the named constants, and finally return that value.

Testing your Length class:

1. Ask the user to enter a number as a double from the keyboard. Store the response in number2.

2. Ask the user to enter a unit as a String from the keyboard. Store the response in unit2.

3. If unit2 is not "meters", "inches", "feet", "yards", or "miles", then print a warning message and set unit2 to "meters".

4. Instantiate a Length object named length2 using the input from above, and print length2 using the toString method. Be sure to use a descriptive label.

5. Print the values from calling length2 with the getMeters, getInches, getFeet, getYards, and getMiles methods. Be sure to use descriptive labels.

6. Ask the user to enter another number and another unit from the keyboard. Store the responses in number3 and unit3.

7. If unit3 is not "meters", "inches", "feet", "yards", or "miles", then print a warning message and set unit2 to "meters".

8. Instantiate a Length object named length3 using the input from above, and print length3 using the toString method. Be sure to use a descriptive label.

9. Determine whether length2 is about equal to length3, and assign the result to a boolean variable. Print different messages depending on the value of the variable.

10. Assign the result of adding length2 and length3 to length4, and print length4 using the toString method. Be sure to use a descriptive label.

Operating System, Computer Science

  • Category:- Operating System
  • Reference No.:- M91614295
  • Price:- $20

Priced at Now at $20, Verified Solution

Have any Question?


Related Questions in Operating System

Research types of operating systems that are currently

Research types of operating systems that are currently available and provide a scenario in which the operating system you chose would be appropriate to be used in this situation. Explain why you think the choice you made ...

Question research hex editors available for mac os and

Question : Research hex editors available for Mac OS and Linux. Based on the documentation, how easy would validating these tools be? Select at least two hex editors for each OS, and discuss what you would do to validate ...

Foundation of information technologyresearch types of

Foundation of Information Technology Research types of operating systems that are currently available and provide a scenario in which the operating system you chose would be appropriate to be used in this situation. Expl ...

Assignment -building a multi-threaded web server using c

Assignment - Building a multi-threaded web server using C and p threads, following the model from the lecture. Your program will have one thread acting as a dispatcher thread, listening fornetwork connections with reques ...

Question you are a security administrator responsible for

Question: You are a security administrator responsible for providing secure configuration requirements for new laptop deployments. After reading Module 2 of Certified Secure Computer User v2exercises, apply the configura ...

Question what do you see as the major differences between

Question : What do you see as the major differences between UNIX/Linux and other operating systems, such as Windows and Mac OS X? The response must be typed, single spaced, must be in times new roman font (size 12) and m ...

Question description of lasa in this assignment you will

Question: Description of LASA: In this assignment, you will select a real-world operating system (can be for a PC, server, tablet, handheld, or embedded device). You will introduce the operating system and its components ...

Discussion question this research assignment will give

Discussion Question : This research assignment will give further information on the nature and workings of multi-tasking and multi-processing operating systems. All information reported in this assignment is to be in the ...

Taskyour job in this assignment is to create two virtual

Task Your job in this assignment is to create two Virtual machines each running a different but the latest distribution of Linux e.g. Ubuntu Server and CentOS. Each of these VM's is to offer services to a user base. The ...

State the required answer precisely and then provide proper

State the required answer precisely and then provide proper explanation. It is not enough to provide one- word or one-line answers. Briefly describe the following concepts and indicate how they are related in the context ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As