Please review my code (java)
Someone helped me with it but i cannot get it to compile i tried to separate the code that didnt
work.
package ch02.stacks;
import java.lang.Iterable;
import java.util.*;
import java.lang.*;
import java.io.*;
public class ArrayBoundedStack implements StackInterface
public class StackUnderflowException extends RuntimeException
class StackUnderflowException extends RuntimeException
{
public StackUnderflowException()
{
super();
}
public StackUnderflowException(String message)
{
super(message);
}
}
class StackOverflowException extends RuntimeException
{
public StackOverflowException()
{
super();
}
public StackOverflowException(String message)
{
super(message);
}
}
class ArrayBoundedStack implements StackInterface
{
protected final int DEFCAP = 100; // default capacity
protected T[] elements; // holds stack elements
protected int topIndex = -1; // index of top element in stack
public ArrayBoundedStack()
{
elements = (T[]) new Object[DEFCAP];
}
public ArrayBoundedStack(int maxSize)
{
elements = (T[]) new Object[maxSize];
}
public void push(T element)
// Throws StackOverflowException if this stack is full,
// otherwise places element at the top of this stack.
{
if (isFull())
throw new StackOverflowException(\"Push attempted on a full stack.\");
else
{
topIndex++;
elements[topIndex] = element;
}
}
public void pop()
// Throws StackUnderflowException if this stack is empty,
// otherwise removes top element from this stack.
{
if (isEmpty())
throw new StackUnderflowException(\"Pop attempted on an empty stack.\");
else
{
elements[topIndex] = null;
topIndex--;
}
}
public T top()
// Throws StackUnderflowException if this stack is empty,
// otherwise returns top element of this stack.
{
T topOfStack = null;
if (isEmpty())
throw new StackUnderflowException(\"Top attempted on an empty stack.\");
else
topOfStack = elements[topIndex];
return topOfStack;
}
public boolean isEmpty()
// Returns true if this stack is empty, otherwise returns false.
{
return (topIndex == -1);
}
public boolean isFull()
// Returns true if this stack is full, otherwise returns false.
{
return (topIndex == (elements.length - 1));
}
public String toString()
{
String ans=new String();
int counter=topIndex;
while(counter>=0)
{
ans=ans+elements[topIndex].toString()+\"--\";
counter--;
}
}
public int size()
{
return topIndex+1;
}
public void popSome(int count)
{
if(size()0)
{
elements[topIndex] = null;
topIndex--;
count--;
}
}
public boolean swapStart()
{
if(size()<2)
return false;
T topOfStack = null;
topOfStack=elements[topIndex];
elements[topIndex]=elements[topIndex-1];
elements[topIndex-1]=topOfStack;
return true;
}
public T poptop()
{
if(topIndex==-1)
throw new StackUnderflowException(\"Top attempted on an empty stack.\");
else
{
T t=null;
t=elements[topIndex--];
return t;
}
}
}
public class ArrayBounded
{
public static void main(String args[])
{
Stack s=new ArrayBoundedStack();
s.push(10);
s.push(20);
s.push(30);
System.out.println(s.toString());
System.out.pr.
Latin America, Asia (except Japan), and Africa comprise a set of sta.pdf
Please show your input and output screenshot of matlab. Show all wor.pdf
1. Please show your input and output screenshot of matlab. Show all work!
5. Fill a MATLAB vector array with 1000 Gaussianly distributed numbers (ie, randn and
another with 1000 uniformly distributed numbers (ie, rand. Find the mean and standard deviation
of both sets of numbers. Modify the array of numbers to have a mean value of zero. Confirm it
has a mean of zero and recalculate the standard deviation.
Solution
r = randn(1,1000,'single')
r =
Columns 1 through 13
0.5377 1.8339 -2.2588 0.8622 0.3188 -1.3077 -0.4336 0.3426 3.5784 2.7694 -
1.3499 3.0349 0.7254
Columns 14 through 26
-0.0631 0.7147 -0.2050 -0.1241 1.4897 1.4090 1.4172 0.6715 -1.2075 0.7172
1.6302 0.4889 1.0347
Columns 27 through 39
0.7269 -0.3034 0.2939 -0.7873 0.8884 -1.1471 -1.0689 -0.8095 -2.9443 1.4384
0.3252 -0.7549 1.3703
Columns 40 through 52
-1.7115 -0.1022 -0.2414 0.3192 0.3129 -0.8649 -0.0301 -0.1649 0.6277 1.0933
1.1093 -0.8637 0.0774
Columns 53 through 65
-1.2141 -1.1135 -0.0068 1.5326 -0.7697 0.3714 -0.2256 1.1174 -1.0891 0.0326
0.5525 1.1006 1.5442
Columns 66 through 78
0.0859 -1.4916 -0.7423 -1.0616 2.3505 -0.6156 0.7481 -0.1924 0.8886 -0.7648
-1.4023 -1.4224 0.4882
Columns 79 through 91
-0.1774 -0.1961 1.4193 0.2916 0.1978 1.5877 -0.8045 0.6966 0.8351 -0.2437
0.2157 -1.1658 -1.1480
Columns 92 through 104
0.1049 0.7223 2.5855 -0.6669 0.1873 -0.0825 -1.9330 -0.4390 -1.7947 0.8404 -
0.8880 0.1001 -0.5445