Quantcast

A community for students. Sign up today!

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

MAO

  • one year ago

Anyone knows what is the best way to resolve the Exercise 11, Chapter 3 of the book: The Art and Science of Java?

  • This Question is Open
  1. Brenar
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    It might help to post the question here.

  2. MCA2014
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Give few questions dude dont have book.

  3. MCA2014
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    If u Have ebook for that please upload or give link to download from site

  4. MAO
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    11. Exercise 4 in Chapter 2 asks you to write a graphics program that produces a diagram of a simple frame house. If you wanted to make (the DrawHouse program easy to change, what named constants should you define to provide the necessary flexibility? Rewrite the program so that it uses these named constants rather than explicit coordinate values. Here it is the DrawHouse: import acm.graphics.*; import acm.program.*; public class JHouse extends GraphicsProgram{ public void run(){ GRect rectWalls = new GRect(((getWidth() - 300)/2), ((getHeight()-120)/2), 300, 120); GRect rectDoor = new GRect(((getWidth() - 50)/2), ((getHeight()-80)/2+20), 50, 80); GRect windLeft = new GRect(((getWidth() - 40)/2-90), ((getHeight()-40)/2), 40, 40); GRect windRight = new GRect(((getWidth() - 40)/2+90), ((getHeight()-40)/2), 40, 40); GLine roofRight = new GLine(527,177,370,50); GLine roofLeft = new GLine(228,177,369,50); GLine windFrameR = new GLine(287,255,287,216); GLine windFrameL = new GLine(467,255,467,216); GOval doorHandle = new GOval(387,255,7,7); add(rectWalls); add(rectDoor); add(windLeft); add(windRight); add(roofRight); add(roofLeft); add(windFrameR); add(windFrameL); add(doorHandle); } }

  5. MAO
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    And here is what I came up with: Can you guys tell me if there is a better way to resolve this? I appreciate if you post the explanation as well, so I can understand how to think. Thanks import acm.graphics.*; import acm.program.*; public class JHouseRevised extends GraphicsProgram{ public void run(){ add(new GRect(((getWidth()-HOUSE_SIZE)/2),((getHeight()-HOUSE_SIZE+ROOF_SIZE)/2),HOUSE_SIZE,HOUSE_SIZE/2)); add(new GRect(((getWidth()-(DOOR_SIZE/2))/2),((getHeight()-DOOR_SIZE)/2+(DOOR_SIZE/2)),DOOR_SIZE/2,DOOR_SIZE)); add(new GRect(((getWidth()-(DOOR_SIZE/2))/2-90),((getHeight()-(DOOR_SIZE/2))/2),(DOOR_SIZE/2),(DOOR_SIZE/2))); add(new GRect(((getWidth()-(DOOR_SIZE/2))/2+90),((getHeight()-(DOOR_SIZE/2))/2),(DOOR_SIZE/2),(DOOR_SIZE/2))); add(new GLine(((getWidth()+HOUSE_SIZE)/2),((getHeight()+(ROOF_SIZE-HOUSE_SIZE))/2),(getWidth()/2),(getHeight()-(HOUSE_SIZE*2)+ROOF_SIZE))); add(new GLine(((getWidth()-HOUSE_SIZE)/2),((getHeight()+(ROOF_SIZE-HOUSE_SIZE))/2),(getWidth()/2),(getHeight()-(HOUSE_SIZE*2)+ROOF_SIZE))); add(new GLine((getWidth()/2-(HOUSE_SIZE/4)-15),((getHeight()/2)+DOOR_SIZE/4),(getWidth()/2-(HOUSE_SIZE/4)-15),((getHeight()/2)-DOOR_SIZE/4))); add(new GLine((getWidth()/2+(HOUSE_SIZE/4)+15),((getHeight()/2)-DOOR_SIZE/4),(getWidth()/2+(HOUSE_SIZE/4)+15),((getHeight()/2)+DOOR_SIZE/4))); add(new GOval(((getWidth()-DOOR_HANDLE)/2+(DOOR_SIZE/6)),(getHeight()/2+(DOOR_SIZE/2)),DOOR_HANDLE,DOOR_HANDLE)); } /*Constant*/ private static final int HOUSE_SIZE = 300; private static final int ROOF_SIZE = 200; private static final int DOOR_SIZE = 100; private static final int DOOR_HANDLE = 7; }

  6. Not the answer you are looking for?
    Search for more explanations.

    Search OpenStudy
    • Attachments:

Ask your own question

Ask a Question
Find more explanations on OpenStudy

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.