Results 1 to 6 of 6
  1. #1
    Join Date
    Dec 2008
    Posts
    10
    Rep Power
    0

    Default Constructor with unknown amount of objects?

    Ok, as a project for my programming class i was given te job to create a Point class then creating a circle class and then making a drawing class. This drawing class would consist of multiple circle objects that would then be stored in an array. To be honest i am utterly at a road block as to how make this constructor. i have tried...

    Java Code:
    import java.util.Scanner;
    
    public class Dessin {
    Scanner scan = new Scanner(System.in);
    int i;
        public Dessin(int size) 
        {
        Cercle[] tab = new Cercle[size];
        for (i=0;i<tab.length;i++);
        {
        	
        	double x=scan.nextDouble();	double y=scan.nextDouble(); double z=scan.nextDouble();
        	tab[i]=new Cercle(x,y,z);
        	
        }
        }
    No doubt this thinking is VERY flawed, i believe that my Dessin constructor should receive a circle(x coordinates, its y and its radius), and maybe a double to say how many to make.

    I am up for any suggestions on ways to do this constructor, this is a learning experience so any input on better way of doing things would be appreciated. Thank you

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    I think what's causing you (and me) problems, is that you have no idea how to initialize all of the Circles. How do you know how big they should be? How do you know where they should be located?

    Well, were you given any clues about this from your instructor? Are they supposed to be random size and location?

    Much luck.

  3. #3
    Join Date
    Dec 2008
    Posts
    10
    Rep Power
    0

    Default

    Ok, the bes ti can do is translate as exactly as possible the question one the paper( its french), honestly i find it a bit badly written. For reference a Dessing is a Drawing

    . Create a class Dessin that represents a drawing on a "plan" , a Dessing is composed of multiple Circles. The circles of the Dessin must be stored in an array.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    It doesn't say anything it seems about how to get any of the Circles' data. In this situation, I'd punt and just create your circles but use a default constructor.

    Without knowing more, I'd avoid getting user input via a console (such as with a Scanner object) inside of the constructor. What if this is for a GUI program where there really isn't supposed to even be a console?

  5. #5
    Join Date
    Dec 2008
    Posts
    10
    Rep Power
    0

    Default

    The ultimate objective of this project is to display these "Drawings" threw the use of Jframe. Im not quite there yet but i need to get threw the drawing part first,ill email my teacher to try and clarify the question

    Any idea what i should ask in this email

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Hm, I'd ask him just what should be passed to the Drawing class's constructor? The number of circles? Anything about their location or size? Or will we just create an empty array of Circle and fill it with Circle objects as the program is run (perhaps through mouse interaction or through random generation of Circles)?

    Good luck

Similar Threads

  1. java.net.MalformedURLException: unknown protocol: ntp
    By Nicholas Jordan in forum Networking
    Replies: 6
    Last Post: 12-24-2008, 03:35 AM
  2. Replies: 0
    Last Post: 08-21-2008, 01:26 PM
  3. Replies: 0
    Last Post: 12-19-2007, 09:10 AM
  4. iteration on huge amount of files in a folder
    By tshaked in forum Advanced Java
    Replies: 1
    Last Post: 08-07-2007, 07:08 PM
  5. Unknown publisher / Signing standalone tomcat.exe
    By millross in forum New To Java
    Replies: 1
    Last Post: 06-14-2007, 02:25 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •