Results 1 to 3 of 3
- 07-07-2011, 09:53 AM #1
Member
- Join Date
- Jun 2011
- Location
- Jakarta
- Posts
- 5
- Rep Power
- 0
[Ask] Good Decomposition Technique
Hello folks, I'm new member here and I got stumble to this forum when I google out the CS106A problem , so pardon me if I do make some mistake in this forum.
So here is my problem ,
I teach myself programming from CS106A free courses.
And I try to do the assignment but sadly I failed to complete it correctly.
Whenever I try to decompose the project, I'm somehow hard to figure out especially the coordinate of the object and when it comes to argument, I'm totally screwed.
So does anyone know how to decompose problem effectively, I mean what aspect we should take care first?
So here is my work for assignment number 3.
http://see.stanford.edu/materials/ic...imple-java.pdf
The code looks messy, isn't it? However it took my half an hour to figure out the code.Java Code:/* * File: ProgramHierarchy.java * Name: * Section Leader: * --------------------------- * This file is the starter file for the ProgramHierarchy problem. */ import acm.graphics.*; import acm.program.*; import java.awt.*; public class ProgramHierarchy extends GraphicsProgram { /* Dimension of the box */ private static final double BOX_WIDTH = 200; private static final double BOX_HEIGHT = 50; /* Width of space between boxes */ private static final double BOX_SPACE = 25; /* The height of space between boxes */ private static final double BOX_CONNECTOR = 50; double x = (getWidth()/2) - (BOX_WIDTH/2); double y = (getHeight()/2) - (BOX_HEIGHT/2); double dx = BOX_SPACE + BOX_WIDTH; double dy = BOX_CONNECTOR; public void run(){ drawProgram(x, y); drawConsole(x, y + dy); drawGraphics(x - dx , y + dy); drawDialog(x + dx , y + dy); } private void drawProgram(double x, double y){ drawBox(x, y); drawLabel("Program" , x, y ); } private void drawConsole(double x, double y){ drawBox(x, y); drawLine(x + BOX_WIDTH/2 , y + BOX_HEIGHT, x, y + dy/2 ); drawLabel("ConsoleProgram" ,x ,y); } private void drawGraphics(double x, double y){ drawBox(x,y); drawLine(x + BOX_WIDTH/2, y + BOX_HEIGHT, x + BOX_WIDTH - dx, y + BOX_HEIGHT + dy); drawLabel("GraphicsProgram" ,x, y); } private void drawDialog(double x, double y ){ drawBox(x,y); drawLine(x + BOX_WIDTH/2, y + BOX_HEIGHT, x + BOX_WIDTH + dx, y + BOX_HEIGHT + dy ); } private void drawLine(double x1, double x2, double y1, double y2){ add(new GLine(x1, x2, y1, y2)); } private void drawLabel(String text, double x, double y) { GLabel label = new GLabel(text, x, y); x = BOX_WIDTH/2 - label.getWidth()/2; y = BOX_HEIGHT/2 - label.getAscent()/2; add(label); } private void drawBox(double x, double y){ add(new GRect(x, y)); } }
By the way when I try to run the code, the code can't run. Your help will be appreciated.
Thanks :)
- 07-07-2011, 09:58 AM #2
Whats the error message you get when you try to compile/run it?
- Use [code][/code] tags when posting code. That way people don't want to stab their eyes out when trying to help you.
- +Rep people for helpful posts.
- 07-07-2011, 10:04 AM #3
Member
- Join Date
- Jun 2011
- Location
- Jakarta
- Posts
- 5
- Rep Power
- 0
Similar Threads
-
need fast image processing technique
By madroadbiker in forum Advanced JavaReplies: 0Last Post: 04-30-2011, 07:29 PM -
need advice regarding coding technique
By Basit56 in forum New To JavaReplies: 4Last Post: 01-08-2010, 04:28 PM -
Hello Good Morning, Good afternoon, and Good Evening
By MrFreeweed in forum IntroductionsReplies: 3Last Post: 12-11-2009, 03:32 PM -
Input technique for unknown lines of input
By ducreative in forum New To JavaReplies: 16Last Post: 09-23-2009, 09:26 AM -
Programing Technique question - Try or If
By TimHuey in forum New To JavaReplies: 6Last Post: 09-15-2009, 10:03 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks