Questions
Create a ShoppingCart class in java that simulates the operation of a shopping cart. The ShoppingCart...

Create a ShoppingCart class in java that simulates the operation of a shopping cart. The ShoppingCart instance should contain a BagInterface implementation that will serve to hold the Items that will be added to the cart. Use the implementation of the Item object provided in Item.java. Note that the price is stored as the number of cents so it can be represented as an int (e.g., an Item worth $19.99 would have price = 1999).

**PLEASE USE THE CLASSES BELOW*** to show Your shopping cart should support the following operations:

  •  Add an item

  •  Add multiple quantities of a given item (e.g., add 3 of Item __)

  •  Remove an unspecified item

  •  Remove a specified item

  • Checkout – should "scan" each Item in the shopping cart (and display its ***IMPORTANT

    information), sum up the total cost and display the total cost

  •  Check budget – Given a budget amount, check to see if the budget is large ***IMPORTANT

    enough to pay for everything in the cart. If not, remove an Item from the shopping cart, one at a time, until under budget.

    Write a driver program to test out your ShoppingCart implementation.

*Item Class*

/**

* Item.java - implementation of an Item to be placed in ShoppingCart

*/

public class Item

{

private String name;

private int price;

private int id;//in cents

  

//Constructor

public Item(int i, int p, String n)

{

name = n;

price = p;

id = i;

}

  

public boolean equals(Item other)

{

return this.name.equals(other.name) && this.price == other.price;

}

  

//displays name of item and price in properly formatted manner

public String toString()

{

return name + ", price: $" + price/100 + "." + price%100;

}

  

//Getter methods

public int getPrice()

{

return price;

}

public String getName()

{

return name;

}

}

BAG INTERFACE CLASS

/**

* BagInterface.java - ADT Bag Type

* Describes the operations of a bag of objects

*/

public interface BagInterface<T>

{

//getCurrentSize() - gets the current number of entries in this bag

// @returns the integer number of entries currently in the bag

public int getCurrentSize();

  

//isEmpty() - sees whether the bag is empty

// @returns TRUE if the bag is empty, FALSE if not

public boolean isEmpty();

  

//add() - Adds a new entry to this bag

// @param newEntry - the object to be added to the bag

// @returns TRUE if addition was successful, or FALSE if it fails

public boolean add(T newEntry);

  

//remove() - removes one unspecified entry from the bag, if possible

// @returns either the removed entry (if successful), or NULL if not

public T remove();

  

//remove(T anEntry) - removes one occurrence of a given entry from this bag, if possible

// @param anEntry - the entry to be removed

// @returns TRUE if removal was successful, FALSE otherwise

public boolean remove(T anEntry);

  

//clear() - removes all entries from the bag

public void clear();

  

//contains() - test whether this bag contains a given entry

// @param anEntry - the entry to find

// @returns TRUE if the bag contains anEntry, or FALSE otherwise

public boolean contains(T anEntry);

  

//getFrequencyOf() - count the number of times a given entry appears in the bag

// @param anEntry - the entry to count

// @returns the number of time anEntry appears in the bag

public int getFrequencyOf(T anEntry);

  

//toArray() - retrieve all entries that are in the bag

// @returns a newly allocated array of all the entries in the bag

// NOTE: if bag is empty, it will return an empty array

public T[] toArray();

  

}

In: Computer Science

Consider the random variable y = the number of broken eggs in a randomly selected carton...

Consider the random variable y = the number of broken eggs in a randomly selected carton of one dozen eggs. Suppose the probability distribution of y is as follows.

y 0 1 2 3 4
p(y) 0.66 0.19 0.11 0.03 ?

(a)

Only y values of 0, 1, 2, 3, and 4 have probabilities greater than 0. What is p(4)? (Hint: Consider the properties of a discrete probability distribution.)

(b)

How would you interpret p(1) = 0.19?

If you check a large number of cartons, the proportion that will have at most one broken egg will equal 0.19.The proportion of eggs that will be broken in each carton from this population is 0.19.    In the long run, the proportion of cartons that have exactly one broken egg will equal 0.19.The probability of one randomly chosen carton having broken eggs in it is 0.19.

(c)

Calculate P(y ≤ 2), the probability that the carton contains at most two broken eggs.

Interpret this probability.

If you check a large number of cartons, the proportion that will have at most two broken eggs will equal 0.96.The probability of two randomly chosen cartons having broken eggs in them is 0.96.    In the long run, the proportion of cartons that have exactly two broken eggs will equal 0.96.The proportion of eggs that will be broken in any two cartons from this population is 0.96.

(d)

Calculate P(y < 2), the probability that the carton contains fewer than two broken eggs.

Why is this smaller than the probability in part (c)?

This probability is less than the probability in Part (c) because the proportion of eggs with any exact number of broken eggs is negligible.This probability is not less than the probability in Part (c) because the two probabilities are the same for this distribution.    This probability is less than the probability in Part (c) because in probability distributions, P(yk) is always greater than P(y < k).This probability is less than the probability in Part (c) because the event y = 2 is now not included.

(e)

What is the probability that the carton contains exactly 10 unbroken eggs? (Hint: What is the corresponding value of y?)

(f)

What is the probability that at least 10 eggs are unbroken?

In: Statistics and Probability

