954,554 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

SuperPop and SuperPush Methods Using Stacks

So i am suppose to write two methods called superPop and superPush. superPop() pops a StarLine object from the stack, sends it to System.out.print, and returns it. superPush() pushes a StarLine object onto the stack, sends it to System.out.print, and returns it. I am continuing to try new things but any help would be greatly appreciated. So far I have this written for this new class I am creating:

import java.io.*;
import java.util.*;

public class AllStars extends MyStack{
  
  public StarLine superPop(){
    if(empty()) {
      throw new EmptyStackException();
    }
    
    System.out.print();
    return; 
  }
  
  public StarLine superPush(StarLine stars){
  
  }


Also here is the Starline class which we are using:

public class StarLine {
 
 int starCount = 0;
 int leadingSpaces = 0;
 
 public StarLine(int n, int m){
  leadingSpaces = n;
  starCount = m;
 }
 
 public String toString(){
  String res = "";
  for (int i=0; i<leadingSpaces; i++)
   res += " ";
  for (int i=0; i<starCount; i++)
   res += "*";
  return res;
 }
 
 public static void main (String[] args) {
  StarLine stars = new StarLine(3,5);
  System.out.print(stars);
  System.out.println();
 }


}
nwalser
Newbie Poster
13 posts since Mar 2010
Reputation Points: 10
Solved Threads: 0
 

What about MyStack? Presumably it implements the push and pop methods, right? If so you need to call pop from superPop, and call push from superPush.

kramerd
Posting Pro in Training
403 posts since Sep 2010
Reputation Points: 49
Solved Threads: 73
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: