Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8865379
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:29:29+00:00 2026-06-14T16:29:29+00:00

The problem I’m trying to solve is building a pyramid centered in the window

  • 0

The problem I’m trying to solve is building a pyramid centered in the window built with individual bricks. With the code blow I expect the there should be 1 brick on the 1st row, two bricks on the 2nd row, 3 on the 3rd row all the way up to 12 bricks on the base of the pyramid. Instead only 1 brick is appearing in the center of the screen. What could I do to correct my code?

import acm.program.*;
import acm.graphics.*;



public class BrickPyramid extends GraphicsProgram{          

        public void run() {
         /** xBrick, yBrick trying to calculate for the center of the window **/ 

         double xBrick = (getWidth() - BRICK_WIDTH) / 2 ;              
         double yBrick = (getHeight() - BRICK_HEIGHT) /2 ; 

         /** getting the size of the brick by multiplying the brick width by brick height **/ 
         double buildingBrick = BRICK_WIDTH * BRICK_HEIGHT; 

           for (int i = 0 ; i <= 12; i ++ ){
               for (int j = 0; j < BRICKS_IN_BASE; j++){

                   double x = i * buildingBrick; 
                   double y = j * buildingBrick; 


               /* adding the brick with starting point xbrick, ybrick **/
                   GRect brick = new GRect (xBrick, yBrick, BRICK_WIDTH, BRICK_HEIGHT);
                   add(brick);

               } 
           }

    }
private static final int  BRICK_WIDTH = 100;
private static final int  BRICK_HEIGHT = 50;
private static final int BRICKS_IN_BASE = 12;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T16:29:31+00:00Added an answer on June 14, 2026 at 4:29 pm

    You construct all of your bricks with this line executed many times:

    GRect brick = new GRect (xBrick, yBrick, BRICK_WIDTH, BRICK_HEIGHT);
    

    but you never change the values of any of the variables passed to the constructor so the bricks are all drawn in the same place.

    You need to change these values for each brick. Maybe use i and j to determine those values?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Problem: I'm trying to integrate a slider (carousel) inside an info window of google
Problem: Been struggling to get my code to load external shaders and it is
Problem in MATLAB Code for solving desired 'n' number of simultaneous equations of the
Problem: I am trying to build a recursive tree using a function and data
Problem is like this: Suppose there are records in dataTable with FruitType as A
Problem is like this: I have two winapi application's. There is only one way
Problem: If I pull my app's toolbar off of the window frame and float
Problem (simplified to make things clearer): 1. there is one statically-linked static.lib that has
Problem: I'm working on a website where there is a dial that displays a
PROBLEM: Here's the code: import matplotlib.pyplot as plt plt.bar([1,2],[5,4]) plt.title('this is a very long

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.