answer.
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]
2 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]2 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
A laptop gets replaced if there's a hardware issue. Which stage of the hardware lifecycle does this scenario belong to?
Ilya [14]

Answer: Maintenance. This is the stage where software is updated and hardware issues are fixed if and when they occur. Retirement. In this final stage, hardware becomes unusable or no longer needed and it needs to be properly removed from the fleet

Explanation:

3 0
2 years ago
Which are factors that go into a project plan? Choose four answers.
USPshnik [31]

Factors that go into a project plan

  • Estimate the scope of work, based on similar projects.
  • Make sure everyone takes responsibility.
  • Creating and defining team goal
  • Working to a budget

Explanation:

Project Estimating  : Every project is different, but that doesn’t mean you have to start from zero each time. The best way to make sure you’re on the right track is to approach it from every angle. Consider similar projects, talk to your team, and understand what the client is expecting and how they’d like things to go.

Managing your team size  : A smaller team is usually preferable as it puts your project in the most ideal position to be completed on time and at the quality you expect, without burning out your team members. A smaller team also reduces the number of communication channels, which means there’s less opportunity for misinterpretation or people simply missing something.  

Planning and managing your team resources  : That said, there may be a time when you don’t have the right resources in-house to do the job. Either they are fully allocated to another project or no one has the right skill set. In this situation you have two options, either bring in freelance contractors or hire a new employee to fill the role.  

Creating and defining team goals  : The planning phase is when you’ll want to work with the team to understand what their individual goals are for the project. Is there something different they’d like to try? A test or new idea they’d like the chance to prove? Or perhaps a roadblock they want to avoid?

Scheduling Tasks to a Project Timeline  : The timeline of the project will largely be determined by the client, as they often have deadlines they need to hit to meet certain business goals that are simply out of your control. However, setting clear expectations and agreeing on the timing of key deliverables is crucial.

7 0
2 years ago
Which of the following best describes open-source web browsers?
podryga [215]
Hello, Good Works mate!

Answer: A) <span>Open-source web browsers allow non-paid access and distribution.

Kind Regards.</span>
4 0
2 years ago
Read 2 more answers
2) Complete the get_num_of_characters() function, which returns the number of characters in the user's string. We encourage you
Lilit [14]

Explanation:

Number of characters: 46

String with no whitespace: Theonlythingwehavetofearisfearitself.

########################################################

def get_num_of_characters(inputStr):

   count = 0

   for i in range(0,len(inputStr)):

       count = count + 1

   #count = len(inputStr)

   return count

def output_without_whitespace(inputStr):

   #statement = statement.strip()

   statement2 = ' '

   for i in range(0,len(inputStr)):

        if(inputStr[i] == ' '):

           statement2 = statement2

       else:

           statement2 = statement2 + inputStr[i]

       

   inputStr = inputStr.replace(" ", "")

   return statement2

inputStr = input('Enter a sentence or phrase: ')

print()

print('You entered:', inputStr)

num = get_num_of_characters(inputStr)

print()

print('Number of characters:', num)

print('String with no whitespace:',output_without_whitespace(inputStr))

#if __name__ == '__main__':

   # Think I'm supposed to use this if statement

########################################################

'''ERROR MESSAGE WHEN RUNNING TEST

Unit test

0/1

Tests that get_num_of_characters() returns 46 for "The only thing we have to fear is fear itself."

Your output

Enter a sentence or phrase: Traceback (most recent call last):

 File "zyLabsUnitTestRunner.py", line 4, in <module>

   from zyLabsUnitTest import test_passed

 File "/home/runner/local/unit_test_student_code/zyLabsUnitTest.py", line 1, in <module>

   from main import get_num_of_characters

 File "/home/runner/local/unit_test_student_code/main.py", line 19, in <module>

   inputStr = input('Enter a sentence or phrase: ')

EOFError: EOF when reading a line'''

6 0
2 years ago
Translate each of these statements into logical expressions using predicates, quantifiers, and logical connectives. a) Something
yKpoI14uk [10]

Answer:

Let P(x) = x is in the correct place

Let Q(x) =  x is in the excellent place

R(x) denotes the tool

Explanation:

a) Something is not in the correct place.

P(x) is that x is in the correct place so negation of ¬P(x) will represent x is not in the correct place. ∃x is an existential quantifier used to represent "for some" and depicts something in the given statement. This statement can be translated into logical expression as follows:

                                                    ∃x¬P(x)

b) All tools are in the correct place and are in excellent condition.

R(x) represents the tool, P(x) represents x is in correct place and Q(x) shows x is in excellent place. ∀ is used to show that "all" tools and ∧ is used here because tools are in correct place AND are in excellent condition so it depicts both P(x) and Q(x). This statement can be translated into logical expression as follows:

                                       ∀ x ( R(x) → (P(x) ∧ Q(x))

c) Everything is in the correct place and in excellent condition.

Here P(x) represents correct place and Q(x) represents excellent condition ∀ represent all and here everything. ∧  means that both the P(x) and Q(x) exist. This statement can be translated into logical expression as follows:

                                              ∀ x (P(x) ∧ Q(x)

7 0
2 years ago
Other questions:
  • Which of the given information should you keep confidential and why? a. You see a memo with the name of your coworker, who will
    13·2 answers
  • Assume that a kernel is launched with 1000 thread blocks each of which has 512 threads. If a variable is declared as a shared me
    6·1 answer
  • Given six memory partitions of 300 KB, 600 KB, 350 KB, 200 KB, 750 KB, and 125 KB (in order), how would the first-fit, best-fit,
    11·1 answer
  • Write an application that throws and catches an ArithmeticException when you attempt to take the square root of a negative value
    15·1 answer
  • To reduce costs and the environmental impact of commuting, your company decides to close a number of offices and to provide supp
    11·1 answer
  • The area of a square is stored in a double variable named area. write an expression whose value is length of the diagonal of the
    11·1 answer
  • Using basic programming (for loops, while loops, and if statements), write two MATLAB functions, both taking as input:
    6·1 answer
  • Write a function named max that accepts two integer values as arguments and returns the value that is the greater of the two. Fo
    12·1 answer
  • System design is the determination of the overall system architecture-consisting of a set of physical processing components, ___
    6·2 answers
  • Company A is setting up a network of mostly Windows machines. Which networking file system protocol would you recommend for maxi
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!