JAVA
Stack - Implementation.
You will be able to use the push, pop and peek of Stack concept. Post-Fix calculator - When an arithmetic expression is presented in the postfix form, you can use a stack to evaluate the expression to get the final value. For example: the expression 3 + 5 * 9 (which is in the usual infix form) can be written as 3 5 9 * + in the postfix. More interestingly, post form removes all parentheses and thus all implicit precedence rules.
Program Implementation Requirements
Use the stack concept to create a post-fix calculator. I will be using a test-harnessPreview the document to run your program. Please make sure it meets the requirements to be run by the test harness.
Test harness:
public class StackCalcTest {
public static void main(String[] args) {
StackCalc stackCalc = new StackCalc();
String[] values = {"3", "5", "9", "*", "+"};
for(int i = 0; i < 5; i++) {
stackCalc.stack.push(values[i]);
}
System.out.println(stackCalc.stack);
System.out.println(stackCalc.answer()); }}
In: Computer Science
The implementations of the methods addAll, removeAll, retainAll are omitted in the MyList interface. Implement these methods.
/** Adds the elements in otherList to this list.
* Returns true if this list changed as a result of the call
*/
public default boolean addAll(Collection<? extends E> c)
/** Removes all the elements in otherList from this list
* Returns true if this list changed as a result of the call
*/
public default boolean removeAll(Collection<?> c)
/** Retains the elements in this list that are also in
otherList
* Returns true if this list changed as a result of the call
*/
public default boolean retainAll(Collection<?> c)
Write a test program that creates two MyArrayLists, list1 and
list2, with the initial values {"Tom", "George", "Peter", "Jean",
"Jane"} and {"Tom", "George", "Michael", "Michelle", "Daniel"},
then perform the following operations:
■ Invokes list1.addAll(list2), and displays list1 and list2.
■ Recreates list1 and list2 with the same initial values, invokes
list1.removeAll(list2), and displays list1 and list2.
■ Recreates list1 and list2 with the same initial values, invokes
list1.retainAll(list2), and displays list1 and list2.
In: Computer Science
Given a standardized normal distribution (with a mean of 0 and a standard deviation of 1), complete parts (a) through (d). Show ALL Work.
a. What is the probability that Z is less than 1.53?
The probability that Z is less than 1.53 is .9370 (Round to four decimal places as needed.)
b. What is the probability that Z is greater than 1.85?
The probability that Z is greater than 1.85 is .0322 (Round to four decimal places as needed.)
c. What is the probability that Z is between 1.53 and 1.85?
The probability that Z is between 1.53 and 1.85 is .0308 (Round to four decimal places as needed.)
d. What is the probability that Z is less than 1.53 or greater than 1.85?
The probability that Z is less than 1.53 or greater than 1.85 is .9692. (Round to four decimal places as needed.)
In: Statistics and Probability
java circular linked list
/*
* Complete the playGame(int players, int passes) method
* Complete the addPlayers(int players) method
* Complete the passPotatoe(int passes) method
* No other methods/variables should be added/modified
*/
public class A3CircleLL {
/*
* Grading:
* Correctly uses helpers to play game - 1pt
* Prints correct winner when game is complete -
0.5pt
*/
public void playGame(int players, int passes) {
/*
* Use the helper methods addPlayers
and passPotatoe to play the game
* Continue passing the potato until
only 1 player remains
* Print the winning players
number
*
* For players = 5 and passes = 3,
the winner should be 1. Players should be removed in this
order:
* - 4, 3, 5, 2
*/
}
/*
* Grading:
* Correctly creates circular linked list of size
amount - 1pt
*/
private void addPlayers(int amount) {
/*
* Set up this method to create a
Node for each player
* The value of each Node, should be
the player number, starting at 1
* For example, if the amount is 5,
there should be Nodes 1-5
* Node 1 should always be set as
the start
* Make list circular by connecting
the last player Node to the first
*/
}
/*
* Grading:
* Correctly removes the player the number of passes
away from the start - 1pt
* Correctly changes the start to the player after the
one being removed - 0.5pt
*/
private void passPotato(int passes) {
/*
* Set up this method to play a
single round of the game
* Move through the list the number
of passes from the start
* Remove the player/Node at this
position
* Set the start equal to the
player/Node after this position
* Do not play a round if there is
one 1 player remaining
* Print the player number that was
removed and the player with the potato
*/
}
private Node start;
private int count;
public A3CircleLL() {
start = null;
count = 0;
}
public String printList() {
String output = "";
if(start != null) {
Node current =
start;
do {
output += current.value + ",";
current = current.next;
}while(current
!= start);
}
return output;
}
public String toString() {
return this.printList();
}
private class Node {
Integer value;
Node next;
public Node(Integer v) {
value = v;
next =
null;
}
}
}
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
public class A3Driver {
public static void main(String[] args) {
A3DoubleLL<Integer> list =
new A3DoubleLL<>();
for(int i = 1; i < 10; i++)
{
list.add(i);
}
System.out.println("Before
Swap");
System.out.println(list.printList());
System.out.println(list.printListRev());
list.swap(4);
System.out.println("After
Swap");
System.out.println(list.printList()
+ ":1,2,3,4,6,5,7,8,9,");
System.out.println(list.printListRev() +
":9,8,7,6,5,4,3,2,1,");
System.out.println();
System.out.println("Hot
Potatoe");
A3CircleLL hotPotato = new
A3CircleLL();
hotPotato.playGame(5, 3);
System.out.println("Correct:");
System.out.println("Removed Player
4\nRemoved Player 3\nRemoved Player 5\nRemoved Player 2\nWinning
player is 1");
System.out.println();
A3Queue<Integer> queue = new
A3Queue<>();
queue.enqueue(5);
queue.enqueue(20);
queue.enqueue(15);
System.out.println(queue.peek()+":5");
System.out.println(queue.dequeue()+":5");
queue.enqueue(25);
System.out.println(queue.dequeue()+":20");
System.out.println(queue.dequeue()+":15");
}
}
In: Computer Science
1. Amy rolls 15 8-sided dice. What is the probability that at least 2 of the rolls are 5s?
Answer: 0.5759
2. Amy shoots 10 arrows at a target. Each arrow hits the target (independently) with probability 0.3. What is the probability that at least 3 of the arrows hit the target?
Answer: 0.6172
3. Amy shoots 64000 arrows at a target. Each arrow hits the target (independently) with probability 0.3. What is the probability that more than 2 of the first 17 arrows hit the target?
Answer: 0.9226
4. Amy tosses 19 biased coins. Each coin comes up heads with probability 0.1. What is the probability that at least 3 of the coins come up heads?
Answer: 0.2946
5. Amy tosses 10 biased coins. Each coin comes up heads with probability 0.5. What is the probability that at most 1 of the coins come up heads?
Answer: 0.0107
In: Statistics and Probability
According to a daily newspaper, the probability is about 0.74 that the favorite in a horse race will finish in the money (first, second, or third place). Complete parts (a) through (j) below.
a. In the next five races, what is the probability that the favorite finishes in the money exactly twice? The probability that the favorite finishes in the money exactly twice is 0.096.
b. In the next five races, what is the probability that the favorite finishes in the money exactly four times? The probability that the favorite finishes in the money exactly four times is 0.390.
c. In the next five races, what is the probability that the favorite finishes in the money at least four times? The probability that the favorite finishes in the money at least four times is 0.611.
d. In the next five races, what is the probability that the favorite finishes in the money between two and four times, inclusive?
The probability that the favorite finishes in the money between two and four times, inclusive, is ____.
(Round to three decimal places as needed.)
In: Math
In this programming challenge you are to create two Python programs: randomwrite.py and randomread.py. One program, randomwrite.py, is to write a set of random numbers to a file. The second program, randomread.py, is to read a set of random numbers from a file, counts how many were read, displays the random numbers, and displays the total count of random numbers.
Random Number File Writer (randomwrite.py)
Create a program called randomwrite.py that writes a series of random integers to a file. The program is to request from the user how many random numbers to generate, the lower bound of the random numbers’ range, and the upper bound of the random numbers’ range. Each random integer value is to be on a separate line and is to be in the range of the inputted lower bound through the inputted upper bound. The file that the random numbers are written to is to be called randomnum.txt.
The user input is to be safe from crashes from invalid input. The user must enter a positive number for all required input (quantity of random numbers to generate, the lower bound of the random numbers’ range, and the upper bound of the random numbers’ range). If invalid input is received the user is to be given feedback and provided with the ability to enter a value again. A positive number is not zero and not negative. The program must not crash if an error occurs during a file operation. Use exception handling.
These are the same requirements for this program:
Example:
How many random numbers do you want? 10
What is the lowest the random number should be: 1
What is the highest the random number should be: 10
The random numbers were written to randomnum.txt
Program 2: Random Number File Reader (randomread.py)
Create a program called randomread.py that reads a series of random numbers from a file called randomnum.txt, counts how many there are, displays the random numbers, and displays the count.
The output to the user is to be labeled and nicely formatted. Prior to displaying the random numbers display the string List of random numbers in randomnum.txt: Each random number is to be displayed on a separate line. The count displayed to the user is to be preceded with the string Random number count:.
Example:
List of random numbers in randomnum.txt:
5
45
32
15
Random number count: 4
The program must not crash if an error occurs during a file operation. Use exception handling. For example, if randomread.py is run and there is no randomnum.txt file the program should handle the exception that occurs when attempting to open the file.
In: Computer Science
Problem 1: Relations among Useful Discrete Probability Distributions. A Bernoulli experiment consists of only one trial with two outcomes (success/failure) with probability of success p. The Bernoulli distribution is
P(X=k) = pkq1-k, k= 0,1
The sum of n independent Bernoulli trials forms a binomial experiment with parameters n and p. The binomial probability distribution provides a simple, easy-to-compute approximation with reasonable accuracy to hypergeometric distribution with parameters N , M and n when n/N is less than or equal to 0.10. In this case, we can approximate the hypergeometric probabilities by a binomial distribution with parameters n and p = M/N . Further, the Poisson distribution with mean μ = np gives an accurate approximation to binomial probabilities when n is large and p is small. Child-abuse victims and developing cancer: Truth or myth? Is physical childhood abuse somehow related to the development of cancer later in life? A recent survey revealed that people who have been physically abused as children were 49% more likely to develop cancer as adults.
Assuming that in some part of Quebec the probability is 0.00007 that a child will develop cancer. Therefore, the number Z among 28 572 children that will develop cancer follows a Binomial distribution with parameters p = 0.00007 and n = 28 572. We would like to use the Poisson distribution to approximate these binomial probabilities.
(a) What is the adequate value of the variance of the Poisson distribution to use in order to approximate the precedent binomial distribution?
(b) Find the probabilities of the 11 first possible values of Z (i.e. Z = 0, 1, …, 10) using both the formulas for the binomial distribution and then the Poisson approximation. Plot the two histograms and make a comparison. Is this approximation close enough? Justify!
(c) Use the Poisson probabilities to approximate the binomial probabilities that among 28 572 children
i. None will develop cancer.
ii. At most two will develop cancer.
(d) Using Poisson approximation, calculate the probability that at least seven in a sample of ten children will not develop cancer. Is it a good approximation? Justify!
In: Statistics and Probability
Question 1
The binomial formula has two parts. The first part of the binomial formula calculates the number of combinations of X successes. The second part of the binomial formula calculates the probability associated with the combination of success and failures. If N=4 and X=2, and p = .5, what is that probability from the second part of the formula?
Group of answer choices
.0625
.5
.3750
.1563
Question 2
Normal Distribution Problem. The birth weight is of newborn babies is approximately normally distributed with a mean of 3.39 kg and a standard deviation of .55kg. Note: my probabilities are exact probabilities. Solutions using the standard normal table will be close.
Low birth rate babies are strongly associated with infant mortality and other complications. A baby that weighs less than 2.5kg is considered low birthweight. What is the probability of a baby less than 2.5kg?
Group of answer choices
1 - .8944
.0125
.4472
.0528
Question 3
Normal Distribution Problem. The birth weight is of newborn babies is approximately normally distributed with a mean of 3.39 kg and a standard deviation of .55kg. Note: my probabilities are exact probabilities. Solutions using the standard normal table will be close.
What is the probability of a baby born weighing less than 3kg?
Group of answer choices
.7609
.5217
.2391
.2609
Question 4
Normal Distribution Problem. Red Blood Cell Counts are expressed millions per cubic millimeter of whole blood. For healthy females, x has a approximately normal distribution with mu = 4.8 and sigma =.3. Note: my probabilities are exact probabilities. Solutions using the standard normal table will be close.
What is the red blood count at the 80th percentile?
Group of answer choices
4.6427
5.1000
5.0525
.5244
Question 5
Normal Distribution Problem. The birth weight is of newborn babies is approximately normally distributed with a mean of 3.39 kg and a standard deviation of .55kg. Note: my probabilities are exact probabilities. Solutions using the standard normal table will be close.
What is the probability of a baby born weighing more than 5.00 kg?
Group of answer choices
.0017
1 - .4983
2.927
.4983
In: Statistics and Probability
1. A population of values has a normal distribution with μ=72μ=72 and σ=3.1σ=3.1. You intend to draw a random sample of size n=154n=154.
Find the probability that a single randomly selected value is
between 71.3 and 71.7.
P(71.3 < X < 71.7) =
Find the probability that a sample of size n=154n=154 is
randomly selected with a mean between 71.3 and 71.7.
P(71.3 < M < 71.7) =
Enter your answers as numbers accurate to 4 decimal places. Answers obtained using exact z-scores or z-scores rounded to 3 decimal places are accepted.
2.
In a recent year, the Better Business Bureau settled 75% of
complaints they received. (Source: USA Today, March 2, 2009) You
have been hired by the Bureau to investigate complaints this year
involving computer stores. You plan to select a random sample of
complaints to estimate the proportion of complaints the Bureau is
able to settle. Assume the population proportion of complaints
settled for the computer stores is the 0.75, as mentioned above.
Suppose your sample size is 278. What is the probability that the
sample proportion will be at least 5 percent more than the
population proportion?
Note: You should carefully round any z-values you calculate to at least 4 decimal places to match wamap's approach and calculations.
Answer =
(Enter your answer as a number accurate to 4 decimal places.)
3.
Business Weekly conducted a survey of graduates from 30 top MBA
programs. On the basis of the survey, assume the mean annual salary
for graduates 10 years after graduation is 165000 dollars. Assume
the standard deviation is 32000 dollars. Suppose you take a simple
random sample of 90 graduates.
Find the probability that a single randomly selected salary that
doesn't exceed 169000 dollars.
Answer =
Find the probability that a sample of size n=90n=90 is randomly
selected with a mean that that doesn't exceed 169000 dollars.
Answer =
Enter your answers as numbers accurate to 4 decimal places.
Thank You
In: Statistics and Probability