Question: Thanks for help my Java Arraylists question. I will upvote when you done. . Create an Arraylist of Fruit objects. Create 8 Fruit objects: 1
Thanks for help my Java Arraylists question. I will upvote when you done.


. Create an Arraylist of Fruit objects. Create 8 Fruit objects: 1 non-rotten red Apple with a crisp texture and sweet taste 2 rotten green Apple objects with a soft texture and tart taste 3 non-rotten Lemon objects with a sour taste. "sourness" should be a random integer from 0-100 for each object 2 rotten Orange objects of type "mandarin" with a sweet taste. Put those objects in the Arraylist. They should all be able to be added to the same Arraylist, regardless of their subclass. The Arraylist MUST be parameterized to accept Fruit objects. It should accept all Fruit objects but should not accept non-fruit objects. For example, this: fruitArrayList.add(new Object (); should not compile Print out the average sourness of all the Lemon objects in the Arraylist. You have to do this by looping through the array list, finding the Lemon objects, and their sourness Remove the matching objects: Retain the 1st rotten green Apple object in an Apple variable. The goal is ultimately to remove all of the Apple objects in the Arraylist that match this variable: To start: Loop through the Arraylist and print out (using toString) which objects in the Apple object is equal (in value) to the Apple object in your variable. Also print out which object in the Arraylist is the same object as the one in your variable. You must figure out how to remove all the matching objects from the Arraylist. There is no one correct way to do this. But there are incorrect ways. Print out the remaining objects: Loop through the Arraylist again and print out (using toString) all the remaining objects in the Arraylist. Fruit -color:String -rotten:Boolean -next id.int -Id:int +Fruit() +Fruit(color:String, rotten:boolean) +getColor():String +setColor(color:String): void +is Rotten():boolean +setRotten(rotten:boolean):void +getld():int +toString():String extends extends Citris -taste:String +Citrus() + Citrus(taste:String, color:String, rotten:boolean) +getTaste():String +setTaste(taste:String): void +toString():String extends extends Orange Apple -taste:String -texture:String +Apple() +Apple(taste:String, texture:String, color:String, rotten:boolean) +getTaste():String +setTaste(taste:String): void +getTexture():String + setTexture(texture:String): void +toString():String -type:String +Orange() + Orange(type:String, taste:String, rotten:Boolean) +getType():String +setType(type:String): void +toString(): String Lemon -sourness:int +Lemon() +Lemon(sourness:int,taste:String rotten:boolean) +getSourness():int +setSourness(sourness:int): void +toString():String FruitArraylist.java X 1 package arraylists; 2 import java.util.ArrayList; 5 6 public class FruitArraylist { 7 80 public static void main(String[] args) { 9 10 // this ArrayList MUST be parameterized 2.11 ArrayList fruitArrayList; 12 13 // this is the variable you should retain to compare 14 // to the other objects in the arraylist 2215 Apple rottenGreenApple1; 16 } 17 } 18
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
