0

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();
 }


}
2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by kramerd
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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.