Results 1 to 12 of 12
  1. #1
    jamesov89 is offline Member
    Join Date
    Sep 2008
    Posts
    21
    Rep Power
    0

    Default 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");

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    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.

  3. #3
    jamesov89 is offline Member
    Join Date
    Sep 2008
    Posts
    21
    Rep Power
    0

    Default

    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.

  4. #4
    serjant's Avatar
    serjant is offline Senior Member
    Join Date
    Jun 2008
    Location
    Ukraine,Zaporozhye
    Posts
    487
    Rep Power
    7

    Default

    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:

    Java Code:
    class Hospital{
             public void print(){
                    System.out.println("Speedy recovery to my grandmother");
            }
    
             public static void main (String[] args){
              }
    }
    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){
                    Hospital hosp=new Hospital();
                    hosp.print();
              }
    }
    And now run it.

  5. #5
    jamesov89 is offline Member
    Join Date
    Sep 2008
    Posts
    21
    Rep Power
    0

    Default

    Thanks for the advise. If I need to print two seperate things should I create a different class?

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    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.

  7. #7
    jamesov89 is offline Member
    Join Date
    Sep 2008
    Posts
    21
    Rep Power
    0

    Default

    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.

  8. #8
    serjant's Avatar
    serjant is offline Senior Member
    Join Date
    Jun 2008
    Location
    Ukraine,Zaporozhye
    Posts
    487
    Rep Power
    7

    Default

    So in the method print() which i wrote to you add four time System.out.println(<what you need to print out>);

  9. #9
    jamesov89 is offline Member
    Join Date
    Sep 2008
    Posts
    21
    Rep Power
    0

    Default

    But if you read my first post I am only allowed to write it out once . . .

  10. #10
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    I am somewhat suspect on those rules. Could you type out exactly what the rules state?

  11. #11
    jamesov89 is offline Member
    Join Date
    Sep 2008
    Posts
    21
    Rep Power
    0

    Default

    "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."

  12. #12
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    ah, as you can only have those methods called once in your program, but you can place them in methods that can be called multiple times, methods such as the one that serjant has shown you above.

Similar Threads

  1. Replies: 29
    Last Post: 09-25-2008, 07:55 PM
  2. Replies: 0
    Last Post: 04-04-2008, 02:40 PM
  3. need help with my 1st multi-method program
    By Phobos0001 in forum New To Java
    Replies: 6
    Last Post: 02-08-2008, 05:44 AM
  4. Replies: 0
    Last Post: 10-04-2007, 09:33 PM
  5. Replies: 1
    Last Post: 08-07-2007, 06:16 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •