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

  • Home
  • SEARCH
  • 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 8939335
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:48:11+00:00 2026-06-15T10:48:11+00:00

The code below appears in my book in the chapter about Methods. I’m a

  • 0

The code below appears in my book in the chapter about Methods. I’m a little confused about a couple of things.

  1. Is my understanding correct when I believe that the run() method is calling the createFilledCircle method?
  2. Is the run() method the receiver and the createFilledCircle the sender?
  3. for the three add(createFilledCircles...red,yellow and green); how does the programmer know what information is permitted in the argument? Is the format of (x location, y location, width of figure, height of figure) being used in the add(createFilledCircle)?

import acm.program.*;
import acm.graphics.*;
import java.awt.*;

public class StopLight extends ConsoleProgram {
  public void run() {
    double cy = getWidth() / 2 ;
    double cx=  getHeight() / 2; 

    double fx = cx - (FRAME_WIDTH / 2);
    double fy = cy - (FRAME_HEIGHT /2 );

    double dy = (FRAME_HEIGHT / 4 ) + (LAMP_RADIUS / 2);

    GRect frame = new GRect (fx, fy, FRAME_WIDTH, FRAME_HEIGHT);
    frame.setFilled(trye);
    frame.setColor(Color.GRAY);
    add(frame);

    add(createFilledCircle(cx, cy-dy, LAMP_RADIUS, Color.RED));
    add(createFilledCircle(cx, cy, LAMP_RADIUS, Color.YELLOW));
    add(createFilledCircle(cx, cy + dy, LAMP_RADIUS, Color.GREEN));
  }

  private GOval createFilledCircle (double x, double y, double r, Color color) {
    GOval circle = new GOval (x -r, y -r, 2 * r, 2 * y );
    circle.setFilled(true);
    circle.setColor(color);
    return circle; 
  }

  private static final double FRAME_WIDTH = 50; 
  private static final double FRAME_HEIGHT = 100;
  private static final LAMP_RADIUS = 10; 
}
  • 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-15T10:48:12+00:00Added an answer on June 15, 2026 at 10:48 am

    1) Is my understanding correct when I believe that the run() method is calling the createFilledCircle method?

    Yes.

    2) Is the run() method the receiver and the createFilledCircle the sender?

    I don’t know what you mean by “receiver” and “sender”. Those are not terms that people normally use when talking about methods being called.

    (It looks like teminology from the Smalltalk programming language, which was an early object oriented language. In the light of that, it’s exactly the other way around: you’d say run is the sender and createFilledCircle is the receiver.)

    3) for the three add(createFilledCircles…red,yellow and green); how does the programmer know what information is permitted in the argument? Is the format of (x location, y location, width of figure, height of figure) being used in the add(createFilledCircle)?

    The declaration of the createFilledCircle method specifies what parameters that method needs: three double values and a Color value.

    In a line such as this one:

    add(createFilledCircle(cx, cy-dy, LAMP_RADIUS, Color.RED));
    

    what happens is that createFilledCircle is called first, with the arguments cx, cy-dy, LAMP_RADIUS, Color.RED, and then the return value of the method createFilledCircle, which is a GOval value, is passed to the add method. It’s the same as this:

    GOval result = createFilledCircle(cx, cy-dy, LAMP_RADIUS, Color.RED);
    add(result);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

With the code below, the console is hidden BUT it appears for about 1
The below code give me a foreach error. What appears to be the issue
As far as I am aware the code below appears to do what I
When I run the code below outside of timeit(), it appears to complete instantaneously.
The code below is valid: IEnumerable<SomeThing> things = ...; // map type SomeThing to
The code below appears to work - that is, fill an outer List with
the code below is from an assignment in my text book for a simple
The code below works fine. The fancybox appears on document ready. jQuery(document).ready(function() { $.fancybox(
I have the code below as an autoload class, however it appears that the
In the code below the span #2 appears below span #1 , despite the

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.