0

I can't figure out for the life of me why the names of the square and rectangle won't show up....can anyone help?

public class Square extends NamedShape implements Shape 
{
	public void Length() 
	{
		System.out.printf("Please Enter Length Value: ", this.getLength());
	}
	
	public Square(String name) {
		super(name);
		System.out.printf("Shape:", this.getName());
	}

}

and

public class Rectangle extends NamedShape implements Shape
{
	@Override
	public void Length() 
	{
		System.out.printf("Please Enter Length Value: ");
	}
	
	public Rectangle(String name) {
		super(name);
		System.out.printf("Shape:", this.getName());
	}


}

and finally:

public class AreaFinder {
		private Shape[] shapes;	
		private int population;		
		
		public AreaFinder() {
			shapes = new Shape[100];
		}
		
		public void populate() {
			addShape(new Square("Square"));
			addShape(new Rectangle("Rectangle"));
		}

		private void addShape(Shape a) {
			shapes[population++] = a;
		}
		
		public static void main(String[] args) {
			AreaFinder shapes = new AreaFinder();
			shapes.populate();
		}
		

		public void LengthFinder() 
		{
			System.out.printf("Length Values Called");
			for(int i = 0; i < population; i++) 
			{
				shapes[i].Length();
			}
		}
}
public class NamedShape 
{
	private String name;
	public double length;
	double newlength;
	double side_length;
	
	public String getName() {
		return name;
	}
	
	public Double getLength()
	{
		return newlength;
	}
	
	public NamedShape(double newlength)
	{
		this.length = newlength;
		System.out.printf("\t");		
	}
	
	public NamedShape(String name) {
		this.name = name;
			System.out.printf("\t");
		}
}

Edited by PDB1982: n/a

2
Contributors
8
Replies
9
Views
6 Years
Discussion Span
Last Post by apines
1

You are not using the printf properly - you need to tell the method where do you want the String to be printed. Try this:

public Square(String name) 
{
   super(name);
   System.out.printf("Shape: %s", this.getName());
}

Edited by apines: n/a

0

Should the this.getName() return the name "New Square" that is specified in the AreaFinder class?

0

this.getName() will call the getName() method of the calling instance. Square gets its getName() method from NamedShape, so it will print its name - "Square"

0

That's what I thought, but the output right now is:

Shape:     Shape:
0

yes, If I add the code that you suggested, then it just prints out:

Shape: &s    Shape:
0

I'm so stupid....I was inserting the wrong symbol, because I was trying to go quick...your solution was correct.

Thank You!

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.