Results 1 to 11 of 11
  1. #1
    Tyre is offline Member
    Join Date
    Apr 2011
    Posts
    18
    Rep Power
    0

    Default Class enum expected

    I'm having trouble getting this code to run. I have tried lots of things and there is something that I just don't see. If anyone out there can point out why everything past line 22 (except for comments) gets the dreaded red squigglies, I would appreciate it.

    I'm very new to Java (my first program), so small words would be appreciated :)

    Java Code:
    // This project should build a pyramid with a base of 14 blocks
    // of block size 12 x 30 pixels. The pyramid should be centered in the screen.
    
    package pleasework;
    import acm.graphics.*;
    import acm.program.*;
    import java.lang.System;
    
    public class BuildPyramid extends GraphicsProgram {
        private final int BRICK_WIDTH = 30;
        private final int BRICK_HEIGHT = 12;
        private final int BRICKS_IN_BASE = 14;
        BuildShit alpha = new BuildShit();
        
    
        
        public void main() {
           alpha.BuildShit(BRICKS_IN_BASE, BRICK_HEIGHT, BRICK_WIDTH);
        
        }
    }
        private BuildShit() {
                int screenW = getHeight();
                for(int i=0;(i==BRICKS_IN_BASE - 1);i++) {
    
    //starts a for loop that runs as many times as their are bricks in the base
    
                    for(int j = 0; j > ((BRICKS_IN_BASE - 1) - i);j++) {
                        
    //for loop to create a line counting down from bricks in base to one
    
                        int blockPosition = screenW/14 + ((j/2) * BRICK_WIDTH);
                        int rowHeight = (BRICKS_IN_BASE * BRICK_HEIGHT) * (BRICK_HEIGHT * i);
                        GRect rect = new GRect(blockPosition,rowHeight,BRICK_WIDTH,BRICK_HEIGHT);
                        add(rect);
                        System.out.println(rect);
                        blockPosition = blockPosition + BRICK_WIDTH;
                        
                 
    }
                    }
                }

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,658
    Blog Entries
    7
    Rep Power
    21

    Default

    Your curly brackets don't match up.

    kind regards

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    Tyre is offline Member
    Join Date
    Apr 2011
    Posts
    18
    Rep Power
    0

    Default

    Okay I fixed that but it still won't run. What should be the return type of private BuildShit()?

    Also, why can't main find the method?

    Java Code:
    // This project should build a pyramid with a base of 14 blocks
    // of block size 12 x 30 pixels. The pyramid should be centered in the screen.
    
    package pleasework;
    import acm.graphics.*;
    import acm.program.*;
    import java.lang.System;
    
    public class BuildPyramid extends GraphicsProgram {
        private final int BRICK_WIDTH = 30;
        private final int BRICK_HEIGHT = 12;
        private final int BRICKS_IN_BASE = 14;
        BuildShit alpha = new BuildShit();
        
    
        
        public void main() {
           alpha.BuildShit(BRICKS_IN_BASE, BRICK_HEIGHT, BRICK_WIDTH);
        
        }
    
        private BuildShit() {
                int screenW = getHeight();
                for(int i=0;(i==BRICKS_IN_BASE - 1);i++) {
    
    //starts a for loop that runs as many times as their are bricks in the base
    
                    for(int j = 0; j > ((BRICKS_IN_BASE - 1) - i);j++) {
                        
    //for loop to create a line counting down from bricks in base to one
    
                        int blockPosition = screenW/14 + ((j/2) * BRICK_WIDTH);
                        int rowHeight = (BRICKS_IN_BASE * BRICK_HEIGHT) * (BRICK_HEIGHT * i);
                        GRect rect = new GRect(blockPosition,rowHeight,BRICK_WIDTH,BRICK_HEIGHT);
                        add(rect);
                        System.out.println(rect);
                        blockPosition = blockPosition + BRICK_WIDTH;
                        
                 
    }
                    }
                }
    }

  4. #4
    baf06 is offline Member
    Join Date
    Jan 2011
    Location
    Beirut, Lebanon
    Posts
    90
    Rep Power
    0

    Default

    Your method has no parameter, while when calling it you included 3 parameters, and that causes the error
    alpha.BuildShit(BRICKS_IN_BASE, BRICK_HEIGHT, BRICK_WIDTH);
    private BuildShit()
    Click on REP and add to member reputation, if you find their advices/solutions effective.

  5. #5
    Tyre is offline Member
    Join Date
    Apr 2011
    Posts
    18
    Rep Power
    0

    Default

    Okay so how do I fix this? Where in the declaration of BuildShit() do I put them? It is askig me for a return type, so I put void because it shouldn't actually return anything. I just want BuildShit() to draw it's blocks and get out of my life.

    Thanks for the advice!

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

  7. #7
    baf06 is offline Member
    Join Date
    Jan 2011
    Location
    Beirut, Lebanon
    Posts
    90
    Rep Power
    0

    Default

    declare them in the method as such,
    private void BuildShit(int BRICKS_IN_BASE, int BRICK_HEIGHT, int BRICK_WIDTH);
    this way you declare these 3 int and can use them inside the method, always declare anything you need it in the method by parameterizing them.
    Click on REP and add to member reputation, if you find their advices/solutions effective.

  8. #8
    Tyre is offline Member
    Join Date
    Apr 2011
    Posts
    18
    Rep Power
    0

    Default

    Ballin', that really helped, I am getting a grasp on parameters now. Only problem I have at the moment is that nothing shows up on the screen when I run it. Any suggestions?

    Java Code:
    // This project should build a pyramid with a base of 14 blocks
    // of block size 12 x 30 pixels. The pyramid should be centered in the screen.
    
    package pleasework;
    import acm.graphics.*;
    import acm.program.*;
    
    public class BuildPyramid extends GraphicsProgram {
        private final double BRICK_WIDTH = 30;
        private final double BRICK_HEIGHT = 12;
        private final double BRICKS_IN_BASE = 14;
    
    
    
        public void main() {
           BuildShit(BRICKS_IN_BASE, BRICK_HEIGHT, BRICK_WIDTH);
        
        }
    
        private void BuildShit(double BRICKS_IN_BASE,double BRICK_HEIGHT,double BRICK_WIDTH) {
                int screenW = getHeight();
                for(int i=0;(i==BRICKS_IN_BASE - 1);i++) {
    
    //starts a for loop that runs as many times as their are bricks in the base
    
                    for(int j = 0; j > ((BRICKS_IN_BASE - 1) - i);j++) {
                        
    //for loop to create a line counting down from bricks in base to one
    
                        double blockPosition = screenW/14 + ((j/2) * BRICK_WIDTH);
                        double rowHeight = (BRICKS_IN_BASE * BRICK_HEIGHT) * (BRICK_HEIGHT * i);
                        GRect rect = new GRect(blockPosition,rowHeight,BRICK_WIDTH,BRICK_HEIGHT);
                        add(rect);
                        System.out.println(rect);
                        blockPosition = blockPosition + BRICK_WIDTH;
                        
    
    }
                    }
                }
    }

  9. #9
    baf06 is offline Member
    Join Date
    Jan 2011
    Location
    Beirut, Lebanon
    Posts
    90
    Rep Power
    0

    Default

    before going deep into your code I can say that you will face an error with the doubles you declared, since a double should be written as 30.0 for example, didn't you face that error ?
    Click on REP and add to member reputation, if you find their advices/solutions effective.

  10. #10
    baf06 is offline Member
    Join Date
    Jan 2011
    Location
    Beirut, Lebanon
    Posts
    90
    Rep Power
    0

    Default

    another thing I noticed
    for(int i=0;(i==BRICKS_IN_BASE - 1);i++)
    this loop doesn't work since you have to pass through every number <= than bricks in the base right? But here you are stating that you perform the action if i = 0 and if == BRICK_IN
    _BASE-1 and not for every number till you reach that number. Try that and tell me what you get
    Click on REP and add to member reputation, if you find their advices/solutions effective.

  11. #11
    baf06 is offline Member
    Join Date
    Jan 2011
    Location
    Beirut, Lebanon
    Posts
    90
    Rep Power
    0

    Default

    another notice :
    for(int j = 0; j > ((BRICKS_IN_BASE - 1) - i);j++) {

    //for loop to create a line counting down from bricks in base to one
    this never works read tutorials about for loops and you will know that when counting downward you should state this code :
    for (int i = maximum_number; i > 0; i--)
    this will loop from the greatest number of bricks to one brick. Isn't this what you want ?
    Last edited by baf06; 04-16-2011 at 07:27 PM.
    Click on REP and add to member reputation, if you find their advices/solutions effective.

Similar Threads

  1. Replies: 2
    Last Post: 10-02-2010, 02:13 AM
  2. class, interface or enum expected?
    By Addez in forum New To Java
    Replies: 2
    Last Post: 08-26-2009, 07:54 PM
  3. Replies: 1
    Last Post: 05-31-2009, 02:17 PM
  4. Replies: 16
    Last Post: 05-28-2009, 03:41 PM
  5. Replies: 9
    Last Post: 08-08-2007, 07:16 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
  •