Question
IN JAVA PLEASE HELP TAKE YOUR TIME I WILL LEAVE A LIKE RATING AND SUPPORT! (8 points) part 1 : Using your Barrel class and
IN JAVA PLEASE HELP TAKE YOUR TIME I WILL LEAVE A LIKE RATING AND SUPPORT!
(8 points) part 1: 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.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 parameters 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. 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.
(2 points) Part 2: 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.)1) 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.2) Create a static void method that has an array parameter and is called 3 times to read in the values for each array.3) Create a static method that computes and returns the average for each array and is also called 3 times.4) Create a static method that prints the contents of an array.5) 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.6) Create a static helper method that has 3 array parameters and returns the largest of them. Use this method in requirement 5.7) As this program is running it should generate user friendly text for input and output explaining what the program is doing.8) 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; }
Temp class:
public class Temperature { private double value; // variable for temperature value private char unit; // variable for unit // default constructor public Temperature() { } public Temperature(double value, char unit) { this.setUnit(unit); this.setValue(value); } // getter methods public double getValue() { return value; }
public char getUnit() { return unit; } // setter methods public void setValue(double value) { this.value = value; }
public void setUnit(char unit) { //this.value = value; this.unit = Character.toUpperCase(unit); switch (unit)
{
case 'F':
if(value
{
System.out.println("degree can not be
System.exit(0);
}
else
{
this.value = value;
this.unit = 'F';
// System.out.println("F is assigned to scale");
}
break;
case 'C':
if(value
{
System.out.println("C can not be
System.exit(0);
}
else
{
this.value = value;
this.value = 'C';
// System.out.println("C is assigned to value");
}
break;
case 'K':
if(value
{
System.out.println("in set degree cannot be negitive");
System.exit(0);
}
else
{
this.value = value;
this.unit = 'K';
}
break; }
} public String toString() { return value + "" + unit; } Temperature toCelsius() { Temperature t = this; if (this.unit == 'F') { double celsius = ((5 * (this.value - 32.0)) / 9.0); t = new Temperature(celsius, 'C'); } else if (this.unit == 'K') { double celsius = this.value - 273.15; t = new Temperature(celsius, 'C'); } return t; } Temperature toKelvin() { Temperature t = this; if (this.unit == 'C') { double kelvin = (double) (this.value + 273.15); t = new Temperature(kelvin, 'K'); } if (this.unit == 'F') { double kelvin = 273.5 + ((this.value - 32.0) * (5.0 / 9.0)); t = new Temperature(kelvin, 'K'); } return t; } Temperature toFahrenheit() { Temperature t = this; if (this.unit == 'C') { double f = (this.value * 9.0 / 5.0) + 32.0; t = new Temperature(f, 'F'); } if (this.unit == 'K') { double f = (((this.value - 273) * 9.0 / 5.0) + 32); t = new Temperature(f, 'F'); } return t; } public boolean equals(Temperature other) { Temperature t1 = this.toCelsius(); Temperature t2 = other.toCelsius();
Barrel class:
Barrel demo:
Temp demo:
Part 1: I already completed it:
Vacuum barrel:
class VaccumBarrel{
int numberOfApples;
Temperature temperature;
// constructors
public VaccumBarrel(){
numberOfApples = 0;
temperature = null;
}
public VaccumBarrel(int tempa,Temperature tempb){
numberOfApples = tempa;
temperature = tempb;
}
// add method
public VaccumBarrel add(VaccumBarrel a){
VaccumBarrel temp = new VaccumBarrel();
temp.numberOfApples = numberOfApples + a.numberOfApples;
temp.temperature = temperature.add(a.temperature);
return temp;
}
// subtract
public VaccumBarrel subtract(VaccumBarrel ob){
VaccumBarrel temp = new VaccumBarrel();
temp.numberOfApples = numberOfApples - ob.numberOfApples;
this.temperature = temperature.subtract(ob.temperature);
return temp;
}
// divide
public VaccumBarrel divide(int num){
VaccumBarrel temp = new VaccumBarrel();
temp.numberOfApples = numberOfApplesum;
temp.temperature = temperature;
double tempTemperatureValue = temp.temperature.getValue()um;
temp.temperature.setValue(tempTemperatureValue);
return temp;
}
public boolean equals(VaccumBarrel ob){
// if all true, return true.
return (numberOfApples==ob.numberOfApples
&& temperature.getValue()== ob.temperature.getValue()
&& temperature.getUnit()==ob.temperature.getUnit());
}
public boolean greaterThan(VaccumBarrel ob){
// if all true, return true.
return (numberOfApples>ob.numberOfApples
&& temperature.getValue()>ob.temperature.getValue()
&& temperature.getUnit()==ob.temperature.getUnit());
}
// converting temp to K
public VaccumBarrel toKelvin(){
VaccumBarrel temp = new VaccumBarrel();
temp.numberOfApples = numberOfApples;
temp.temperature = temperature.toKelvin();
return temp;
}
// converting temp to F
public VaccumBarrel toFahrenheit(){
VaccumBarrel temp = new VaccumBarrel();
temp.numberOfApples = numberOfApples;
temp.temperature = temperature.toFahrenheit();
return temp;
}
// converting temp to C
public VaccumBarrel toCelsius(){
VaccumBarrel temp = new VaccumBarrel();
temp.numberOfApples = numberOfApples;
temp.temperature = temperature.toCelsius();
return temp;
}
// toString() to print Object
public String toString(){
return numberOfApples+" @ "+temperature;
}
}
Math class:
I need help with part 2: of the original question worth 2 points all information above was for part 1 and all the classes were provided with the demos.
import java.util.Scanner; public class Barrel { private int numberOfApples; public static final int MINIMUM = 0; public static final int MAXIMUM = 1000; public Barrel() { this.numberOfApples = 0; } public Barrel (Barrel barrel) { this.numberOfApples = barrel.get(); public Barrel(int n) { while (nStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started