The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | May 2017 |
| Last Sign in: | 405 Weeks Ago, 6 Days Ago |
| Questions Answered: | 66690 |
| Tutorials Posted: | 66688 |
MCS,PHD
Argosy University/ Phoniex University/
Nov-2005 - Oct-2011
Professor
Phoniex University
Oct-2001 - Nov-2016
//Complete the implementation of the ArrayStack class presented in this chapter.
// Specifically, complete the implementations of the peak, isEmpty, size, and toString methods.
//Please fix this so it compiles correctly and tell me what is going wrong!!
import java.io.*;
class ArrayStack
{
int top;
int size;
int max;
int array[]=new int array[];//THIS IS MESSED UP
 Â
ArrayStack(int t,int max)
{
top=t;
size=t;
array = new int[max];
}
 Â
boolean isEmpty()
{
if(top==-1)
return true;
else
return false;
}
 Â
int size()
{
return size;
}
 Â
int peak()
{
return max;
}
 Â
public String toString() //NEED HELP WITH i
{
String a="";
for(i=top;i<=size;i++)
{
int val=this.arr[i];
a=a+val;
}
return a; Â Â
}
 Â
public static void main(String args[])throws IOException
{
ArrayStack b=new ArrayStack(1,10);
boolean empty = b.isEmpty();
if(empty==true)
System.out.println("THIS IS STACK IS EMPTY");
else
System.out.println("THIS STACK IS NOT EMPTY");
 Â
int current=b.size();
System.out.println("CURRENT SIZE: " + current);
 Â
int max=b.peak();
System.out.println("PEAK SIZE: " + max);
 Â
String s=ob.toString();
System.out.println("FINAL STRING: " + a);
 Â
}
}
Hel-----------lo -----------Sir-----------/Ma-----------dam-----------Tha-----------nk -----------You----------- fo-----------r u-----------sin-----------g o-----------ur -----------web-----------sit-----------e a-----------nd -----------and----------- ac-----------qui-----------sit-----------ion----------- of----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n.P-----------lea-----------se -----------pin-----------g m-----------e o-----------n c-----------hat----------- I -----------am -----------onl-----------ine----------- or----------- in-----------box----------- me----------- a -----------mes-----------sag-----------e I----------- wi-----------ll