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


}

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.