Results 1 to 12 of 12
- 09-22-2008, 12:20 AM #1
Member
- Join Date
- Sep 2008
- Posts
- 21
- Rep Power
- 0
I need help with my first method program!!!
Hey everyone, I really need your help. I need to write a program that will display a checkerboard pattern out of blanks and #'s. It needs to be 8 spaces wide by four lines. They make up boxes and there are 4 blank boxes and 4 # boxes in each row and column. The numbers are the same. I have read the chapter on methods although I am not sure how I would complete this program. We ARE NOT allowed to use loops (even though I don't know how to use them). If anyone could help me out I would be indebted to you forever. I probably would have had more time to study but my grandma has been in the hospital and this program is due tomorrow! :eek:
Using only 3 print statements (each one time in your entire program)
System.out.print (" ");
System.out.print ("########");
System.out.print ("\n");
-
Best wishes on the speedy recovery of your grandmother. So, what exactly do you need help with? and you know of course that we cannot do your program for you as that would be cheating, but we can answer questions you have. This means that you will still need to study the materials regardless of events unless your teacher grants you a bye of some sort. If you truly have a hardship, I recommend that you talk to your teacher about this.
- 09-22-2008, 03:25 AM #3
Member
- Join Date
- Sep 2008
- Posts
- 21
- Rep Power
- 0
I understand that I cannot ask you to do my program for me. What I need to do is make methods that refer back to that over and over. Any suggestions? I know there are a few different types of methods and I was wondering if someone could tell me which it was that I needed to do and perhaps an example of how to write them out.
- 09-22-2008, 04:47 AM #4
First of all create class and static main method in it like here:
Java Code:class Hospital{ public static void main (String[] args){ } }
then,you should create inside this class another public method,where you define your task,for example if you need to prints smth so it should be like this:
then in main static method you create the object from the class Hospital and by object call the method print() like this one:Java Code:class Hospital{ public void print(){ System.out.println("Speedy recovery to my grandmother"); } public static void main (String[] args){ } }
And now run it.Java Code:class Hospital{ public void print(){ System.out.println("Speedy recovery to my grandmother"); } public static void main (String[] args){ Hospital hosp=new Hospital(); hosp.print(); } }
- 09-22-2008, 05:13 AM #5
Member
- Join Date
- Sep 2008
- Posts
- 21
- Rep Power
- 0
Thanks for the advise. If I need to print two seperate things should I create a different class?
-
No. You should only create a separate class when you want an entity to have a separate role.If I need to print two seperate things should I create a different class?
- 09-22-2008, 05:24 AM #7
Member
- Join Date
- Sep 2008
- Posts
- 21
- Rep Power
- 0
I understand that, but I need to print out "########" four times and then "__________" four times. They cannot be consecutive otherwise the checkerboard will not look correct.
- 09-22-2008, 05:26 AM #8
So in the method print() which i wrote to you add four time System.out.println(<what you need to print out>);
- 09-22-2008, 05:35 AM #9
Member
- Join Date
- Sep 2008
- Posts
- 21
- Rep Power
- 0
But if you read my first post I am only allowed to write it out once . . .
-
I am somewhat suspect on those rules. Could you type out exactly what the rules state?
- 09-22-2008, 05:50 AM #11
Member
- Join Date
- Sep 2008
- Posts
- 21
- Rep Power
- 0
"Using only 3 print statements (one each time) in your entire program
System.out.print ("___________")
System.out.print ("########")
System.out.print (\n)
display the checkerboard as shown below. You will want to make heavy use of methods that you write. Your program does not have to produce the outline or shading! Turn in your program listing, printed output, flowchart and structure chart."
-
Similar Threads
-
Calling a method in a different class from within a method problem
By CirKuT in forum New To JavaReplies: 29Last Post: 09-25-2008, 07:55 PM -
How to execute an External Program through Java program
By Java Tip in forum java.ioReplies: 0Last Post: 04-04-2008, 02:40 PM -
need help with my 1st multi-method program
By Phobos0001 in forum New To JavaReplies: 6Last Post: 02-08-2008, 05:44 AM -
How to execute an External Program through Java program
By JavaBean in forum Java TipReplies: 0Last Post: 10-04-2007, 09:33 PM -
Call a main method from within a running program
By zoe in forum New To JavaReplies: 1Last Post: 08-07-2007, 06:16 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks