Questions
Implement our own stack class patterned after Java's Stack class. Start with a generic class that...

Implement our own stack class patterned after Java's Stack class. Start with a generic class that uses an ArrayList for storage of the elements:

public class StackBox<E>
{
ArrayList<E> stack = new ArrayList<E>();
}

Implement the following methods in StackBox:

boolean empty()
Tests if this stack is empty.

E push(E item)
Pushes an item onto the top of this stack. Returns item pushed.

E pop()
Removes the object at the top of this stack and returns that object as the value of this function. Throws EmptyStackException if empty.

E peek()
Looks at the object at the top of this stack without removing it from the stack. Throws EmptyStackException if empty.

Refer to my slides in class for exact specifications details for each of these methods. For full marks your StackBox must throw exceptions as specified above. Now create an instance of StackBox that holds Integers. Create a menu that looks like this to test your StackBox:

=[==[==[=[=================================]=]==]==]=

=[==[==[=[ Welcome to StackBox ]=]==]==]=

=[==[==[=[=================================]=]==]==]=

Choose...

1. Push a (Integer) to our stack box.

2. Pop a (Integer) off our stack box.

3. Peek at top of the stack.

4. Exit

Defining StackBox as a generic class. [ 1 mark ].  WARNING - your program will NOT be accepted if you don't create and use a generic class StackBox as defined for this assignment.

Implementing the four Stack methods: empty, push. pop, and peek as per their specification including throwing exceptions if specified. [ 2 marks ]

=[==[==[=[=================================]=]==]==]=

=[==[==[=[ Welcome to StackBox ]=]==]==]=

=[==[==[=[=================================]=]==]==]=

Choose...

1. Push a (Integer) to our stack box.

2. Pop a (Integer) off our stack box.

3. Peek at top of the stack.

4. Exit

>> 1

Enter an Integer you want to add to the StackBox >>1

=[==[==[=[=================================]=]==]==]=

=[==[==[=[ Welcome to StackBox ]=]==]==]=

=[==[==[=[=================================]=]==]==]=

Choose...

1. Push a (Integer) to our stack box.

2. Pop a (Integer) off our stack box.

3. Peek at top of the stack.

4. Exit

>> 1

Enter an Integer you want to add to the StackBox >>2

=[==[==[=[=================================]=]==]==]=

=[==[==[=[ Welcome to StackBox ]=]==]==]=

=[==[==[=[=================================]=]==]==]=

Choose...

1. Push a (Integer) to our stack box.

2. Pop a (Integer) off our stack box.

3. Peek at top of the stack.

4. Exit

>> 1

Enter an Integer you want to add to the StackBox >>3

=[==[==[=[=================================]=]==]==]=

=[==[==[=[ Welcome to StackBox ]=]==]==]=

=[==[==[=[=================================]=]==]==]=

Choose...

1. Push a (Integer) to our stack box.

2. Pop a (Integer) off our stack box.

3. Peek at top of the stack.

4. Exit

>> 3

The element currently at the top of the stack is 3   [ 2 mark for correct peek behavior ]

=[==[==[=[=================================]=]==]==]=

=[==[==[=[ Welcome to StackBox ]=]==]==]=

=[==[==[=[=================================]=]==]==]=

Choose...

1. Push a (Integer) to our stack box.

2. Pop a (Integer) off our stack box.

3. Peek at top of the stack.

4. Exit

>> 2

The element 3 was removed from the top of the stack box.

=[==[==[=[=================================]=]==]==]=

=[==[==[=[ Welcome to StackBox ]=]==]==]=

=[==[==[=[=================================]=]==]==]=

Choose...

1. Push a (Integer) to our stack box.

2. Pop a (Integer) off our stack box.

3. Peek at top of the stack.

4. Exit

>> 2

The element 2 was removed from the top of the stack box.

=[==[==[=[=================================]=]==]==]=

=[==[==[=[ Welcome to StackBox ]=]==]==]=

=[==[==[=[=================================]=]==]==]=

Choose...

1. Push a (Integer) to our stack box.

2. Pop a (Integer) off our stack box.

3. Peek at top of the stack.

4. Exit

>> 2

The element 1 was removed from the top of the stack box.

[ 7 MARKS for correct push/pop behavior ]

=[==[==[=[=================================]=]==]==]=

=[==[==[=[ Welcome to StackBox ]=]==]==]=

=[==[==[=[=================================]=]==]==]=

Choose...

1. Push a (Integer) to our stack box.

2. Pop a (Integer) off our stack box.

3. Peek at top of the stack.

4. Exit

>> 2

Stack is empty. Caught EmptyStackException. [ 1 MARK ]

=[==[==[=[=================================]=]==]==]=

=[==[==[=[ Welcome to StackBox ]=]==]==]=

=[==[==[=[=================================]=]==]==]=

Choose...

1. Push a (Integer) to our stack box.

2. Pop a (Integer) off our stack box.

3. Peek at top of the stack.

4. Exit

>> 3

Stack is empty. Caught EmptyStackException. [ 1 MARK ]

=[==[==[=[=================================]=]==]==]=

=[==[==[=[ Welcome to StackBox ]=]==]==]=

=[==[==[=[=================================]=]==]==]=

Choose...

1. Push a (Integer) to our stack box.

2. Pop a (Integer) off our stack box.

3. Peek at top of the stack.

4. Exit

>> 4

In: Computer Science

StackBox Implement our own stack class patterned after Java's Stack class. Start with a generic class...

StackBox

Implement our own stack class patterned after Java's Stack class. Start with a generic class that uses an ArrayList for storage of the elements:

public class StackBox<E>
{
ArrayList<E> stack = new ArrayList<E>();
}

Implement the following methods in StackBox:

boolean empty()
Tests if this stack is empty.

E push(E item)
Pushes an item onto the top of this stack. Returns item pushed.

E pop()
Removes the object at the top of this stack and returns that object as the value of this function. Throws EmptyStackException if empty.

E peek()
Looks at the object at the top of this stack without removing it from the stack. Throws EmptyStackException if empty.

Refer to my slides in class for exact specifications details for each of these methods. For full marks your StackBox must throw exceptions as specified above. Now create an instance of StackBox that holds Integers. Create a menu that looks like this to test your StackBox:

=[==[==[=[=================================]=]==]==]=

=[==[==[=[ Welcome to StackBox ]=]==]==]=

=[==[==[=[=================================]=]==]==]=

Choose...

1. Push a (Integer) to our stack box.

2. Pop a (Integer) off our stack box.

3. Peek at top of the stack.

4. Exit

Marking (The Program will look like as below):-

Defining StackBox as a generic class. [ 1 mark ].

WARNING - your program will NOT be accepted if you don't create and use a generic class StackBox as defined for this assignment.

Implementing the four Stack methods: empty, push. pop, and peek as per their specification including throwing exceptions if specified. [ 2 marks ]

=[==[==[=[=================================]=]==]==]=

=[==[==[=[ Welcome to StackBox ]=]==]==]=

=[==[==[=[=================================]=]==]==]=

Choose...

1. Push a (Integer) to our stack box.

2. Pop a (Integer) off our stack box.

3. Peek at top of the stack.

4. Exit

>> 1

Enter an Integer you want to add to the StackBox >>1

=[==[==[=[=================================]=]==]==]=

=[==[==[=[ Welcome to StackBox ]=]==]==]=

=[==[==[=[=================================]=]==]==]=

Choose...

1. Push a (Integer) to our stack box.

2. Pop a (Integer) off our stack box.

3. Peek at top of the stack.

4. Exit

>> 1

Enter an Integer you want to add to the StackBox >>2

=[==[==[=[=================================]=]==]==]=

=[==[==[=[ Welcome to StackBox ]=]==]==]=

=[==[==[=[=================================]=]==]==]=

Choose...

1. Push a (Integer) to our stack box.

2. Pop a (Integer) off our stack box.

3. Peek at top of the stack.

4. Exit

>> 1

Enter an Integer you want to add to the StackBox >>3

=[==[==[=[=================================]=]==]==]=

=[==[==[=[ Welcome to StackBox ]=]==]==]=

=[==[==[=[=================================]=]==]==]=

Choose...

1. Push a (Integer) to our stack box.

2. Pop a (Integer) off our stack box.

3. Peek at top of the stack.

4. Exit

>> 3

The element currently at the top of the stack is 3   [ 2 mark for correct peek behavior ]

=[==[==[=[=================================]=]==]==]=

=[==[==[=[ Welcome to StackBox ]=]==]==]=

=[==[==[=[=================================]=]==]==]=

Choose...

1. Push a (Integer) to our stack box.

2. Pop a (Integer) off our stack box.

3. Peek at top of the stack.

4. Exit

>> 2

The element 3 was removed from the top of the stack box.

=[==[==[=[=================================]=]==]==]=

=[==[==[=[ Welcome to StackBox ]=]==]==]=

=[==[==[=[=================================]=]==]==]=

Choose...

1. Push a (Integer) to our stack box.

2. Pop a (Integer) off our stack box.

3. Peek at top of the stack.

4. Exit

>> 2

The element 2 was removed from the top of the stack box.

=[==[==[=[=================================]=]==]==]=

=[==[==[=[ Welcome to StackBox ]=]==]==]=

=[==[==[=[=================================]=]==]==]=

Choose...

1. Push a (Integer) to our stack box.

2. Pop a (Integer) off our stack box.

3. Peek at top of the stack.

4. Exit

>> 2

The element 1 was removed from the top of the stack box.

[ 7 MARKS for correct push/pop behavior ]

=[==[==[=[=================================]=]==]==]=

=[==[==[=[ Welcome to StackBox ]=]==]==]=

=[==[==[=[=================================]=]==]==]=

Choose...

1. Push a (Integer) to our stack box.

2. Pop a (Integer) off our stack box.

3. Peek at top of the stack.

4. Exit

>> 2

Stack is empty. Caught EmptyStackException. [ 1 MARK ]

=[==[==[=[=================================]=]==]==]=

=[==[==[=[ Welcome to StackBox ]=]==]==]=

=[==[==[=[=================================]=]==]==]=

Choose...

1. Push a (Integer) to our stack box.

2. Pop a (Integer) off our stack box.

3. Peek at top of the stack.

4. Exit

>> 3

Stack is empty. Caught EmptyStackException. [ 1 MARK ]

=[==[==[=[=================================]=]==]==]=

=[==[==[=[ Welcome to StackBox ]=]==]==]=

=[==[==[=[=================================]=]==]==]=

Choose...

1. Push a (Integer) to our stack box.

2. Pop a (Integer) off our stack box.

3. Peek at top of the stack.

4. Exit

>> 4

In: Computer Science

A few years ago, you got married and bought a house with an adjustable rate mortgage...

  1. A few years ago, you got married and bought a house with an adjustable rate mortgage with the following terms:

           Loan:               $240,000

            Term:              20 years

           Initial Rate:      4%

           Margin:          2% over the Index Rate

           Lifetime Max: 4.5%

The index rate was 2% in year 1, 1.5% in year 2, 4% in year 3, 1% in year 4, and 1% in year 5.

  1. What is your loan balance at year 5?

  1. What is the effective interest rate is paid off after year 5?

In: Finance

Given the following table of possible values for rv Z and the number of possible ways...

  1. Given the following table of possible values for rv Z and the number of possible ways that this value can occur,
    1. Construct the pmf and cdf for this rv
    2. Graph the cdf
    3. Calculate Pr(Z=6)
    4. Calculate Pr(Z=2)
    5. Calculate Pr(Z > 4 or Z ≤ 2)
    6. Calculate Pr( 1 < Z ≤ 6)
    7. Calculate Pr( Z ≤ 3 | Z < 9 )

Z

Count

0

4

1

10

2

16

4

11

6

5

8

3

9

1

In: Statistics and Probability

Two fair six-sided dice are tossed independently. Let M = the maximum of the two tosses...

Two fair six-sided dice are tossed independently. Let M = the maximum of the two tosses (so M(1,5) = 5, M(3,3) = 3, etc.).

(a) What is the pmf of M? [Hint: First determine p(1), then p(2), and so on.] (Enter your answers as fractions.)

m 1 2 3 4 5 6
p(m)                                  


(b) Determine the cdf of M. (Enter your answers as fractions.)F(m) =

     m < 1
     1 ≤ m < 2
     2 ≤ m < 3
     3 ≤ m < 4
     4 ≤ m < 5
     5 ≤ m < 6
     m ≥ 6


Graph the cdf of M.

In: Statistics and Probability

An experiment is conducted to compare the effects of weathering on paint of three different types....

  1. An experiment is conducted to compare the effects of weathering on paint of three different types. To do so, identical surfaces are coated with some paint of each type that has been exposed to four different environments. Measurements of the degree of deterioration we made for each surface. The data set is uploaded to Moodle. What can you say about the different paint types and different environments and their effects on the paint degradation?

    Deterioration Paint Type Environment
    9.42 A 1
    9.14 A 1
    10.82 A 2
    11.82 A 2
    8.51 A 3
    7.4 A 3
    10.08 A 4
    10.11 A 4
    11.37 B 1
    12.43 B 1
    13.56 B 2
    11.31 B 2
    11.14 B 3
    10.55 B 3
    14.7 B 4
    14.35 B 4
    9.85 C 1
    11.84 C 1
    12.13 C 2
    11.34 C 2
    10.09 C 3
    9.03 C 3
    10.87 C 4
    12.7 C 4

    I am trying to do this in Excel but the "Anova: two-factor with replication" test won't work and I can't figure out what I'm doing wrong. I keep getting an error that says "Anova: Two-Factor With Replication - Each sample must contain the same number of rows." Some explanation and help would be greatly appreciated. Thanks.

In: Statistics and Probability

1)When an industry consists of [Raw material producer]-[Supplier]-[Firm]-[Channel], which stage is a downstream player? Select one:...

1)When an industry consists of [Raw material producer]-[Supplier]-[Firm]-[Channel], which stage is a downstream player?

