Question: mystack.java import java.util.Arrays; import java.util.EmptyStackException; public final class MyStack { private T[] stack; private int topIndex; private boolean initialized = false; private static final int

 mystack.java import java.util.Arrays; import java.util.EmptyStackException; public final class MyStack { private
T[] stack; private int topIndex; private boolean initialized = false; private static
mystack.java
import java.util.Arrays;
import java.util.EmptyStackException;
public final class MyStack
{
private T[] stack;
private int topIndex;
private boolean initialized = false;
private static final int DEFAULT_CAPACITY = 20;
private static final int MAX_CAPACITY = 5000;
public MyStack()
{
this(DEFAULT_CAPACITY);
} // end default constructor
public MyStack(int initialCapacity)
{
checkCapacity(initialCapacity);
@SuppressWarnings("unchecked")
T[] tempStack = (T[])new Object[initialCapacity];
stack = tempStack;
topIndex = -1;
initialized = true;
}
public void push(T newEntry)
{
checkInitialization();
ensureCapacity();
stack[topIndex + 1] = newEntry;
topIndex++;
}
public T peek()
{
checkInitialization();
if (isEmpty())
throw new EmptyStackException();
else
return stack[topIndex];
}
public T pop()
{
checkInitialization();
if (isEmpty())
throw new EmptyStackException();
else
{
T top = stack[topIndex];
stack[topIndex] = null;
topIndex--;
return top;
}
}
public boolean isEmpty()
{
return topIndex
}
public void clear()
{
checkInitialization();
while (topIndex > -1)
{
stack[topIndex] = null;
topIndex--;
}
}
private void checkInitialization()
{
if (!initialized)
throw new SecurityException ("ArrayStack object is not initialized properly.");
}
private void checkCapacity(int capacity)
{
if (capacity > MAX_CAPACITY)
throw new IllegalStateException("Attempt to create a stack " +
"whose capacity exceeds " +
"allowed maximum.");
}
private void ensureCapacity()
{
if (topIndex >= stack.length - 1)
{
int newLength = 2 * stack.length;
checkCapacity(newLength);
stack = Arrays.copyOf(stack, newLength);
}
}
}
there are two parts of today's exam. You need to turn in this part in order to get the next part. Both input files are on folder Part Il-Step 2: Test your programming skill on File I/O and Stack. (70 points) Continue with the main program of Exam2 and uncomment the three lines related to Step2 and then complete this step according to the following: public class Exam2 ( public static void main (Stringl) args) ( System.out.printin"Exam 2: Step 1 by (Your Name)"): Step1 s1 = new Step1(); //Step 2 System.out.printin("nExam 2: Step 2 by (Your Name)"); String fileName = "xxxxx.txt'.. Step2 s2 = new Step2(fileName); //Step3 //You may refer to the sample output at 4 first. 1. Assign "e2arts.txt" to the fileName. i.e., filename "e2arts.txt" 2. Write a simple class called MyArt which contains the following: a. Two fields: artName, artistName. b. Constructor that takes the values of above two fields. c. toString that prints these two values separated by a tab. 3. Complete Step2 class according to the following: which contains the following lines inside your program: int STACK-SIZE = 20; a. MyStack myArtStack new MyStack(STACK SIZE); //This is your generic stack that you created during our lab hours MyArtistList myArtstList = new MyArtstList("e2artists.txt"); //This is the class that you defined in Unit 1. Remember that this class will read the entire artists into an ArrayList or an array. b. this program logic is similar to processing the transaction file that you did fo project 2. The only difference is that this program will read "e2arts.txt" an the artist name associated with this piece of art. (i.e., in your MyArtistList there are two parts of today's exam. You need to turn in this part in order to get the next part. Both input files are on folder Part Il-Step 2: Test your programming skill on File I/O and Stack. (70 points) Continue with the main program of Exam2 and uncomment the three lines related to Step2 and then complete this step according to the following: public class Exam2 ( public static void main (Stringl) args) ( System.out.printin"Exam 2: Step 1 by (Your Name)"): Step1 s1 = new Step1(); //Step 2 System.out.printin("nExam 2: Step 2 by (Your Name)"); String fileName = "xxxxx.txt'.. Step2 s2 = new Step2(fileName); //Step3 //You may refer to the sample output at 4 first. 1. Assign "e2arts.txt" to the fileName. i.e., filename "e2arts.txt" 2. Write a simple class called MyArt which contains the following: a. Two fields: artName, artistName. b. Constructor that takes the values of above two fields. c. toString that prints these two values separated by a tab. 3. Complete Step2 class according to the following: which contains the following lines inside your program: int STACK-SIZE = 20; a. MyStack myArtStack new MyStack(STACK SIZE); //This is your generic stack that you created during our lab hours MyArtistList myArtstList = new MyArtstList("e2artists.txt"); //This is the class that you defined in Unit 1. Remember that this class will read the entire artists into an ArrayList or an array. b. this program logic is similar to processing the transaction file that you did fo project 2. The only difference is that this program will read "e2arts.txt" an the artist name associated with this piece of art. (i.e., in your MyArtistList

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!