Results 1 to 2 of 2

Thread: very basic code

  1. #1
    BlueJ2008 is offline Member
    Join Date
    Oct 2008
    Posts
    2
    Rep Power
    0

    Default very basic code

    Hi im a complete beginner and seem to be falling at the first hurdle here :(
    I am using BlueJ and working with the picture project that the BlueJ book came with.

    1. Add a second sun to the picture. To do this, pay attention to the field definitions close
    to the top of the class. You will find this code:

    private Square wall;
    private Square window;
    private Triangle roof;
    private Circle sun;
    so i added another field -
    private Circle sun;

    Then im being asked to write the appropriate code for creating the second sun, but i cant seem to find any existing code creating the first sun :confused: my attempt at answering is -

    This is in another class named Circle
    Java Code:
     /**
         * Create a new circle at default position with default color.
         */
        public Circle()
        {
            diameter = 30;
            xPosition = 20;
            yPosition = 60;
            color = "blue";
            isVisible = false;
        }
    
    /**
     * create second sun?
     *(my input)
     */
    public Circle sun2()
    {
        diameter = 30;
        xPosition = 40;
        yPosition = 80;
        color = "yellow";
        isVisible = false;
    }
    but i know this is wrong.. can someone point me in the right direction?

  2. #2
    ojn
    ojn is offline Senior Member
    Join Date
    Sep 2008
    Location
    Stockholm, Sweden
    Posts
    119
    Rep Power
    0

    Default

    Do you know how to create new objects? Do you know how the constructor works? Do you know how those two things are connected?

    If the answer is no, you should go back and re-read those chapters, before attempting to write programs you don't understand how they work.

Similar Threads

  1. basic java help
    By adred in forum New To Java
    Replies: 0
    Last Post: 03-08-2008, 01:36 PM
  2. Basic Applet
    By jkswebsite in forum Java Applets
    Replies: 4
    Last Post: 01-13-2008, 10:14 PM
  3. Very basic question
    By gvi in forum New To Java
    Replies: 2
    Last Post: 10-30-2007, 07:30 PM
  4. help with basic java code
    By elizabeth in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 07:47 PM
  5. help with basic example
    By fred in forum New To Java
    Replies: 1
    Last Post: 07-20-2007, 06:45 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
  •