Can someone please answer these 3 by Friday? Problem 2 Let D, E, F, G, and...

Can someone please answer these 3 by Friday?

Problem 2 Let D, E, F, G, and H be events such that P(D) = 0.7, P(E) = 0.6, P(F) = 0.8, P(G) = 0.9, and P(H) = 0.5. Suppose that Dc, E, Fc, Gc, and H are independent.
(a) Find the probability that all of the events D, E, F, G, and H occur.
(b) Find the probability that at least one of the events D, E, F, G, and H occurs.

Problem 3 Five men and five women are ranked according to their scores on an examination. Assume that no two scores are alike, and all 10! possible rankings are equally likely. Let X denote the highest ranking achieved by a woman (for example, X = 2 if the top-ranked person was a man, and the next-ranked person was a woman). Find the probability mass function (pmf) of the random variable X, and plot the cumulative distribution function (cdf) of X.

Problem 4 Suppose there are three cards numbered 2, 7, 10, respectively. Suppose you are to be offered these cards in random order. When you are offered a card, you must immediately either accept it or reject it. If you accept a card, the process ends. If you reject a card, then the next card (if there is one) is offered. If you reject the first two cards, you have to accept the final card. You plan to reject the first card offered, and then to accept the next card if and only if its value is greater than the value of the first card. Let X be a number on the card you have accepted in the end. Find the pmf of X and plot the cdf of X.

In: Statistics and Probability

Let X be the number of Heads when we toss a coin 3 times. Find the...

Let X be the number of Heads when we toss a coin 3 times. Find the probability distribution (that is, the probability function) for X

In: Statistics and Probability

Three fair dice colored red, blue and green are rolled. 1. What will you choose the...

Three fair dice colored red, blue and green are rolled.

1. What will you choose the sample space to be in this case? How many atomic events are there in the sample space? What probability distribution will you use to model this problem?

2. What is the probability that exactly two of the dice roll the same number?

3. What is the probability that all three dice roll distinct numbers?

4. What is the probability that at least two of the dice roll the same number?

Give explanations for all your answers and show all the steps involved.

In: Statistics and Probability

The investing activities of THE WALL STREET JOURNAL INTERACTIVE EDITION subscribers show that the average annual...

The investing activities of THE WALL STREET JOURNAL INTERACTIVE EDITION subscribers show that the average annual number of stock transactions is approximately 15. Suppose a certain investor transacts this frequently. In addition, suppose that the probability of a transaction, for this investor, is the same for any two months, and that the transactions in one month are independent of those that it makes in any other month.
a. What is the average number of transactions per month?
b. What is the probability that there will be no stock transactions for a month?
c. What is the probability that there will be exactly one transaction for a month
d. What is the probability that there will be more than one transaction per month

In: Statistics and Probability

1. In selecting a card form a regular deck of cards, the event of "drawing a...

1. In selecting a card form a regular deck of cards, the event of "drawing a queen" and the event of "drawing a king" are mutually exclusive.

True

False

2. Suppose we toss a coin a large number of times and we use the observed number of tails to help compute the probability of a tail occurring when this coin is tossed. This approach to probability is known as the ___________ concept of probability.

A.

Classical

B.

Relative Frequency

C.

Subjective

3. If a regular six-sided die is rolled and the outcomes are equally likely, then this is an example of ___________ probability.

A.

Classical

B.

Relative Frequency

C.

Subjective

In: Statistics and Probability

Consider two independent experiments testing for two different and independent genetic mutations in rabbits. • •Experiment...

Consider two independent experiments testing for two different and independent genetic mutations in rabbits. •

•Experiment A: Tests 12 rabbits for a mutation that occurs with probability 0.1. Let X be the number of these rabbits w/ this mutation.

• Experiment B: Tests 16 rabbits for a mutation that occurs with probability 0.25. Let Y be the number of these rabbits w/ this mutation.

(a) Compute P(X ≤ 6)

(b) Compute P(10 ≤ Y ).

(c) Compute the joint probability P(X = 4, Y = 6).

(d) Compute the joint probability P(X ≤ 3 and Y ≤ 4).

In: Statistics and Probability

Suppose that the number of requests for assistance received by a towing service is a Poisson...

Suppose that the number of requests for assistance received by a towing service is a Poisson process with rate α = 6 per hour.

a) Find expected value and variance of the number of requests in 30-minutes. Then compute the probability that there is at most one request in 30-minute interval. Clearly state the random variable of interest using the context of the problem and what probability distribution it follows.

b) What is the probability that more than 20 minutes elapse between two successive requests? Clearly state the random variable of interest using the context of the problem and what probability distribution it follows.

In: Statistics and Probability

Suppose that in any given period an unemployed person will find a job with probability .6...

  1. Suppose that in any given period an unemployed person will find a job with probability .6 and will therefore remain unemployed with a probability of .4. Additionally, persons who find themselves employed in any given period may lose their job with a probability of .3 and will have a .7 probability of remaining employed.

    1. Set up the Markov transition matrix for this problem

    2. There are 1000 people in the economy. At period 0, half of the

      population is unemployed, what will be the number of unemployed

      people after 1 period?

    3. What will be the number of unemployed people after 4 period?

    4. What is the steady-state level of unemployment?

In: Advanced Math