dimanche 8 avril 2018

missing return statement if/else boolean method

Thank you to the community at large here for helping me out in the past, and in advance for my question. You guys rock.

I am building a very basic object right now, and being told I am missing a return statement. I'm sure I'm making a basic mistake, but I'm not sure as to what. Below is what I believe to be the pertinent code.

import java.util.*;

public class Stack
{

   //Object Attributes
   public ArrayList data;
   private int count;
   private int maxSize;
   private boolean verbose;
   String errorlog = "";
   String bic = "";

       //Constructor w/o Parameters
   public Stack()
   {
      this.count = 0;
      this.maxSize = 10;
      ArrayList<Integer> data = new ArrayList<Integer>(10);
      this.verbose = false;

      //Verbose Log
      String bic = "--Constructor w/o Parameter--\n";
      if(verbose)
      {
         errorlog += bic;
         System.out.println(bic);
      }
      else{
         errorlog += bic;}

   }

//Push
   public boolean push(int num_)
   {
      if(this.data.size()<(maxSize))
      {
         this.data.add(num_);
         String bic = "--Push "+num_+"--\n";
      }
      else
      {
         String bic = "--Failed to Push--\n";         
         return false;
      }


      //Verbose Log
      if(verbose)
      {
         errorlog += bic;
         System.out.println(bic);
      }
      else{
         errorlog += bic;}
   }

Aucun commentaire:

Enregistrer un commentaire