I'm having issues with the abstract class idea...I've attempted to use Eclipse, but this time the IDE is just messing it up.
I've got the files uploaded.
They should be attempted to be compiled as this
1. Container
2. Base Container
3. Height, and color exception
4. Round and square containers
5. client for containers

I have the files uploaded here http://bit.ly/nDiObk


Here is the error I'm getting

ClientForContainers.java:19: SquareBaseContainer is abstract; cannot be instantiated
				BaseContainer aContainer = new SquareBaseContainer(10.0);
				                           ^
ClientForContainers.java:31: RoundBaseContainer is abstract; cannot be instantiated
				aContainer = new RoundBaseContainer(10.0);

SquareBaseContainer is abstract so you can't instantiate it. Eclipse is just following the Java language definition correctly.

Edited 5 Years Ago by JamesCherrill: n/a

when I take out the abstract part...I still get the error.

// Extending the qualities of BaseContainer into SquareBaseContainer
public class SquareBaseContainer extends BaseContainer 

{ 
// Calling declarations that were declared in BaseContainer  
   
public SquareBaseContainer(double aLength, double aHeight, String aColor)
   {
   super(aLength, aHeight, aColor);
   }
   
// Calculates volume for the Square Base Container
// Returns calculations once done.
   public double getVolume()
   {
   	   double SquareBaseVolume = length * length * height;
   	   return SquareBaseVolume;	   
   }
	
// Print Statement For Square Base Container	
   public void printState()
   {
  	System.out.println();  //Whitespace 
  	System.out.println("Height = " + height + " Feet");
  	System.out.println("Volume = " + getVolume()); //Printed from local call
  	System.out.println("Radius = " + length + " Feet");
  	System.out.println("Color = "+ color);
  	System.out.println();  //Whitespace  
   }

Remove the abstract keyword or you can make SquareBaseContainer an interface. By the way, SquareBaseContainer extends BaseContainer, which is also abstract. Remove the abstract keyword from there, too.

Edited 5 Years Ago by tkud: n/a

Remove the abstract keyword or you can make SquareBaseContainer an interface. By the way, SquareBaseContainer extends BaseContainer, which is also abstract. Remove the abstract keyword from there, too.

He has removed the abstract keyword from SquareBaseConstainer.
If he makes it an interface he definitely cannot instantiate it.
You can't remove the abstract keyword from BaseContainer because it has public abstract double getVolume()

when I take out the abstract part...I still get the error.

Exactly what error do you now get?

BaseContainer compiles fine now.

Square and round containers compile and get this error

SquareBaseContainer.java:17: SquareBaseContainer is not abstract and does not override abstract method setLength(double) in Container
public class SquareBaseContainer extends BaseContainer 
       ^
1 error

I must not have implemented setLenth properly.

// Defines an interface of common interactions with all types
// of storage containers.
public interface Container
{
   String legalColors[] = {"green", "blue", "red"};
   double DEFAULT_HEIGHT = 6.0;
   String DEFAULT_COLOR = legalColors[0];
   double MIN_HEIGHT = 6.0, MAX_HEIGHT = 10.0;

   // Returns this container's height.
   double getHeight();

   // Returns this container's color.
   String getColor();
   
   // Returns the length measurement for this container's base.
   double getLength();

   // Sets this container's height. Throws HeightException if
   // aHeight is not in range [6.0,10.0].
   void setHeight(double aHeight) throws HeightException;

   // Sets this container's color. Throws ColorException if color
   // is not "red", "blue", or "green".
   void setColor(String aColor) throws ColorException;
   
   // Sets the length measurement for this container's base.
   void setLength(double aLength);
   
     // Returns this container's volume.
   double getVolume();

   // Prints the attributes of this container on the standard output on a 
   // single line in a manner appropriate to and defined by subclasses of 
   // this class. All numeric values are rounded to the nearest whole unit.
   void printState();
}

Yes, BaseContainer is declared as implementing Container, so all the methods from Container must be defined fully either in BaseContainer or in every non-abstract subclass of BaseContainer.

I get what you are mentioning JamesCherrill, I'm just completely lost.
I've rewritten the program using simpler redundant constructors, and I still get the

SquareBaseContainer.java:4: SquareBaseContainer is not abstract and does not override abstract method setLength(double) in Container
public class SquareBaseContainer extends BaseContainer 
       ^
1 error

Any tips to solve this problem are appreciated

Your SquareBaseContainer class must provide a complete definition for the setLength(double) method. That's because BaseContainer says it implements Container - ie implements all the methods declared in Container. In fact it doesn't implement them, but that's ok because it's abstract. But when you (finally) get to a non-abstract class somebody must have implemented those methods.

I figured that out in BaseContainer by looking at Container

Many thanks for the help pointing it out!

This question has already been answered. Start a new discussion instead.