This discussion is archived
7 Replies Latest reply: Nov 14, 2009 1:14 PM by 807580 RSS

String toString not working correctly. Not sure if my getResults method is

807580 Newbie
Currently Being Moderated
this is my error when i try to display the jumper,his club and results.

Thanks in advance for your help.

Name: wayne: Club: sweden: Results: [I@1a758cb

here is my main class:

import java.util.Scanner;
public class LongJumpCompetition
{
     public static void main(String[]args)
     {
          Scanner keyboard = new Scanner(System.in);
          int choice = 0;
          int SIZE =0;
          int NumOfJumps =0;
          int NumOfJumpers =0;
                    
          
          System.out.print("state amount of jumpers: ");
          SIZE=keyboard.nextInt();
          System.out.println();
          System.out.print("state amount of jumps per each jumper: ");
NumOfJumps=keyboard.nextInt();     
          keyboard.nextLine();
          int [] theResults = new int [NumOfJumps];
          
          LongJumper [] LongJumpers = new LongJumper [SIZE];
          
          System.out.println();

          
          choice = menu(keyboard);
          while (choice !=0)
          {
               switch (choice)
               {
                    case 1: addLongjumper (keyboard,LongJumpers,NumOfJumpers);
                              NumOfJumpers++;
                         break;
                    case 2: addResults (keyboard, LongJumpers, NumOfJumpers,theResults,NumOfJumps);
                    
                         break;
                    case 3: showAllJumpers(LongJumpers, NumOfJumpers);
                         break;
               }     
               System.out.println();
               choice = menu(keyboard);
                                                  
                         
          }     
          
     }
     public static int menu(Scanner keyboard)
     {
          //Scanner keyboard=new Scanner(System.in);
          System.out.println("1. add jumper");
          System.out.println("2. add results for choosen jumper");
          System.out.println("3. show all jumper and their results");
          System.out.println("0. end");
          System.out.print("\nYour choice: ");
          return keyboard.nextInt();
     }     
     public static void addLongjumper(Scanner keyboard, LongJumper[]LongJumpers, int NumOfJumpers)
     {
          
          String theName = "";
          String theClub = "";
          int NumOfJumps = 0;
          keyboard.nextLine();
          System.out.print(" state jumpers name: ");
          theName=keyboard.nextLine();
          System.out.print("state the club: ");
          theClub=keyboard.nextLine();
                    
          LongJumpers[NumOfJumpers]= new LongJumper(theName,theClub,NumOfJumps);
                    
     }
     public static void addResults(Scanner keyboard, LongJumper[]LongJumpers, int NumOfJumpers,int []theResults, int NumOfJumps)
     {
          //keyboard.nextLine();
          String searchname ="";
     /*     String theName = "";
          String theClub = "";
          int NumOfJumps =0;
          System.out.print("how many jumper per jumper: ");
NumOfJumps=keyboard.nextInt();     
          keyboard.nextLine();
          int [] theResults = new int [NumOfJumps];
          System.out.println();*/
                    
          System.out.print("state jumpers' name:");
          keyboard.nextLine();
          searchname = keyboard.nextLine();
          int pos = -1;
          boolean found = false;
          
          for(int i=0; i<NumOfJumpers;i++)
          {
               if(searchname.equals(LongJumpers.getName()))
               {
                    pos=i;
                    found=true;
               }     
          }          
                    
          if(pos!=-1)
          {          
               LongJumpers[pos].setResult(theResults,NumOfJumps);
               
          }     
          else if (pos==-1)
          {     
               System.out.print("No jumper with that name found");     
                         
          }
          
     }
     public static void showAllJumpers(LongJumper[] LongJumpers, int NumOfJumpers)
     {
          System.out.println();
          for(int i=0; i<NumOfJumpers; i++)     
          {
               System.out.println(LongJumpers[i]);
          }     
     }          
}

here is my object class:
import java.util.Scanner;
public class LongJumper
{
     //Instants variables
     
     private String name;
     private String club;
     int [] result;

     
     //constructors
     
     public LongJumper()
     {
          
          this.name="";
          this.club="";
          this.result= new int [0];
     }
     
     public LongJumper(String name, String club,int NumOfJumps)
     {
               
          this.name=name;
          this.club=club;
          this.result= new int [NumOfJumps];
          
     }
     
     
     public LongJumper(String name, String club,int []result,int NumOfJumps)
     {
          
          
          this.name=name;
          this.club=club;
          this.result= new int [NumOfJumps];
     }

     
     //Metoder

     
     public void setName(String name)
     {
          this.name=name;
     }
     
     public void setClub(String club)
     {
          this.club=club;
     }
     
     public void setResult(int []result,int NumOfJumps)
     {
     Scanner keyboard= new Scanner(System.in);
     
     for(int i=0; i<NumOfJumps;i++)
     {
          System.out.print("Ange resultat:");
          result[i] = keyboard.nextInt();
          keyboard.nextLine();
          this.result= result;
     }
               
     }
     
     public String getName()
     {
          return this.name;
     }
     
     public String getClub()
     {
          return this.club;
     }
     
     public int [] getResult()
     {
          return this.result;     
     }
     
     

     public String toString()
     {
          return "Name: " + this.name + ": " + "Club: " + this.club+ ": " + " Results: " + this.result;
     }