This discussion is archived
1 2 Previous Next 27 Replies Latest reply: Dec 3, 2008 2:27 PM by 807589 RSS

toString meathod help in a class and arrys

807589 Newbie
Currently Being Moderated
I can't get the toString method to work, i have a temp class and a temp client and I'm trying to call the toString method from the class in the client but its not working. Can anyone please help me out with this. THANKS!

Here's the Temp Client:
import java.util.Scanner;



public class TempClient 

{
    public static void main(String [] args)
      
    {
      
             Scanner scan = new Scanner(System.in);
               
             int [] dailyTemps = new int [7];
             int [] inputTemps = { 32, 45, 52, 66, 76, 53, 31};
               
               Temp t1 = new Temp (inputTemps);
               
               Temp t2 = new Temp (dailyTemps);
               
               
          
               
               for ( int i = 0; i < dailyTemps.length; i ++) 
               {
               
                    System.out.print(" Enter the temperature for day  " + (i + 1) + "\t");
                    dailyTemps[i] = scan.nextInt (); 
                          
               }
               
                               System.out.println( t1.toString() );


                    
hers the Temp class:
 import java.util.Scanner;
     

   public class Temp
     
   {
    
           
          public final int TEMPS = 7;
          int temp;
          //String dailyTemps;     
          int [] dailyTemps;
            int [] inputTemps;
          int Temp;
          String temp1;
      
         //constructor
    
      public  Temp()
           
      {               
          
     
     
        }
          
          public Temp( int [] dailyTemps)
          
          {
                
               
          }
          
          public  Temp(int newTemp)
          
          {
          
               temp = newTemp;
                         
          }
  
        public int getTemp()
          
          {
          
               return temp;
               
          }
          
          public void setTemp( int changeTemp )
          
          {
          
               temp = changeTemp;
          
          }
          
          public String toString(int [] inputTemps)
          
          {
          
          String returnValue = " ";
          
          for(int i = 0; i < inputTemps.length; i++)
          {
          
               returnValue = returnValue + inputTemps  + "\t";
          }
          
          
               returnValue += "\n";
                    return returnValue;
          }
          
          
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
1 2 Previous Next