Hey there,
For some reason when I run this code my output isn't what I want it to be.
Can you please tell me how to fix it or what I can make better to make this code work and output the different shapes that I made a list for. I want the names, color and radius of the shape to display.
Here is my code for all my different classes and the main program:
--- Update ---
/* * Shape Class */ package nov4; import java.io.*; import java.util.*; /** * * @author gavinnagra */ public class Shape { static String name; protected List<Circle> circles; Shape(String name, List<Circle> circles) { this.name = name; this.circles = circles; } public List<Circle> display1() { return circles; } @Override public String toString() { return "Name: " + this.name; } }
/* * Circle Class */ package nov4; public class Circle { String name; String color; double radius; Circle(String name, String color, double radius) { this.name = name; this.color = color; this.radius = radius; } public void display() { System.out.println("Name: " + this.name + "\nRadius: " + this.radius + "\nColor: " + this.color); } @Override public String toString() { return super.toString() + "\nRadius: " + this.radius; } }
/* * MAIN PROGRAM */ package nov4; import java.util.*; public class Nov4 { /** * @param args the command line arguments */ public static void main(String[] args) { Circle c1 = new Circle("One", "Red", 1); Circle c2 = new Circle("Two", "Blue", 2); Circle c3 = new Circle("Three", "Red", 3); Circle c4 = new Circle("Four", "Blue", 4); List <Circle> red_circles = new ArrayList<Circle>(); red_circles.add(c1); red_circles.add(c3); List <Circle> blue_circles = new ArrayList<Circle>(); blue_circles.add(c2); blue_circles.add(c4); Shape red = new Shape("Red", red_circles); Shape blue = new Shape("Blue", blue_circles); System.out.println(red_circles.toString()); } }
Please help urgently if you can this is really bothering me!