Reverse Polish (HP) StyleCalculator - Part 2
The purpose of this assignment is to incorporate an abstractclass and inheritance and add it to the interface of the businesscalculator created in Topic 4.
• Implement a pure abstract stack class named AbstractStack thathas no implementation. It will not have a private array ofdouble, because that is an implementation detail of ArrayStack thatwould not be found in other implementations such as LinkedStack.Nor will it have the constructor publicAbstractClass(int size), or methods public doublepeek(int n) or public int count(), since thesemethods are convenience features that are easily implemented forArrayStack, but not other implementations of stack. Â
• Include the method public double peek(), andadd the method public void clear(), resulting in the followingabstract methods.
o public abstract voidpush(double item) – Standard stack action; Throws an exception ifthe stack is full.
o public abstract double pop()– Standard stack action; Throws an exception if the stack isempty.
o public abstract boolean isEmpty() – Returnstrue if the stack is empty and false otherwise.
o public abstract doublepeek() – returns the value of the item located at the specifiedposition on the stack; throws an exception if the array bounds areexceeded or if a nonexistent element is requested.
o public abstract void clear()– empties the stack if it is not already empty.
• Do not specify a constructor. Depend on the defaultconstructor.
• Modify the existing ArrayStack.java file to include the phrase\"extends AbstractStack.\"
• Add an implementation for the methods void clear() and doublepeek(), which overloads the existing double peek(int n). Provide adefault constructor that creates an array that will hold threeelements.
o public ArrayClass(int size) - constructorthat creates an ArrayClass instance containing an array of thespecified size. Remember that in Java, arrays are indexed from0!
o public push(double item) – standard stackaction; throws an exception if the array bounds are exceeded.
o public double pop() – standard stack action;throws an exception if the array bounds are exceeded.
o public boolean isEmpty() – returns true ifthe stack is empty and false otherwise.
o public double peek(int n) – returns the valueof the item located at the specified position on the stack; throwsan exception if the array bounds are exceeded or if a nonexistentelement is requested; peek(0) will return the top element of thestack.
o public int count() - returns the number ofitems currently pushed onto the stack.
• Modify the existing TestArrayStack.java file to include testsfor void clear() and double peek(). Note that it is easiest to do\"incremental testing\" in which you code a little then test alittle. Â
• Create an interface with additional methods.
• Create a new file called Forth.java. Make this apublicinterface file. Add thefollowing methods to the interface.
o public add() – pops two values from thestack, adds them together, and pushes the result back onto thestack. Throws an exception if there are not at least 2 items on thestack.
o public sub() – pops two values from thestack, subtracts the second number popped from the first numberpopped, and pushes the result back onto the stack. Throws anexception if there are not at least 2 items on the stack.
o public mult() – pops two values from thestack, multiplies them together, and pushes the result back ontothe stack. Throws an exception if there are not at least 2 items onthe stack.
o public div() – pops two values from thestack, divides the second number popped by the first number popped,and pushes the result back onto the stack. Throws an exception ifthere are not at least 2 items on the stack.
o public dup() – peeks at the top value on thestack and pushes a copy of that value onto the stack. Throws anexception if the stack is empty or full.
o public twoDup() – peeks at the top two valueson the stack and pushes a copy of both values onto the stack (inthe same order). Throws an exception if the stack does not have atleast 2 items or room for 2 additional items.
• Create another file called ForthStack.java. Make this fileextend ArrayStack and implementForth. Code concrete implementations of each of the methods in theinterface.
• Test by making a copy of the file TestArrayStack.java and nameit TestForth. Change the name of the class inside the file. Addtests for add, sub, mult, div, dup, and twoDup.
• After thoroughly testing the program, submit theAbstractStack.java, ArrayStack.java, Forth.java, ForthStack.java,and TestForthStack.java files to the instructor.
Previous Array Stack
public class ArrayStack
{
private double[] array;
private int size;
private int num;
  public ArrayStack(int a){
  array = new double[a];
  size = a;
  num = 0;
}
  public void push(double a){
  if (num < size){
  array[num] = a;
  num++;
  System.out.println(\"Success\");
}
  else {
  System.out.println(\"Failure! Stack is full\");
}
}
  public double pop(){
  if (num > 0){
  num--;
  return array[num];
}
  else {
  System.out.println(\"Stack is empty\");
  return -1;
}
}
  public boolean isEmpty(){
  return (num == 0);
}
  public double peek(int n){
  try
{
  if (num > 0)
{
  if (n < 0 || n >= num)
  return -1;
  else
  return array[num-1-n];
}
  else
{
  System.out.println(\"Stack is empty\");
  return -1;
}
}
  catch(Exception e ){
  e.printStackTrace();
}
  return 0;
}
  public int count(){
  return num;
}
}
 Â
 Â
Previous Test Array Stack
public class TestArrayStack{
public static void main(String [] args)
{
  int choice;
  int peek;
  double val,poped;
  boolean empty;
  Scanner sc =new Scanner(System.in);
  ArrayStack as = new ArrayStack(20);
 Â
  while(true){
     System.out.println(\"1. Enter aValue in stack\");
     System.out.println(\"2. Pop aValue\");
     System.out.println(\"3. Check Ifarray is Empty\");
     System.out.println(\"4. PeekFunction\");
     System.out.println(\"5.Exit\n\");
  choice = sc.nextInt();
  switch(choice)
  {
 Â
  case 1:
     System.out.print(\"Enter a value Topush : \");
  val = sc.nextDouble();
  as.push(val);
  break;
  case 2:
  poped = as.pop();
     System.out.println(\"Popped :\"+poped);
  break;
  case 3:
  empty = as.isEmpty();
     System.out.println(\"Empty ?\"+empty);
  break;
  case 4:
     System.out.print(\"Enter a index topeek : \");
  peek = sc.nextInt();
  poped = as.peek(peek);
  if(poped != -1)
     System.out.println(\"Peeked Value :\"+poped);
 Â
  else
     System.out.println(\"Oops it was nota valid index this place is empty\");
  break;
  case 5:
  System.exit(0);
}
}
}
}
What I need is AbstractStack.java, ArrayStack.java, Forth.java,ForthStack.java, and TestForthStack.java
Thank you