Write in Java
* Create a new client class called Plants.java
* Write code in the Plants class that solves problems 1,2,3 and 4
* Include the solutions of the different problems in different methods and call them from the main method
* Use the BagInterface.java and ArrayBag.java, but do not add any code
Problem 1: Create a bag plantsCart, which holds the following spring seedlings(represented by String) Rose, Daisy, Cabbage, Cucumber, Carrot, Cucumber, Daffodil, Daisy, Rose, Iris, Rose, Spinach.
Problem 2: Given the bag plantsCart, write statements that remove and display all plants in the bag
Probelm 3: Write statements that remove and count all occurnace of the string Rose in plantsCart. Do not remoe any other strings from the bag. Report the number of time that Rose occured. Print the new content of plantCarts.
Problem 4: Write a code fragment that moves all flowers from plantCart to a new cart (a new bag of Srtring objects) - flowersCart. At the end, report the numbers of flowers in flowersCart.
HINT: You can create a bag called flowers, which contains the strings representing flowers used in this program: Daisy, Iris, Rose, Daffodil and then use it to check each plant from plantsCart, whether it is a flower or not.
************************************************************************************
**BagInterface.java code**
_____________________________________
public interface BagInterface<T> {
/** Gets the current number of entries in this bag.
@return the integer number of entries currently in the bag */
public int getCurrentSize();
/** Sees whether this bag is full.
@return true if the bag is full, or false if not */
public boolean isFull();
/** Sees whether this bag is empty.
@return true if the bag is empty, or false if not */
public boolean isEmpty();
/** Adds a new entry to this bag.
@param newEntry the object to be added as a new entry
@return true if the addition is successful, or false if not
*/
public boolean add(T newEntry);
/** Removes one unspecified entry from this bag, if
possible.
@return either the removed entry, if the removal
was successful, or null */
public T remove();
/** Removes one occurrence of a given entry from this bag,
if possible.
@param anEntry the entry to be removed
@return true if the removal was successful, or false if not
*/
public boolean remove(T anEntry);
/** Removes all entries from this bag. */
public void clear();
/** Counts the number of times a given entry appears in this
bag.
@param anEntry the entry to be counted
@return the number of times anEntry appears in the bag */
public int getFrequencyOf(T anEntry);
/** Tests whether this bag contains a given entry.
@param anEntry the entry to locate
@return true if the bag contains anEntry, or false otherwise
*/
public boolean contains(T anEntry);
/** Creates an array of all entries that are in this bag.
@return a newly allocated array of all the entries in the bag
*/
public T[] toArray();
/** Overrides the toString method to give a nice display of the
items in
* the bag in this format Bag{Size:# <1>
<2> <3> <4> }
* @return a string representation of the contents of the bag
*/
public String toString();
/** Test whether this bag is equal to a given (as
parameter) bag.
@param aBag the bag to be compare to
@return true if both bags are equal */
public boolean equals(ArrayBag<T> aBag)
} // end BagInterface
*******************************************************************
***ArrayBag.java code *******
______________________________________________
//Start of ArrayBag class
public class ArrayBag<T> implements BagInterface<T>
{
private final T[] bag;
private static final int DEFAULT_CAPACITY = 25;
private int numberOfEntries;
/** Creates an empty bag whose initial capacity is 25. */
public ArrayBag() {
this(DEFAULT_CAPACITY);
} // end default constructor
/** Creates an empty bag having a given initial capacity.
@param capacity the integer capacity desired */
public ArrayBag(int capacity) {
numberOfEntries = 0;
// the cast is safe because the new array contains null
entries
@SuppressWarnings("unchecked")
T[] tempBag = (T[]) new Object[capacity]; // unchecked cast
bag = tempBag;
} // end constructor
public boolean add(T newEntry) {
boolean result = true;
if (isFull()) {
result = false;
} else { // assertion: result is true here
bag[numberOfEntries] = newEntry;
numberOfEntries++;
} // end if
return result;
} // end add
/** Retrieves all entries that are in this bag.
@return a newly allocated array of all the entries in the bag
*/
public T[] toArray() {
// the cast is safe because the new array contains null
entries
@SuppressWarnings("unchecked")
T[] result = (T[]) new Object[numberOfEntries]; // unchecked
cast
for (int index = 0; index < numberOfEntries; index++) {
result[index] = bag[index];
} // end for
return result;
} // end toArray
/** Sees whether this bag is full.
@return true if the bag is full, or false if not */
public boolean isFull() {
return numberOfEntries == bag.length;
} // end isFull
/** Sees whether this bag is empty.
@return true if the bag is empty, or false if not */
public boolean isEmpty() {
return numberOfEntries == 0;
} // end isEmpty
/** Gets the current number of entries in this bag.
@return the integer number of entries currently in the bag */
public int getCurrentSize() {
return numberOfEntries;
} // end getCurrentSize
public int getFrequencyOf(T anEntry) {
int counter = 0;
for (int index = 0; index < numberOfEntries; index++) {
if (anEntry.equals(bag[index])) {
counter++;
} // end if
} // end for
return counter;
} // end getFrequencyOf
/** Tests whether this bag contains a given entry.
@param anEntry the entry to locate
@return true if the bag contains anEntry, or false otherwise
*/
public boolean contains(T anEntry) {
return getIndexOf(anEntry) > -1;
} // end contains
/** Removes all entries from this bag. */
public void clear() {
while (!isEmpty()) {
remove();
}
} // end clear
/** Removes one unspecified entry from this bag, if
possible.
@return either the removed entry, if the removal was
successful,
or null otherwise */
public T remove() {
T result = null;
if (numberOfEntries > 0) {
numberOfEntries--;
result = bag[numberOfEntries];
bag[numberOfEntries] = null;
} // end if
return result;
} // end remove
/** Removes one occurrence of a given entry from this bag.
@param anEntry the entry to be removed
@return true if the removal was successful, or false if not
*/
public boolean remove(T anEntry) {
int index = getIndexOf(anEntry);
T result = removeEntry(index);
return anEntry.equals(result);
} // end remove
private T removeEntry(int givenIndex) {
T result = null;
if (!isEmpty() && (givenIndex >= 0)) {
result = bag[givenIndex]; // entry to remove
numberOfEntries--;
bag[givenIndex] = bag[numberOfEntries]; // replace entry with last
entry
bag[numberOfEntries] = null; // remove last entry
} // end if
return result;
} // end removeEntry
private int getIndexOf(T anEntry) {
int where = -1;
boolean found = false;
for (int index = 0; !found && (index < numberOfEntries);
index++) {
if (anEntry.equals(bag[index])) {
found = true;
where = index;
} // end if
} // end for
} // end getIndexOf
public String toString() {
String result = "Bag{Size:" + numberOfEntries + " ";
for (int index = 0; index < numberOfEntries; index++) {
result += "<" + bag[index] + "> ";
} // end for
result += "}";
return result;
}
public boolean equals(ArrayBag<T> aBag)
{
boolean result = false; // result of comparison of bags
int position; // want position available throughout method
if (numberOfEntries == aBag.getCurrentSize()) {
// Provisionally these are the same
result = true;
for (position = 0; (position < numberOfEntries); position++)
{
// Get the frequency of the item in this bag
int countInThisBag = getFrequencyOf(bag[position]);
int countInOtherBag = aBag.getFrequencyOf(bag[position]);
if (countInThisBag != countInOtherBag) {
result = false }
} // end for
}
return result;
} // end equals
} // end ArrayBag
In: Computer Science
Consider a sample of 50 football games, where 33 of them were won by the home team. Use a 0.05 significance level to test the claim that the probability that the home team wins is greater than one-half. Identify the null and alternative hypotheses for this test. Choose the correct answer below. A. Upper H 0 : pequals 0.5Upper H 1 : pless than 0.5 B. Upper H 0 : pequals 0.5Upper H 1 : pgreater than 0.5 C. Upper H 0 : pgreater than 0.5Upper H 1 : pequals 0.5 D. Upper H 0 : pequals 0.5Upper H 1 : pnot equals 0.5 Identify the test statistic for this hypothesis test. The test statistic for this hypothesis test is nothing . (Round to two decimal places as needed.) Identify the P-value for this hypothesis test. The P-value for this hypothesis test is nothing . (Round to three decimal places as needed.) Identify the conclusion for this hypothesis test.
In: Statistics and Probability
UsePython (import numpy as np) use containers (Branching if statement, while loop, for loop, numpy Array)
Implement an algorithm to guess a random number that the computer generates. The random number must be an integer between 1 and 1000 (inclusive). For each unsuccessful attempt, the program must let the user know whether to deal with a higher number or more. low. There is no limit on the number of attempts, the game only ends when the user succeeds. The user starts the game with $ 1000 and for each unsuccessful attempt loses $ 100. If you repeat any number of those who had already entered, they lose $ 200 instead of $ 100. If you don't follow the immediate instruction, you lose $ 200 instead of $ 100 (for example, if the program says to try a higher number, but you enter a higher number low to the previous one). In each unsuccessful attempt the program must tell the user how much money he has left (the figure can be negative). If the user hits the number and still has money, the program should congratulate him and tell him how much he won. If the user hits the number and owes money, the program must “bully” him and charge him. If the user hits the number by closing at $ 0 (neither wins nor owes), the program must let them know. In your report present 4 "print screens" of the execution of your program that result in 4 different results and their respective desktop tests (note that this is a special case where you have to run the program before the desktop test as there is no way I can control the random number that will come out in each run).
In: Computer Science
JAVA : Design and implement an application that plays the Rock-Paper-Scissors game against the computer. When played between two people, each person picks one of three options (usually shown by a hand gesture) at the same time, and a winner is determined. In the game, Rock beats Scissors, Scissors beats Paper, and Paper beats Rock. The program should randomly choose one of the three options (without revealing it) and then prompt for the user’s selection. At that point, the program reveals both choices and prints a statement indicating whether the user won, the computer won, or it was a tie. Continue playing until the user chooses to stop by saying either ‘y’ or ‘n’, where ‘y’ means ‘yes continue playing’, and ‘n’ means ‘no stop playing’. Then print the number of user wins, losses, and ties.
In: Computer Science
Use the geometric probability distribution to solve the
following problem.
On the leeward side of the island of Oahu, in a small village,
about 71% of the residents are of Hawaiian ancestry. Let n
= 1, 2, 3, … represent the number of people you must meet until you
encounter the first person of Hawaiian ancestry in the
village.
(a) Write out a formula for the probability distribution of the
random variable n. (Enter a mathematical
expression.)
P(n) =
(b) Compute the probabilities that n = 1, n =
2, and n = 3. (For each answer, enter a number. Round your
answers to three decimal places.)
P(1) =
P(2) =
P(3) =
(c) Compute the probability that n ≥ 4. Hint:
P(n ≥ 4) = 1 − P(n = 1) −
P(n = 2) − P(n = 3). (Enter a
number. Round your answer to three decimal places.)
(d)What is the expected number of residents in the village you
must meet before you encounter the first person of Hawaiian
ancestry? Hint: Use μ for the geometric
distribution and round. (Enter a number. Round your answer to the
nearest whole number.)
residents
In: Statistics and Probability
Use the geometric probability distribution to solve the
following problem.
On the leeward side of the island of Oahu, in a small village,
about 89% of the residents are of Hawaiian ancestry. Let n
= 1, 2, 3, … represent the number of people you must meet until you
encounter the first person of Hawaiian ancestry in the
village.
(a)
Write out a formula for the probability distribution of the
random variable n. (Enter a mathematical
expression.)
P(n) =
(b)
Compute the probabilities that n = 1, n = 2,
and n = 3. (For each answer, enter a number. Round your
answers to three decimal places.)
P(1) =
P(2) =
P(3) =
(c)
Compute the probability that n ≥
4. Hint: P(n ≥ 4) = 1 −
P(n = 1) − P(n = 2) −
P(n = 3). (Enter a number. Round your answer to
three decimal places.)
(d)
What is the expected number of residents in the village you must
meet before you encounter the first person of Hawaiian ancestry?
Hint: Use μ for the geometric distribution and
round. (Enter a number. Round your answer to the nearest whole
number.)
In: Statistics and Probability
Use the geometric probability distribution to solve the
following problem.
On the leeward side of the island of Oahu, in a small village,
about 72% of the residents are of Hawaiian ancestry. Let n
= 1, 2, 3, … represent the number of people you must meet until you
encounter the first person of Hawaiian ancestry in the
village.
(a)
Write out a formula for the probability distribution of the
random variable n. (Enter a mathematical
expression.)
P(n) =
(b)
Compute the probabilities that n = 1, n = 2,
and n = 3. (For each answer, enter a number. Round your
answers to three decimal places.)
P(1) =
P(2) =
P(3) =
(c)
Compute the probability that n ≥ 4. Hint:
P(n ≥ 4) = 1 − P(n = 1) −
P(n = 2) − P(n = 3). (Enter a
number. Round your answer to three decimal places.)
(d)
What is the expected number of residents in the village you must
meet before you encounter the first person of Hawaiian ancestry?
Hint: Use μ for the geometric distribution and
round. (Enter a number. Round your answer to the nearest whole
number.)
residents
In: Statistics and Probability
A geologist collected 5 specimens of limestone rock and 5 specimens of sandstone. A lab assistant randomly selects 7 specimens for analysis. Let X = the number of sandstone samples that are selected.
a) What is the name of the distribution of X?
b) What is the probability that all specimens of one of the two types of rock are selected?
c) What is the probability that the number of sandstone specimens selected is within 1 standard deviation of its mean value?
In: Statistics and Probability
the number of chocolate chips in an 18 oz bag of chocolate chip cookies is approximately normally distributed with 1270 in the standard deviation is 130 chips
what is the probability that a randomly-selected bag contains no more than 1200 chips
what is the probability that a randomly-selected bag of 30 bags has a random mean that's no more than 1200 chips
what number of chocolate chips in a bag will correspond to the 15th percentile
In: Statistics and Probability
A production line produces monitors, 7% of which have cosmetic defects. A quality manager randomly selects 7 monitors from the production line and is interested in the number of defective parts found.
For questions 2-9 compute the probability for the number of monitors that have a cosmetic defect. (Use 5 decimal places for your answers):
Table 01
| x | f (x) |
| 0 | x0 |
| 1 | x1 |
| 2 | x2 |
| 3 | x3 |
| 4 | x4 |
| 5 | x5 |
| 6 | x6 |
| 7 | x7 |
Compute the probability for x0.
| a. |
0.60170 |
||||||||||
| b. |
0.12500 |
||||||||||
|
c. 0.04955 Based on information in Table 01, compute the probability for x1.
|
Based on information in Table 01, compute the probability for x2.
| a. |
0.12500 |
|
| b. |
0.07159 |
|
| c. |
0.14317 |
Based on information in Table 01 compute the probability for x3.
| a. |
0.53882 |
|
| b. |
0.12500 |
|
| c. |
0.00898 |
Based on information in Table 01 compute the probability for x4.
| a. |
0.00068 |
|
| b. |
0.06759 |
|
| c. |
0.12500 |
Based on information in Table 01 compute the probability for x5.
| a. |
1.25000 × 10-1 |
|
| b. |
3.05264 × 10-5 |
|
| c. |
3.05264 × 10-6 |
Based on information in Table 01 compute the probability for x6.
| a. |
7.65895 × 10-8 |
|
| b. |
1.25000 × 10-1 |
|
| c. |
7.65895 × 10-7 |
Based on information in Table 01 compute the probability for x7.
| a. |
8.23543 × 10-10 |
|
| b. |
8.23543 × 10-08 |
|
| c. |
8.23543 × 10-09 |
Based on information in Table 01 compute the expected value of monitors with cosmetic defects.
| a. |
0.49 |
|
| b. |
1.00 |
|
| c. |
6.51 |
Based on information in Table 01 compute the standard deviation in cosmetic defects in monitors.
| a. |
2.44949 |
|
| b. |
0.44970 |
|
| c. |
0.67506 |
Based on information in Table 01 compute the probability that the maximum number of monitors with cosmetic defects is 3.
| a. |
0.99929 |
|
| b. |
0.00898 |
|
| c. |
0.00710 |
Based on information in Table 01, compute the probability that the number of monitors with cosmetic defects is at least 4.
| a. |
0.00068 |
|
| b. |
0.00071 |
|
| c. |
3.130050 × 10-5 |
Based on information in Table 01, for the next 1000 units what is the expected value of monitors with cosmetic defects?
| a. |
930 |
|
| b. |
70 |
|
| c. |
700 |
In: Statistics and Probability