Select one:

1. Channel

2. Supplier

3. Raw material producer

4. Firm

2)Which one is not a benefit of vertical integration strategy?

Select one:

1. Control over production timing across stages

2. Secure flexibility to choose alternative transaction partners

3. A secure source of new materials

4. Simplified procurement and administrative procedures

3)_____________ comprise all the expenses that network users incur in order to establish and maintain platform affiliation.

Select one:

1. Opportunity costs

2. Diversified costs

3. Multi-homing costs

4. Average costs

4)Which one is not a source of first-mover advantages?

Select one:

1. Preemption of assets

2. Significant learning curve effect

3. High level of technological and market uncertainty

4. Buyer switching costs

5. Reputation and brand awareness by consumers

5)In traditional businesses, growth beyond some point usually leads to diminishing returns. However, in the digital age, successful platforms enjoy increasing returns to scale. So we observe mature two-sided network industries are dominated by a handful of large platforms. This phenomenon is called __________________.

Select one:

1. Innovator's dilemma

2. Winner's curse

3. Winner-takes-all

4. Market disruption

In: Operations Management

1. Provide the equation of the line that has slope ? = −4 and passes through the point (−2,1).

 

1. Provide the equation of the line that has slope ? = −4 and passes through the point (−2,1).

2.Rewrite ?(?) = |? − 4| as a piecewise-defined function.

3.Rewrite ln((?4(?2+2) )/??3 ) in terms of simpler logarithms (no powers, products, or quotients inside the logarithm).

4.Test ℎ(?) = −2?^4 + 8? − 3 for symmetry and state your conclusion.

5. If the domain is restricted to the open interval (-pi/2,pi/2),find the range of f(x)=e^tan x

 

In: Math

Nim Game Java, PegClass One variation of the game of Nim, described in Chapter 5 Exercise...

Nim Game Java, PegClass

One variation of the game of Nim, described in Chapter 5 Exercise 12, is played with four
piles of stones. Initially, the piles contain 1, 2, 3, and 4 stones. On each turn, a player may
take 1, 2, or 3 stones from a single pile. The player who takes the last stone loses.
a) Write a program that allows two players to play Nim. Be sure to allow only legal
moves. The program should be written so that it can easily be modified for more
or less than four piles. The program output should look similar to:

Name for player #1: Petra
Name for player #2: Elaine
Board: 1 2 3 4
Petra
Which pile? 3
How many? 2
Board: 1 2 1 4
Elaine
Which pile? 4
How many? 3
Board: 1 2 1 1

You do not need to write the full program but figure out how to display the board as:

XXX|XXX

XXX|XXX XXX|XXX

XXX|XXX XXX|XXX XXX|XXX

XXX|XXX XXX|XXX XXX|XXX XXX|XXX

and as the numbers change

XXX|XXX - represents one stone

changes.

In: Computer Science

IN JAVA A salesman wants to go to five different cities and sell some products. The...

IN JAVA

A salesman wants to go to five different cities and sell some products. The locations of the cities are listed in the following table.

City #

X_location

Y_location

City 1

1

1

City 2

1

3

City 3

4

1

City 4

5

3

City 5

3

5

The distance between two cities is defined as the Euclidean distance. That is:

Distance = sqrt( (x1 – x2)^2 + (y1 – y2)^2 )

For example, the distance between cities 1 and 2 will be:

Distance = sqrt( (11)^2 + (1 – 3)^2 ) = sqrt( 4 ) = 2

The purpose: The salesman starts his journey from city 1. He then has 4 remaining options for the next city (city 2, city 3, city 4, city 5). If he chooses city 3 as the next destination, then he will have 3 remaining options (city 2, city 4, city 5). He wants to travel all the cities and then come back to the start location (City 1). Not all the paths will be a good choice. We want to help the salesman by finding the shortest path (best order of cities to visit (visit all of them once) starting from city 1).

Steps:

Step 1 [7 points]: Create a class City with x and y as the class variables. The constructor with argument will get x and y and will initialize the city. Add a member function getDistanceFrom() to the class that gets a city as the input and finds the distance between the two cities.

city1.getDistanceFrom(city2) will be distance between city 1 and 2.

Step 2 [6 points]: Create 5 city objects and initialize their location (x and y) using the above table. Then put all of the five cities in a vector.

Step 3 [7 points]: Create a two dimensional array or vector DistanceVec of size 5 * 5 and initialize it such that DistanceVec[i,j] is the distance between city_i and city_j. Print the distanceVec and show the distance among all cities.

Step 4 [15 points]: If the salesman starts from the city 1, search all the possible paths and find the optimal path (order of cities to visit) that leads to the minimum total travel distance. Display the found optimal path (order of cities to travel) in your sample run.

In: Computer Science