Results 21 to 40 of 70
- 05-21-2010, 07:09 PM #21
Senior Member
- Join Date
- May 2010
- Posts
- 112
- Rep Power
- 0
- 05-21-2010, 07:13 PM #22
Senior Member
- Join Date
- Mar 2010
- Posts
- 953
- Rep Power
- 4
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-
- 05-21-2010, 07:17 PM #23
Senior Member
- Join Date
- May 2010
- Posts
- 112
- Rep Power
- 0
I went to college 6 years ago..Forgotten almost all the programming knowledge:(
- 05-21-2010, 07:24 PM #24
Senior Member
- Join Date
- May 2010
- Posts
- 112
- Rep Power
- 0
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.:-)
- 05-21-2010, 07:33 PM #25
Sorry, what I saw was
Followed by your comment.public class Echo {
public static void main (String[] args) {
for (String s: args) {
System.out.println(s);
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.
- 05-21-2010, 07:34 PM #26
Senior Member
- Join Date
- May 2010
- Posts
- 112
- Rep Power
- 0
by the way I copied and pasted above code just for an example.
- 05-21-2010, 07:37 PM #27
Senior Member
- Join Date
- May 2010
- Posts
- 112
- Rep Power
- 0
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.?
- 05-22-2010, 11:12 AM #28
Senior Member
- Join Date
- May 2010
- Posts
- 112
- Rep Power
- 0
Gary now I understood how outer and inner loops work.Just like car odometer yes?cheers.
- 05-22-2010, 12:45 PM #29
Senior Member
- Join Date
- May 2010
- Posts
- 112
- Rep Power
- 0
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
}
}
- 05-22-2010, 03:57 PM #30
Senior Member
- Join Date
- May 2010
- Posts
- 112
- Rep Power
- 0
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 03:58 PM. Reason: http://i.domaindlx.com/cobainia/calendar.jpg
- 05-22-2010, 04:09 PM #31
Senior Member
- Join Date
- May 2010
- Posts
- 436
- Rep Power
- 4
- 05-22-2010, 04:49 PM #32
Senior Member
- Join Date
- May 2010
- Posts
- 112
- Rep Power
- 0
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 04:56 PM.
- 05-22-2010, 07:33 PM #33
What are the values 12, 12?GLabel day = New GLabel(("1"),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 07:49 PM.
- 05-22-2010, 08:27 PM #34
Senior Member
- Join Date
- May 2010
- Posts
- 112
- Rep Power
- 0
It is size of the label Norm.can we have coordinates x,y for Glabel?
- 05-22-2010, 08:34 PM #35
What does the doc say? I don't have the doc for the acm packages.
- 05-22-2010, 08:41 PM #36
Senior Member
- Join Date
- May 2010
- Location
- London
- Posts
- 106
- Rep Power
- 0
- 05-22-2010, 08:42 PM #37
Senior Member
- Join Date
- May 2010
- Posts
- 112
- Rep Power
- 0
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.
Moderator Edit: Code tags addedJava 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); } } } }Last edited by Fubarable; 05-22-2010 at 10:08 PM. Reason: Moderator Edit: Code tags added
- 05-22-2010, 08:46 PM #38
Senior Member
- Join Date
- May 2010
- Posts
- 112
- Rep Power
- 0
If I change to 100 to 200 coordinates changes not size.Sorry my mistake.
- 05-22-2010, 09:08 PM #39
How do you know how to code the GLabel and GRect classes without documentation?I do not know where to look for doc
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 09:10 PM.
- 05-22-2010, 10:05 PM #40
Senior Member
- Join Date
- May 2010
- Location
- London
- Posts
- 106
- Rep Power
- 0
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.
Similar Threads
-
CS106A Stanford University
By Learning Java in forum New To JavaReplies: 116Last Post: 07-09-2011, 04:43 PM -
Need help with java question
By ccie007 in forum New To JavaReplies: 23Last Post: 05-18-2010, 06:32 PM -
Java question
By TGH in forum New To JavaReplies: 12Last Post: 11-27-2009, 02:05 PM -
question about java rmi
By hakimade in forum Advanced JavaReplies: 1Last Post: 07-01-2009, 07:15 AM -
Java Question
By Jay-1.1 in forum New To JavaReplies: 11Last Post: 05-01-2008, 04:04 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks