Using your Bottle class and Fraction class extends a Fractio
Using your Bottle class and Fraction class extends a FractionBottle class that extends the Bottle class and incorporates a Fraction as the private data of the FractionBottle. The Bottle value is kept separate from the Fraction value.They are pot combined. Provide constructors. add(FractionBottle). multiply(FractionBottle). subtract(FractionBottle). divide(FractionBottk). cquals(FractionBottle). I greaterThan(Fraction Bottle) that has one parameter and returns true if the this is greater than the parameter(use the Bottle value for comparison) and toString() methods. Use a similar demo to the one you used for the Fraction class. You must put FractionBottles in arrays and manipulate them. Write a program that satisfies the next 8 requirements Use the random number generator as described on the bottom of page 402 to create 3 arrays of random sizes of I to 5 elements. Create a static void method that has an array parameter and is called 3 times to read in the values for each array. Create a static method that computes and returns the average for each array and is also called 3 times. Create a static method that prints the contents of an array. 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 the instances of FractionBottle that are the largest FractionBottle of the three arrays for each element. For the purpose of this project consider the Bottle part of the FractionBottle for comparison. Create a static helper method that has 3 array parameters and returns the largest of them. Use this method in requirement 5. As this program is running it should generate user friendly text for input and output explaining what the program is doing Create a set of test values that demonstrate that your program runs correctly. Here are some further thoughts on the FractionBottle class. Using the Bottle add method as an example we know that the following code is a part of the add method for the FractionBottle: public FractionBottle add (FractionBottle other) FractionBottle answer - new FractionBottle(); return answer; The FractionBottle class extends Bottle so it is a Bottle. The data of the Bottle class should be private so the code answer marbles-this marbles + other marbles; will box compile. The Bottle methods are inherited however and they can be used to make the addition. The Bottle class should have methods set(int) that can be used to set the value of marbles to the integer parameter. The bottle class should have method get() that will return the value of a Bottle. If the values of the two Bottles can be found then an addition is easy. It is also possible that the Bottle class has method set(Bottle) that will set the value of marbles to the parameter\'s value. The method add(Bottle) of the Botle class returns of Bottle. Using these two methods will also give the value for FractionBottle answer. The FractionBottle has a private Fraction that can use the methods from the fraction clas. In the FranctionBottle the private data numerator and denominator of the Fraction class cannot be used. If the private data in the FranctionBottle s called frac then this value can be accessed with this code: anaswer.frac, this, this.frac and other.frac
Solution
public class FractionBottle extends Bottle { Fraction myFraction = new Fraction(); public FractionBottle() { super(); myFraction.getNumerator(); myFraction.getDenominator(); } public FractionBottle(int wholeValue, int num, int den) { super(wholeValue); myFraction.set(num, den);; } public void read() { super.read(); System.out.println(\"Pleas enter value for fraction part:\"); myFraction.read(); } public FractionBottle add(FractionBottle other) { FractionBottle sumOfBottles = new FractionBottle(); sumOfBottles = this.add(other); sumOfBottles.myFraction = this.myFraction.add(other.myFraction); return (sumOfBottles); } public class FractionBottleDemo { public static void main (String args[]) { FractionBottle fbl1 = new FractionBottle(); FractionBottle fbl2 = new FractionBottle(); FractionBottle fbl3 = new FractionBottle(); FractionBottle fbl4 = new FractionBottle() System.out.println(\"Enter info for whole value for fbl1: \"); fbl1.read(); System.out.println(\"Enter infor for whole value for fbl2: \"); fbl2.read(); System.out.println(\"Enter infor for whole value for fbl3: \"); fbl3.read(); System.out.println(fbl1); System.out.println(fbl2); Syatem.out.println(fb13); fbl3 = fbl1.add(fbl2); fb14=fb13.add(fb13); fb15=fb14.(addfb13); fb16=fb15%3; System.out.println(fb16); //print average } }