Results 1 to 5 of 5
  1. #1
    shazakala is offline Member
    Join Date
    Mar 2011
    Posts
    19
    Rep Power
    0

    Default need help with method

    In this method which is part of a bigger program, it is not sending the information back from where it is being called the way that I want it :

    Java Code:
    	private void displayCurrentState(int currentScoreU, int currentScoreC, boolean stayU, boolean stayC) {		
    		displayDashes();
    		displayDashes();
    		System.out.print("- User score:" + currentScoreU);
    
    		if(stayU == true){
    			System.out.println(".  User has stayed.");
    		}
    		if(stayU == false){
    			System.out.println();
    		}
    		System.out.print("- Computer score:" + currentScoreC);	
    		if(stayC == true){
    			System.out.println(".  Computer has stayed.");
    		}
    		if(stayC == false){
    			System.out.println();
    		}
    I cant figure out how to get it so it prints out:

    1.
    ----------------------------------------------
    ----------------------------------------------
    - User score: 18
    - Computer score: 17
    ----------------------------------------------
    ----------------------------------------------
    2.
    ----------------------------------------------
    ----------------------------------------------
    - User score: 16
    - Computer score: 19. Computer has stayed.
    ----------------------------------------------
    ----------------------------------------------
    3.
    ----------------------------------------------
    ----------------------------------------------
    - User score: 18. Computer has stayed.
    - Computer score: 17
    ----------------------------------------------
    ----------------------------------------------

    the methods, this method is asking for are doing most of the jobs I just need to lay it out correctly but right now all that is being printed out is this: (notice the placement of the "2." and "3." are placed wrong and some of the dash's are missing)

    1.
    ----------------------------------------------
    ----------------------------------------------
    - User score: 18
    - Computer score: 17
    2.
    ----------------------------------------------
    ----------------------------------------------
    - User score: 16
    - Computer score: 19. Computer has stayed.
    3.
    ----------------------------------------------
    ----------------------------------------------
    - User score: 18. Computer has stayed.
    - Computer score: 17

    the code this is all sent to looks like this (this code does not need to be edited):
    Java Code:
    	private void test01() {	
    		System.out.println("Your output:");
    		System.out.println("1.");
    		displayCurrentState(18, 17, false, false);
    		System.out.println("2.");
    		displayCurrentState(16, 19, false, true);
    		System.out.println("3.");
    		displayCurrentState(21, 17, true, false);
    Can someone show me how the method I'm trying to fix should look and where I'm going wrong? Much thanks :D
    Last edited by shazakala; 04-01-2011 at 09:23 AM.

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default

    sorry I still haven't figured out how to show the code nicely

    You put [code] at the start of the code and [/code] at the end. I think you can edit your post to do this - but make sure the indentation is correct if you edit the post.

    Close! But it should be [/code] at the end.
    Last edited by pbrockway2; 04-01-2011 at 09:14 AM.

  3. #3
    shazakala is offline Member
    Join Date
    Mar 2011
    Posts
    19
    Rep Power
    0

    Default

    thanks thats one problem out of the way ^.^

  4. #4
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default

    The output you say you get is exactly what you say you should be getting (unless I am missing something...) And neither can possibly be produced by the code you posted.

  5. #5
    shazakala is offline Member
    Join Date
    Mar 2011
    Posts
    19
    Rep Power
    0

    Default

    in the end all I needed to do was add dashes to the end of my code :P oh well, case closed.

Similar Threads

  1. Declaring a method inside a method: Runnable?
    By africanhacker in forum New To Java
    Replies: 8
    Last Post: 03-23-2011, 05:30 AM
  2. Turning Recursion Method into Iterative method
    By mattakuevan in forum New To Java
    Replies: 9
    Last Post: 06-15-2010, 07:46 AM
  3. Replies: 2
    Last Post: 03-26-2010, 06:12 PM
  4. ArrayLists compareTo method, equals method
    By random0munky in forum New To Java
    Replies: 2
    Last Post: 10-26-2009, 08:20 PM
  5. cannot call private method from static method
    By jon80 in forum New To Java
    Replies: 3
    Last Post: 05-07-2008, 09:37 AM

Tags for this Thread

Posting Permissions

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