Search code examples
javajava.lang.class

returning an array but gives .class java


Hey guys i'm a newby programmer, and i'm getting a .class in return from this, but not sure what its asking. Any help would be awesome thank you!

public static Letter[] addLetter(Letter[] array, Scanner kb)


{
      Letter[] temp = new Letter[array.length + 1];
      String toName, toAddress, toCity, toState, fromName, fromAddress, fromCity, fromState;
      int toZip, fromZip;
      double weight;

  for (int x = 0; x < array.length; x++){
     temp[x] = array[x];

     System.out.print("New Letter:\nTo Name: ");
     kb.nextLine();
     System.out.print("To Street: ");
     kb.nextLine();
     System.out.print("To City: ");
     kb.nextLine();
     System.out.print("To State: ");
     kb.nextLine();
     System.out.print("To Zip: ");
     kb.nextInt();
     kb.nextLine();
     System.out.print("From Name: ");
     kb.nextLine();
     System.out.print("From Street: ");
     kb.nextLine();
     System.out.print("From City: ");
     kb.nextLine();
     System.out.print("From State: ");
     kb.nextLine();
     System.out.print("From Zip: ");
     kb.nextInt();
     kb.nextLine();
     System.out.print("Letter weight: ");
     kb.nextDouble();
     kb.nextLine();

     Letter temp = new Letter(toName, toAddress, toCity, toState, toZip, fromName, fromAddress, fromCity, fromState, fromZip, weight);

     int x = array.length - 1;
     temp[x] = temp;
  }
  return temp[];

when i try to return temp [] it gives me an error of . Not too sure on what's going on to make it do that.

class' expected
      return temp[];

Solution

  • Errors in code: You have a

    Letter temp = new Letter ...
    

    Rename it.

    Also change

    return temp[];
    

    to

    return temp;
    

    Errors in design: use ArrayList<Letter> instead of array. It has add method. http://docs.oracle.com/javase/6/docs/api/java/util/ArrayList.html