Results 1 to 3 of 3
  1. #1
    YLTO is offline Member
    Join Date
    Jun 2011
    Location
    Jakarta
    Posts
    5
    Rep Power
    0

    Default [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

    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));
    	}
    }
    The code looks messy, isn't it? However it took my half an hour to figure out the code.
    By the way when I try to run the code, the code can't run. Your help will be appreciated.

    Thanks :)

  2. #2
    Dark's Avatar
    Dark is offline Senior Member
    Join Date
    Apr 2011
    Location
    Camp Lejuene, North Carolina
    Posts
    643
    Rep Power
    4

    Default

    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.

  3. #3
    YLTO is offline Member
    Join Date
    Jun 2011
    Location
    Jakarta
    Posts
    5
    Rep Power
    0

    Default

    Quote Originally Posted by Dark View Post
    Whats the error message you get when you try to compile/run it?
    I do not know , my eclipse just directly turn the perspective into debug perspective.

Similar Threads

  1. need fast image processing technique
    By madroadbiker in forum Advanced Java
    Replies: 0
    Last Post: 04-30-2011, 07:29 PM
  2. need advice regarding coding technique
    By Basit56 in forum New To Java
    Replies: 4
    Last Post: 01-08-2010, 04:28 PM
  3. Hello Good Morning, Good afternoon, and Good Evening
    By MrFreeweed in forum Introductions
    Replies: 3
    Last Post: 12-11-2009, 03:32 PM
  4. Input technique for unknown lines of input
    By ducreative in forum New To Java
    Replies: 16
    Last Post: 09-23-2009, 09:26 AM
  5. Programing Technique question - Try or If
    By TimHuey in forum New To Java
    Replies: 6
    Last Post: 09-15-2009, 10:03 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
  •