1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
sladkih [1.3K]
3 years ago
3

Given a base Plant class and a derived Flower class, complete main() to create an ArrayList called myGarden. The ArrayList shoul

d be able to store objects that belong to the Plant class or the Flower class. Create a method called printArrayList(), that uses the printInfo() methods defined in the respective classes and prints each element in myGarden. The program should read plants or flowers from input (ending with -1), adding each Plant or Flower to the myGarden ArrayList, and output each element in myGarden using the printInfo() method.
Computers and Technology
1 answer:
Zielflug [23.3K]3 years ago
6 0

Answer:

See explaination

Explanation:

import java.util.Scanner;

import java.util.ArrayList;

import java.util.StringTokenizer;

public class PlantArrayListExample{

public static void main(String[] args) {

Scanner scnr = new Scanner(System.in);

String input;

ArrayList<Plant> myGarden = new ArrayList<Plant>();

String plantName, colorOfFlowers;

boolean isAnnual;

double plantCost;

input = scnr.next();

Plant temp = null;

while(!input.equals("-1")){

plantName = scnr.next();

plantCost = scnr.nextDouble();

if(input.equals("flower")){

isAnnual = scnr.next().equals("true");

colorOfFlowers = scnr.next();

temp = new Flower();

temp.setPlantName(plantName);

temp.setPlantCost(plantCost);

((Flower)temp).setPlantType(isAnnual);

((Flower)temp).setColorOfFlowers(colorOfFlowers);

myGarden.add(temp);

}

else{

temp = new Plant();

temp.setPlantName(plantName);

temp.setPlantCost(plantCost);

myGarden.add(temp);

}

input = scnr.next();

}

printArrayList(myGarden);

}

public static <T extends Plant> void printArrayList(ArrayList<T> myGarden){

for(Plant p:myGarden){

System.out.println(p);

}

}

}

You might be interested in
What is the main advantage of using a WYSIWYG("what you see is what you get")editor when constructing a website
Tomtit [17]

Answer:

c

12121212121212121212121212121221212121212121212

7 0
3 years ago
QUESTION 11
tino4ka555 [31]

Answer:

x == 32

Explanation:

CODE in Java:

       int x = 32;

       if(x == 32){

           System.out.println("Pass");

       }

       else{

           System.out.println("Fail");

       }

OUTPUT:

Pass

8 0
3 years ago
Looking at the example below is the type value equal to a string or an integer?
Simora [160]
B. Integer I think that’s the answer
5 0
3 years ago
Read 2 more answers
What is the name for the type of flash memory that is used by mobile devices to store their apps and data?
tankabanditka [31]
D. Solid state is correct
5 0
3 years ago
Black and white squares codehs, i need the whole code (40 points for correct answer)
ludmilkaskok [199]

Answer:

speed(0)

penup()

setposition(-100,0)

count=0

def make_squares(i):

if i % 2 == 0:

begin_fill()

for i in range(4):

forward(25);

left(90)

end_fill()

penup()

pendown()

for i in range(6):

pendown()

make_squares(i)

penup()

forward(35)

Explanation:

3 0
3 years ago
Read 2 more answers
Other questions:
  • 2. What is the purpose of an outline? (1 point)
    8·1 answer
  • How will advertising and communications change as technology improves?????? HELP PLEASE :0 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    12·1 answer
  • Pinterest, a visual bookmarking Website, logs more than 14 terabytes of new data each day, which means its storage needs are con
    10·1 answer
  • Give sally sue specific suggestions on how she can improve her powerpoint skills.
    6·1 answer
  • What is the shortest, abbreviated version of the copy running-config startup-config command?
    6·1 answer
  • Which value can be entered to cause the following code segment to display the message: "That number is acceptable." int number;
    11·1 answer
  • . Each ____ on a menu performs a specific action.
    14·1 answer
  • Many of the first photographers were actullay scientists and inventors
    11·1 answer
  • What are some ways to find out what skills you need to develop at work? Check all of the boxes that apply.
    15·2 answers
  • In confirmatory visualization Group of answer choices Users expect to see a certain pattern in the data Users confirm the qualit
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!