Create a static method that prints the contents of an array


Assignment

Using your Barrel class and Temperature class create a VacuumBarrel class that extends the Barrel class and incorporates a Temperature as the private data of the VacuumBarrel. Provide constructors, add(VacuumBarrel), subtract(VacuumBarrel), divide(int), equals(VacuumBarrel), greaterThan(VacuumBarrel) (that has one parameter and returns true if the this is greater than the parameter), toKelvin(), toFahrenheit(), toCelsius(), and toString() methods. Use a similar demo to the one you used with the Temperature class. This demo will put instances of VacuumBarrel in three arrays and manipulates them.

Again write a program that satisfies the next 8 requirements. Create a class similar to the Math class. Put the next 5 static methods in it. (These static methods could also be in the Demo class.)

i. Use the random number generator as described on the bottom of page 402 to create 3 arrays of random sizes of 1 to 5 elements.

ii. Create a static void method that has an array parameter and is called 3 times to read in the values for each array.

iii. Create a static method that computes and returns the average for each array and is also called 3 times.

iv. Create a static method that prints the contents of an array.

v. Create a static method that returns an array that has the same number of elements as the largest of the three arrays. This method will have 3 array parameters and will store in the returned array a copy of the VacuumBarrel that is the largest VacuumBarrel from the three arrays for each index. For the purpose of this question consider the largest to be the largest Barrel value.

vi. Create a static helper method that has 3 array parameters and returns the largest of them. Use this method in requirement 5.

vii. As this program is running it should generate user friendly text for input and output explaining what the program is doing.

viii. Create a set of test values that demonstrate that your program runs correctly.

Here are some further thoughts on the VacuumBarrel class. Using the Barrel add() method as an example we know that the following code is a part of the add method for the VacuumBarrel:

public VacuumBarrel add (VacuumBarrel other)
{
VacuumBarrel answer = new VacuumBarrel ();
return answer;
}

The VacuumBarrel class extends Barrel so it is a Barrel. The data of the Barrel class should be private so the code answer.marbles = this.marbles + other.marbles; will not compile. The Barrel methods are inherited however and they can be used to make the addition. The Barrel class should have method set(int) that can be used to set the value of marbles to the integer parameter. The Barrel class should have method get() that will return the value of a Barrel. If the values of the two Barrels can be found then an addition is easy. It is also possible that the Barrel class has method set(Barrel) that will set the value of marbles to the parameter's value. The method add(Barrel) of the Barrel class returns a Barrel. Using these two methods will also give the value for VacuumBarrel answer.

The VacuumBarrel has a private Temperature that can use the methods from the Temperature class. In the VacuumBarrel the private data degree and scale of the Temperature class cannot be used. If the private data in the VacuumBarrel is called temp then this value can be accessed with this code: answer.temp, this.temp and other.temp.

Request for Solution File

Ask an Expert for Answer!!
JAVA Programming: Create a static method that prints the contents of an array
Reference No:- TGS03216025

Expected delivery within 24 Hours