Page 2 of 4 FirstFirst 1234 LastLast
Results 21 to 40 of 72
  1. #21
    ccie007 is offline Senior Member
    Join Date
    May 2010
    Posts
    112
    Rep Power
    0

    Default

    Quote Originally Posted by ccie007 View Post
    j continues to increase by 1 each time through the inner loop, until it reaches NCOLUMN, at which point i is incremented to 1, and j is set back to 0.
    GCalvin how do u mean by NCOLUMN above.Is it 1 coloumn or 8 column.cheers.


    Can anybody explain me this please.?
    Last edited by ccie007; 05-21-2010 at 08:36 PM.

  2. #22
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    953
    Rep Power
    5

    Default

    You said two posts ago that you have experience in Pascal and JavaScript. Both of those languages have for loops that work in a very similar manner to the Java for loop (JavaScript is almost exactly the same). What are you not understanding about the Java for loop?

    -Gary-

  3. #23
    ccie007 is offline Senior Member
    Join Date
    May 2010
    Posts
    112
    Rep Power
    0

    Default

    I went to college 6 years ago..Forgotten almost all the programming knowledge:(

  4. #24
    ccie007 is offline Senior Member
    Join Date
    May 2010
    Posts
    112
    Rep Power
    0

    Default

    in my 2 second year I had to choose between computer networking degree or software development degree.My pals went for networking degree bcoz it was easier than software development.When I said to my lady lecturer i would be going for software development which amazed my pals and the lecturer told me"You are a man" meaning(software development is harder than networking and needs more intelligence and hard work).Infact she wanted me to study software development,But after 2 weeks into software development course.I changed to networking course because I found it hard.Fast forward 6 years, here is me trying be a man by cracking into software industry.:-)

  5. #25
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,800
    Rep Power
    25

    Default

    Sorry, what I saw was
    public class Echo {
    public static void main (String[] args) {
    for (String s: args) {
    System.out.println(s);
    Followed by your comment.

    I still don't see a class named Program in the OPs code. I suppose its buried somewhere in some lib pulled in with an import.

  6. #26
    ccie007 is offline Senior Member
    Join Date
    May 2010
    Posts
    112
    Rep Power
    0

    Default

    by the way I copied and pasted above code just for an example.

  7. #27
    ccie007 is offline Senior Member
    Join Date
    May 2010
    Posts
    112
    Rep Power
    0

    Default

    Originally Posted by ccie007 View Post
    j continues to increase by 1 each time through the inner loop, until it reaches NCOLUMN, at which point i is incremented to 1, and j is set back to 0.
    GCalvin how do u mean by NCOLUMN above.Is it 1 coloumn or 8 column.cheers.

    Can anybody explain me this please.?

  8. #28
    ccie007 is offline Senior Member
    Join Date
    May 2010
    Posts
    112
    Rep Power
    0

    Default

    Gary now I understood how outer and inner loops work.Just like car odometer yes?cheers.

  9. #29
    ccie007 is offline Senior Member
    Join Date
    May 2010
    Posts
    112
    Rep Power
    0

    Default I solved the problem

    Guys on the forum were right.They told me i'd have to write the code my self and i did and got the program working.

    And the result is just what i needed.See the pic below:

    http://i.domaindlx.com/cobainia/checkmate.jpg



    I believe my code is right.If you wanna make any comment please do so, you are most welcome.




    /*File:chap4ques11checkerboard.java
    * This program draws checkerboad with circle inside alternate sqaures.
    */


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

    public class chap4ques11checkerboard extends GraphicsProgram{

    /*Number of rows*/

    private static final int NROWS = 8;

    /*Number of columns*/

    private static final int NCOLUMN = 8;

    /*Runs the program*/

    public void run(){
    int sqSize =getHeight() / NROWS;
    for (int i=0; i < NROWS; i++){
    for (int j=0; j < NCOLUMN; j++){

    int x = j * sqSize;

    int y = i * sqSize;

    GRect sq = new GRect(x,y,sqSize,sqSize);

    if(((i + j) % 2) !=0){
    GOval circle = new GOval(x+3,y+3,17,17);

    add(circle);
    }





    add(sq);

    }
    }
    }



    private void fillOval(int i, int j, int k, int l) {
    // TODO Auto-generated method stub

    }


    }

  10. #30
    ccie007 is offline Senior Member
    Join Date
    May 2010
    Posts
    112
    Rep Power
    0

    Default

    Hi guys,
    I have to resolve another program which is very similar to above problem.This is the next problem I have to resolve after the last above problem.The question is as below:

    Using much the same strategy as you did in the preceding exercise, write a
    GraphicsProgram that creates a simple calendar diagram similar to the one shown in
    the following diagram:

    http://i.domaindlx.com/cobainia/calendar.jpg

    Your program should use the following named constants to control the format of the
    calendar display:
    /* The number of days in the month */
    private static final int DAYS_IN_MONTH = 31;
    /* The day of the week on which the month starts */
    /* (Sunday = 0, Monday = 1, Tuesday = 2, and so on) */
    private static final int DAY_MONTH_STARTS = 5;
    /* The width in pixels of a day on the calendar */
    private static final int DAY_WIDTH = 40;
    /* The height in pixels of a day on the calendar */
    private static final int DAY_HEIGHT = 30;

    Your display should generate exactly the number of rows necessary to display the
    days of the month. Here, in a 31-day month that begins on a Friday, the calendar
    needs six rows; if you were generating a calendar for a non-leap-year February that
    began on a Sunday, the calendar would require only four rows.
    Last edited by ccie007; 05-22-2010 at 04:58 PM. Reason: http://i.domaindlx.com/cobainia/calendar.jpg

  11. #31
    curmudgeon is offline Senior Member
    Join Date
    May 2010
    Posts
    436
    Rep Power
    5

    Default

    Quote Originally Posted by ccie007 View Post
    Hi guys,
    I have to resolve another program which is very similar to above problem.This is the next problem I have to resolve after the last above problem.The question is as below:
    I think I speak for all in wishing you much success in solving this new problem. And please feel free to come on back if you have a specific question to ask.

  12. #32
    ccie007 is offline Senior Member
    Join Date
    May 2010
    Posts
    112
    Rep Power
    0

    Default

    So far I am being able to put a circle on the square where it is suppose to be number 1(first day of the month).when I enter

    GLabel day = New GLabel(("1"),12,12);

    Number 1 gets written on the first square of top left corner(0,0 in coordination).Any idea how we can put number one 5 square on the right of the same row i.e 0,5 in coordination.

    Why I can put circle in the right place(0,5) but not GLable or number 1 ?any ideas mates?
    cheers.
    I believe those numbers of days from 1 to 31 should be created be iteration(loop),is it right?

    My code so far:

    /*File:chapter4question12.java
    * This program shows a month calendar

    *
    * */




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

    public class chapter4question12 extends GraphicsProgram{

    /* The number of days in the month */
    private static final int DAYS_IN_MONTH = 31;
    /* The day of the week on which the month starts */
    /* (Sunday = 0, Monday = 1, Tuesday = 2, and so on) */
    private static final int DAY_MONTH_STARTS = 5;
    /* The width in pixels of a day on the calendar */
    private static final int DAY_WIDTH = 40;
    /* The height in pixels of a day on the calendar */
    private static final int DAY_HEIGHT = 30;
    /*The number of rows in the calendar*/
    private static final int NROWS = 6;
    /*The number of columns in the calendar*/
    private static final int NCOLUMN = 7;

    /*Runs the program*/

    public void run(){

    for (int i=0; i < NROWS; i++){
    for (int j=0; j < NCOLUMN; j++){

    int x = j * DAY_WIDTH;

    int y = i * DAY_HEIGHT;

    GRect sq = new GRect(x,y,DAY_WIDTH, DAY_HEIGHT);

    if(i==0 & j==5 ){

    GLabel days =new GLabel(("1"),12,12);
    add (days);





    }
















    add(sq);

    }
    }


    }
    }


    Thank you.
    Last edited by ccie007; 05-22-2010 at 05:56 PM.

  13. #33
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,800
    Rep Power
    25

    Default

    GLabel day = New GLabel(("1"),12,12);
    What are the values 12, 12?
    in general its not good code to hard code constants like that in a program.

    Are these the x,y coordinates for where to draw? Or the size of the label or ?
    Last edited by Norm; 05-22-2010 at 08:49 PM.

  14. #34
    ccie007 is offline Senior Member
    Join Date
    May 2010
    Posts
    112
    Rep Power
    0

    Default

    It is size of the label Norm.can we have coordinates x,y for Glabel?

  15. #35
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,800
    Rep Power
    25

    Default

    What does the doc say? I don't have the doc for the acm packages.

  16. #36
    Learning Java is offline Senior Member
    Join Date
    May 2010
    Location
    London
    Posts
    106
    Rep Power
    0

    Default

    Quote Originally Posted by ccie007 View Post
    It is size of the label Norm.can we have coordinates x,y for Glabel?
    When you add the following to the canvas what happens? If you change the 100 to 200 does the size of the text change, or does the x and y coordinate change?

    Java Code:
    GLabel label = new GLabel ("text", 100, 100)

  17. #37
    ccie007 is offline Senior Member
    Join Date
    May 2010
    Posts
    112
    Rep Power
    0

    Default

    Hi Norm,
    I do not know where to look for doc.I am using Eclipse and doing CS106A stanford university course.Below is a copy of my code for the program I am trying to make.Thank you for your replies Norm.I would be grateful if you could help me please.

    Java Code:
    /*File:chapter4question12.java
     * This program shows a month calendar
      
     * 
     * */
     
    
    
    
    import acm.program.*;
    import acm.graphics.*;
    
    public class chapter4question12 extends GraphicsProgram{
    	
    	/* The number of days in the month */
    	private static final int DAYS_IN_MONTH = 31;
    	/* The day of the week on which the month starts */
    	/* (Sunday = 0, Monday = 1, Tuesday = 2, and so on) */
    	private static final int DAY_MONTH_STARTS = 5;
    	/* The width in pixels of a day on the calendar */
    	private static final int DAY_WIDTH = 40;
    	/* The height in pixels of a day on the calendar */
    	private static final int DAY_HEIGHT = 30;
    	/*The number of rows in the calendar*/	
    	private static final int NROWS = 6;
    	/*The number of columns in the calendar*/	
    	private static final int NCOLUMN = 7;
    	
    	/*Runs the program*/
    	
    	public void run(){
    		
    		for (int i=0; i < NROWS; i++){
    			for (int j=0; j < NCOLUMN; j++){
    				
    				int x = j * DAY_WIDTH;
    				
    				int y = i * DAY_HEIGHT;
    				
    				GRect sq = new GRect(x,y,DAY_WIDTH, DAY_HEIGHT);
    				
    			for (int d=1; d<=DAYS_IN_MONTH;d++){
    				
    				GLabel day = new GLabel((d),200,23);
    				
    				
    				
    			
    				add(day);
    				
    				
    				    
    							
    				
    				add(sq);
    				
    			}
    		}
    
    	
    	}
    }
    Moderator Edit: Code tags added
    Last edited by Fubarable; 05-22-2010 at 11:08 PM. Reason: Moderator Edit: Code tags added

  18. #38
    ccie007 is offline Senior Member
    Join Date
    May 2010
    Posts
    112
    Rep Power
    0

    Default

    If I change to 100 to 200 coordinates changes not size.Sorry my mistake.

  19. #39
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,800
    Rep Power
    25

    Default

    I do not know where to look for doc
    How do you know how to code the GLabel and GRect classes without documentation?

    Ok, the x,y is the position that the label is displayed.
    So now you need to work up the values and increments for positioning the numbers across the screen and down the screen.
    You'll also need some code to draw the horizontal and vertical lines separating the days.
    Last edited by Norm; 05-22-2010 at 10:10 PM.

  20. #40
    Learning Java is offline Senior Member
    Join Date
    May 2010
    Location
    London
    Posts
    106
    Rep Power
    0

    Default

    I'd actually like to know how this exercise is done too. I couldn't figure it out.

    As far as I know the GLabel doesn't accept other than a String as a parameter for text. And I don't remember the book mentioning anything about int to String conversions.

    I honestly can't figure it out.

    Is this where perhaps a switch statement is needed? :confused: That would be rather messy.

Page 2 of 4 FirstFirst 1234 LastLast

Similar Threads

  1. CS106A Stanford University
    By Learning Java in forum New To Java
    Replies: 116
    Last Post: 07-09-2011, 05:43 PM
  2. Need help with java question
    By ccie007 in forum New To Java
    Replies: 23
    Last Post: 05-18-2010, 07:32 PM
  3. Java question
    By TGH in forum New To Java
    Replies: 12
    Last Post: 11-27-2009, 03:05 PM
  4. question about java rmi
    By hakimade in forum Advanced Java
    Replies: 1
    Last Post: 07-01-2009, 08:15 AM
  5. Java Question
    By Jay-1.1 in forum New To Java
    Replies: 11
    Last Post: 05-01-2008, 05:04 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
  •