Question: QUESTION: Write the java code below in Eclipse IDE enviroment and provide screenshot with execution. // a class for wght in pond and ounces Public

QUESTION: Write the java code below in Eclipse IDE enviroment and provide screenshot with execution.

// a class for wght in pond and ounces

Public class Wght {

// instances with private access

private int pond;

private double ounce;

// a secret named constant that specifies how many ounces are in a pond private double ounceInPond = 16;

// function Object() that enables initialization of the pond and ounces // to the parameter values provided

public Wght(int ponds, double ounce) {

this.pond = ponds;

this.ounce = ounce;

// standardise the ounces

normalOunces();

}

// a procedure to determine whether the Wght of the present object is less than

// the thing that the method received as a parameter

public boolean lessThan(Wght wt) {

// if the Wght of the current item is less than, return true. if(this.pond < wt.pond)

return true;

// if the Wght of the current object is more than 0, return false.

else if(this.pond > wt.pond)

return false;

// if not, both Wght have the same number of pond.

else {

// if the Wght of the current object is less than ounces, return true.

if(this.ounce < wt.ounce)

return true;

// if the current object weighs greater than ounces, return false.

else

return false;

}

}

// a process that increases the Wght of the present object

public void addTo(Wght wt) {

// the current object's Wght is increased by the called object's pounds and ounces.

this.pond += wt.pond;

this.ounce += wt.ounce;

// standardise the ounces

normalOunce();

}

// a method that returns the object's string representation

public Str toStr() {

return pond + " lbs " + Str.format("%.2f", ounce) + " oz";

}

// a function that gives the number of ounces in the called object overall private double toOunce() {

return pond * ounceInpond + ounce;

}

// a technique that normalises the Wght it was used with

private void normalOunce() {

//until the number of ounces is lower than the number of ounces in a pound, then repeat

while(ounce > ounceInpond) {

// subtract 16 ounces from the ounces and add 1 pond ounce -= ounceInpond;

pond++;

}

}

// add an additional method named getAvg()

// this method will accept a number and divide the current object's wght

// by the given number & then normalize the wght

public void getAvg(int n) {

// convert the current object's weight to total ounces

ounces = toOunces();

// reinitialize the current object's pound to 0

pond = 0;

// divide the total ounces by the given number

ounces = ounces / n;

// normalize the ounces

normalizeOunces();

}

}

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!