Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello experts. I need help with a JAVA question as soon as possible please. Thanks for your help JAVA PROGRAMMING Your job for this assignment

Hello experts. I need help with a JAVA question as soon as possible please. Thanks for your help

JAVA PROGRAMMING

Your job for this assignment is to design and implement a class named "Measurement". A measurement

consists of a number followed by 1 or more units, which may occur in the numerator or denominator.

For example, the following are measurements: 3in,12.5s, 9.8m/second squared,128.2 ft lb.

To complete the assignment, you need to implement and test the following:

1. A Constructor that takes a number and a string and return a new Measurement. e.g. Measurement x = new Measurement (5, "in");

2. The add operation that takes two measurements and returns a new measurement. The original measurements should remain unchanged.

(You should test for this) Note: You can only add two measurements with exactly the same units. Otherwise, you should cause an error by using:

throw new ArithmeticException();

e.g. x = y.add(z) ;

3. The sub operation that works like add, but subtracts the measurements.

4. The mult operation that takes 2 measurements and multiplies them together. Note: you can always

multiply two measurements 3ft * 4lb yields 12ft lb. You should cancel out units. 9.8m/s squared * 10s yields 98m/s.

5. The div operation that works like mult, but divides its arguments.

8. The toString() method, which will create a printable string for a unit (by writing this method, you should be able to print result to standard out with System. out .print(...........).

Hints: Your constructor only needs to construct measurements with primitive units (no exponents). You can create measurements with complex units by using your operations. For example, to create 12kgm/s squared, you can take a measurement of 12kg , multiply it by 1m and divide it by 1s twice.

Test every case you can think of.

Here is a picture of the work

image text in transcribed

Your job for this assignment is to design and implement a class named "Measurement A measurement consists of a number followed by 1 or more units, which may occur in the numerator or denominator. For example, the following are measurements: 3in, 12.5s, 9.8m/s2,128.2ftlb. To complete the assignment, you need to implement and test the following: 1. A Constructor that takes a number and a string and return a new Measurement. e.g. Measurement x - neu Measurement (5, "in" 2. The add operation that takes two measurements and returns a new measurement. The original measure- ments should remain unchanged. (You should test for this) Note: You can only add two measurements with exactly the same units. Otherwise, you should cause an error by using: throw neu ArithmeticExceptionO e.g. x - y.add(z); 3. The sub operation that works like add, but subtracts the measurements. 4. The mult operation that takes 2 measurements and multiplies them together. Note: you can always multiply two measurements 3ft 4lb yields 12ft Ib. You should cancel out units. 9.8m/s2 10s yields 98m/s 5. The div operation that works like mult, but divides its arguments. 6. The toString) method, which will create a printable string for a unit (by writing this method, you should be able to print result to standard out with System.out.print(...)) Hints: START EARLY Your constructor only needs to construct measurements with primitive units (no exponents). You can create measurements with complex units by using your operations. For example, to create 12kgm/s2, you can take a measurement of 12kg, multiply it by 1m and divide it by 1s twice. Test every case you can think of

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Visualization A Practical Introduction

Authors: Kieran Healy

1st Edition

0691181624, 978-0691181622

More Books

Students also viewed these Databases questions

Question

Differentiate among the various sleep disorders.

Answered: 1 week ago

Question

(1) How many levels and factors are there in this example? Pg45

Answered: 1 week ago