Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Creating a house using BlueJ Shapes

    Hi all! I'm very new to java coding, and I was assigned the task of making a house using the shapes folder example in BlueJ. My code is meant to use four square shapes, a triangle and a circle to form a house. However, the problem that I'm having is that when I try to create the house (both one and two window variants), only the roof (triangle) and the sun (circle) show. It's beyond my understanding just what has gone wrong, though I'm sure it's something simple that I'm overlooking.

    Code:
     
     /**
     * MyPicture class has as attributes a number of shapes
     * and uses them to create pictures
     *
     * Name
     * Date
     */
    public class MyPicture
    
    {
        private Square Square1;
        private Square Square2;
        private Square Square3;
        private Square Square4;
        private Circle Circle1;
        private Triangle Triangle1;
       
       
        /**
         * Instantiates a new MyPicture object. This is a default constructor
         * that only gives values to one of the object's attributes - a circle
         * which is given the colour yellow and made visible.
         * The other attributes are set to NULL.
         */
       
       
        public MyPicture()
        {
            Circle1 = new Circle();
            Circle1.changeColor("yellow");
            Circle1.makeVisible();
        }
     
         /**
         * A basic, one windowed house is created, consisting of two squares and triangles
         * which assigned integer values and then individually set to be visible.
         */public void createOneWindowHouse(){
            Square1 = new Square(110, 60, 90, "red");            
            //Creates 'square1'
            Square2 = new Square(30, 70, 110, "black");           
            //Creates 'square2'
            Triangle1 = new Triangle(50, 150, 114, 40, "yellow"); 
            //Creates 'triangle1'
            Square1.makeVisible();                               
            //Enables visibility for 'square1'
            Square2.makeVisible();                               
            //Enables visibility for 'square2'
            Triangle1.makeVisible();                             
            //Enables visibility for 'triangle1'
        }
       
         /**
         * A varied version of the one windowed house is created, which creates a new square located
         * to the right of the first square in order to create a two windowed house. 
         */public void createTwoWindowHouse(){
            Square1 = new Square(110, 60, 90, "red");             
            //Creates 'square1'
            Square2 = new Square(30, 70, 110, "black");            
            //Creates 'square2'
            Square3 = new Square(30, 115, 110,"black");          
            //Creates 'square3'
            Square4 = new Square(12, 60, 60, "black");
            //Creates 'square4'
            Triangle1 = new Triangle(50, 150, 114, 40, "yellow");  
            //Creates 'triangle1'
            Square1.makeVisible();                                
            //Enables visibility for 'square1'
            Square2.makeVisible();                                
            //Enables visibility for 'square2'
            Square3.makeVisible();                                
            //Enables visibility for 'square3'
            Triangle1.makeVisible();                              
            //Enables visibility for 'triangle1'
        }
    
        /**
         * This allows the user to select the colour of the porch. 
         */public void changePorchColour(String colour){
         Square4.changeColor(colour);
         
         //Changes the colour of square4, which represents the porch. 
        
        }
        
        /**
         * Depending on which value that users input, a one or two windowed house is created. 
         */public void chooseAHouse(int choice){
           
            if (choice==1){
                createOneWindowHouse();  
                //When the chosen value is 1, this method is performed
            }
            else if (choice==2) {
                createTwoWindowHouse();      
                //When the chosen value is 2, this method is performed
            }
           
            else if (choice!=1 && choice!=2){       
                System.out.println("ERROR!  input must be either 1 or 2");    
                // If value is not equal to choice 1 or choice 2, the error message is displayed. 
           
            }
        }
       
        /**
         * This changes the colour of the roof by selecting valid colours (e.g. "blue", "red", "green").
         */public void changeRoofColour(String colour){
       
        Triangle1.changeColor(colour);
       //Changes the colour of the triangle which was used to create the roof
    }
     
        /**
         * This changes the colour of the roof by entering a valid number from 1-6.
         * (e.g. 1 = black, 6= white)
         * If the input is an invalid number, an error message is displayed. 
         */public void changeRoofColour2(int choice){
         
         if (choice==1){ 
            Triangle1.changeColor("black");
            }
         else if (choice==2){
             Triangle1.changeColor("red");
            }
         else if (choice==3){ 
              Triangle1.changeColor("blue");
            }
         else if (choice==4){ 
             Triangle1.changeColor("yellow");
            }
         else if (choice==5){ 
             Triangle1.changeColor("green");
            }
          else if (choice==6){ 
             Triangle1.changeColor("white");
            }
          else{
             System.out.println("ERROR! input must be between 1 and 6");
            }
        }
       
        
        
    }
    If anybody can help me with this I'd be very grateful. Thanks in advance!

  • #2
    Regular Coder
    Join Date
    May 2012
    Location
    France
    Posts
    216
    Thanks
    0
    Thanked 29 Times in 27 Posts
    Java (which is to a dance was developed in France in the early part of the 20th century) is not javascript !

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,730
    Thanks
    202
    Thanked 2,508 Times in 2,486 Posts
    This is the JavaScript forum. Java and Javascript are entirely different programming languages, in spite of the confusingly similar names. Rather like Austria and Australia! Ask a mod to move this thread to the right forum.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #4
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Philip M View Post
    This is the JavaScript forum. Java and Javascript are entirely different programming languages, in spite of the confusingly similar names. Rather like Austria and Australia! Ask a mod to move this thread to the right forum.
    Oh dear that's quite embarrassing. How do I go about getting a mod to move my thread? It's been a long time since I've used a forum!

  • #5
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,978
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Quote Originally Posted by kthreeone View Post
    Oh dear that's quite embarrassing. How do I go about getting a mod to move my thread? It's been a long time since I've used a forum!
    I'll take care of moving it, then review it.

    I won't be able to run this code since there isn't enough here. Are these painted onto a gui or are these handled in the CLI? The output for the errors looks like the CLI is in use here, but colour is not fun on the CLI.

    Edit:
    BTW, I won't be able to look at this until tomorrow now as I have to go bake a cheesecake. But check and see where you are calling all of this step it through a debugger and verify that the shapes are set properly. I'm assuming its a GUI in use here which would tell me its something to do with the painting, but unfortunately we can't see where the painting is occurring (or how; this object isn't a paintable type, but has no access to these items within it individually).
    Edit:
    Unless its just textual output? For which we'd definitely need to see how its accessing.

    Last edited by Fou-Lu; 11-28-2012 at 03:58 AM.


  •  

    Posting Permissions

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