Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 15 of 15

Thread: Im getting 1 Silly error can someone help please

  1. #1
    Junior Member
    Join Date
    Dec 2009
    Posts
    22
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Exclamation Im getting 1 Silly error can someone help please

    import java.util.Arrays;
    import java.util.List;
     
       public class PhoneBook(<PhoneBookEntry> directory){
       {
          int numEntries = Math.max(directory.size(), DEFAULT_SIZE);
          this.directory = new PhoneBookEntry[numEntries];
          for (PhoneBookEntry entry : directory)
          {
             this.directory[nextEntryIndex++] = entry;
          }
       }
     
       public void add(PhoneBookEntry entry)
       {
          directory[nextEntryIndex++] = entry;
       }
     
       public void remove(PhoneBookEntry entry)
       {
          for (int i = 0; i < nextEntryIndex; ++i)
          {
             if (entry.equals(directory[i]))
             {
                directory[i] = null;  
             }
          }
       }
     
       public PhoneBookEntry findByName(String name)
       {
          PhoneBookEntry value = null;
     
          for (int i = 0; i < nextEntryIndex; ++i)
          {
             if ((directory[i] != null) && (directory[i].getName().equals(name)))
             {
                value = directory[i];
                break;
             }
          }
          return value;
       }
     
       public String toString()
       {
          StringBuilder builder = new StringBuilder(DEFAULT_BUFFER_SIZE);
          builder.append("PhoneBook{");
          for (int i = 0; i < nextEntryIndex; ++i)
          {
             PhoneBookEntry entry = directory[i];
             if (entry == null)
             {
                builder.append("null");
             }
             else
             {
                builder.append(entry.toString());
             }
             builder.append(",");
          }
          builder.append('}');
     
          return builder.toString();
       }
    }
    }

       public class PhoneBook(<PhoneBookEntry> directory){
    what am i doing wrong the error says i need to add a { can anyone see wer im goin wrong please?


  2. #2
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Posts
    834
    My Mood
    Cynical
    Thanks
    7
    Thanked 105 Times in 90 Posts

    Default Re: Im getting 1 Silly error can someone help please

    Steve has never taught syntax like this <PhoneBookEntry>, unless it appears after ArrayList. But it has other uses too. Remove < and >

    Chris,
    Bangor University

  3. #3
    Junior Member
    Join Date
    Dec 2009
    Posts
    22
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Im getting 1 Silly error can someone help please

    hey chris cheers for the reply. have removed the < > still gettin the same error dude. havent had much joy with this program its due in tomoz too.. bummer lol

  4. #4
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Posts
    834
    My Mood
    Cynical
    Thanks
    7
    Thanked 105 Times in 90 Posts

    Default Re: Im getting 1 Silly error can someone help please

    You have merged the start of your class ie,

    public class AName{
    }

    with your constructor

    Chris

  5. #5
    Junior Member
    Join Date
    Dec 2009
    Posts
    22
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Im getting 1 Silly error can someone help please

    u know what chris its that late in the day i cant think straight bud. ive ammended my code but no such luck. are you studying with steve in bangor dude?

    import java.util.Arrays;
    import java.util.List;
     
    public class PhoneBook{
     
       public class PhoneBook(PhoneBookEntry directory)
       {
          int numEntries = Math.max(directory.size(), DEFAULT_SIZE);
          this.directory = new PhoneBookEntry[numEntries];
          for (PhoneBookEntry entry : directory)
          {
             this.directory[nextEntryIndex++] = entry;
          }
       }

  6. #6
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Posts
    834
    My Mood
    Cynical
    Thanks
    7
    Thanked 105 Times in 90 Posts

    Default Re: Im getting 1 Silly error can someone help please

    Yes I am. Exactly what errors are you getting now, since from what I can see you don't have a great deal wrong with your code.

    you don't have a global "directory" defined like you are trying to access on the line this.directory = new Phone....

    Paste all your amended code and all of the error messages its hard to properly debug your code without it. I can only give you limited help really.


    Might I as who you are?

  7. #7
    Junior Member
    Join Date
    Dec 2009
    Posts
    22
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Im getting 1 Silly error can someone help please

    import java.util.Arrays;
    import java.util.List;
     
    public class PhoneBook{
     
       public class PhoneBook(PhoneBookEntry directory)
       {
          int numEntries = Math.max(directory.size(), DEFAULT_SIZE);
          this.directory = new PhoneBookEntry[numEntries];
          for (PhoneBookEntry entry : directory)
          {
             this.directory[nextEntryIndex++] = entry;
          }
       }
     
       public void add(PhoneBookEntry entry)
       {
          directory[nextEntryIndex++] = entry;
       }
     
       public void remove(PhoneBookEntry entry)
       {
          for (int i = 0; i < nextEntryIndex; ++i)
          {
             if (entry.equals(directory[i]))
             {
                directory[i] = null;  
             }
          }
       }
     
       public PhoneBookEntry findByName(String name)
       {
          PhoneBookEntry value = null;
     
          for (int i = 0; i < nextEntryIndex; ++i)
          {
             if ((directory[i] != null) && (directory[i].getName().equals(name)))
             {
                value = directory[i];
                break;
             }
          }
          return value;
       }
     
       public String toString()
       {
          StringBuilder builder = new StringBuilder(DEFAULT_BUFFER_SIZE);
          builder.append("PhoneBook{");
          for (int i = 0; i < nextEntryIndex; ++i)
          {
             PhoneBookEntry entry = directory[i];
             if (entry == null)
             {
                builder.append("null");
             }
             else
             {
                builder.append(entry.toString());
             }
             builder.append(",");
          }
          builder.append('}');
     
          return builder.toString();
       }
    }
    }
    im getting the same 1 error message as i did in the beginning. Lets just say im a newbie to java currently at bangor lol how have u got on with your assignment, what experience have u had doing java then? would you have time to compile my program just to see first hand?

  8. #8
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Posts
    834
    My Mood
    Cynical
    Thanks
    7
    Thanked 105 Times in 90 Posts

    Default Re: Im getting 1 Silly error can someone help please

    My assignment was completed before the christmas holidays.
    Formal experience, well the last semester here at Bangor. Other than that I have taught myself I know a few programming languages including C++.

    Your program consists of multiple classes so i woud require more files.

    Your constructor has been defined as a class.

     public class PhoneBook(PhoneBookEntry directory)

  9. #9
    Junior Member
    Join Date
    Dec 2009
    Posts
    22
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Im getting 1 Silly error can someone help please

    fair do's fella. i dont think im the only one sorts struggling on this assignment. i know a few.. ive done task 1 no probz. hopefully get the next 2 programs out of the way by tomoz.. what program do u want my entry one?

  10. #10
    Junior Member
    Join Date
    Dec 2009
    Posts
    22
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Im getting 1 Silly error can someone help please

    class PhoneBookEntry implements Serializable
    {
       private String name;
       private String number;
     
     
       public PhoneBookEntry(String name, String number)
       {
          this.name = name;
          this.number = number;
       }
     
       public String getName()
       {
          return name;
       }
     
       public String getNumber()
       {
          return number;
       }
     
       public boolean equals(Object o)
       {
          if (this == o)
          {
             return true;
          }
          if (o == null || getClass() != o.getClass())
          {
             return false;
          }
     
          PhoneBookEntry that = (PhoneBookEntry) o;
     
          if (name != null ? !name.equals(that.name) : that.name != null)
          {
             return false;
          }
          if (number != null ? !number.equals(that.number) : that.number != null)
          {
             return false;
          }
     
          return true;
       }
     
       public String toString()
       {
          return new StringBuilder().append("PhoneBookEntry{").append("name='").append(name).append('\'').append(", number='").append(number).append('\'').append('}').toString();
       }
    }
    }

  11. #11
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Posts
    834
    My Mood
    Cynical
    Thanks
    7
    Thanked 105 Times in 90 Posts

    Default Re: Im getting 1 Silly error can someone help please

    if you make the change i suggested of removing the word class from your constructor it should work fine.

    I shouldnt need to compile your programs. Also im wondering why your class implements seralizable lol

  12. #12
    Junior Member
    Join Date
    Dec 2009
    Posts
    22
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Im getting 1 Silly error can someone help please

    bad advice from another java programmer that i know lol
    import java.util.Arrays;
    import java.util.List;
     
    public class PhoneBook
    {
     
       public PhoneBook(PhoneBookEntry directory)
       {
          int numEntries = Math.max(directory.size(), DEFAULT_SIZE);
          this.directory = new PhoneBookEntry[numEntries];
          for (PhoneBookEntry entry : directory)
          {
             this.directory[nextEntryIndex++] = entry;
          }
       }
     
       public void add(PhoneBookEntry entry)
       {
          directory[nextEntryIndex++] = entry;
       }
     
       public void remove(PhoneBookEntry entry)
       {
          for (int i = 0; i < nextEntryIndex; ++i)
          {
             if (entry.equals(directory[i]))
             {
                directory[i] = null;  
             }
          }
       }
     
       public PhoneBookEntry findByName(String name)
       {
          PhoneBookEntry value = null;
     
          for (int i = 0; i < nextEntryIndex; ++i)
          {
             if ((directory[i] != null) && (directory[i].getName().equals(name)))
             {
                value = directory[i];
                break;
             }
          }
          return value;
       }
     
       public String toString()
       {
          StringBuilder builder = new StringBuilder(DEFAULT_BUFFER_SIZE);
          builder.append("PhoneBook{");
          for (int i = 0; i < nextEntryIndex; ++i)
          {
             PhoneBookEntry entry = directory[i];
             if (entry == null)
             {
                builder.append("null");
             }
             else
             {
                builder.append(entry.toString());
             }
             builder.append(",");
          }
          builder.append('}');
     
          return builder.toString();
       }
    }
     
    public class PhoneBookEntry 
    {
       private String name;
       private String number;
     
     
       public PhoneBookEntry(String name, String number)
       {
          this.name = name;
          this.number = number;
       }
     
       public String getName()
       {
          return name;
       }
     
       public String getNumber()
       {
          return number;
       }
     
       public boolean equals(Object o)
       {
          if (this == o)
          {
             return true;
          }
          if (o == null || getClass() != o.getClass())
          {
             return false;
          }
     
          PhoneBookEntry that = (PhoneBookEntry) o;
     
          if (name != null ? !name.equals(that.name) : that.name != null)
          {
             return false;
          }
          if (number != null ? !number.equals(that.number) : that.number != null)
          {
             return false;
          }
     
          return true;
       }
     
       public String toString()
       {
          return new StringBuilder().append("PhoneBookEntry{").append("name='").append(name).append('\'').append(", number='").append(number).append('\'').append('}').toString();
       }
    }
    }
    have tried all i can now but cant get my head around it im gettin 2 errors now for the very end of my program which is "class or interface" expected..i enjoy java like but it frustrates the hell out of me. what sites or books would you recommend dude?>

  13. #13
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Posts
    834
    My Mood
    Cynical
    Thanks
    7
    Thanked 105 Times in 90 Posts

    Default Re: Im getting 1 Silly error can someone help please

    You can't have two public classes in one file it should be noted. Also you have more } than you do {.

    The Java API is very helpful. As for what sites and books well, javabat.com is a good site to practise youre work. But there is no good site for teaching Java, nor ca I recommend and books, however there is the ever so popular Deitel & Deitel how to program Java books, which many people are fond of Including Steve, but it requires you ti have a basic understanding of Java. Otherwise indeed Big Java which Steve has suggested is a good book for you. I learnt from experimentation and the Java API

    Chris

  14. #14
    Junior Member
    Join Date
    Dec 2009
    Posts
    22
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Im getting 1 Silly error can someone help please

    Cheers for your input anywayz dude im guna hit the hay pretty soon will try again after my first lecture we got till 5 anywayz so hopefully i will have it sorted by then... will take on board what youve said tho much appreciated

  15. #15
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Posts
    834
    My Mood
    Cynical
    Thanks
    7
    Thanked 105 Times in 90 Posts

    Default Re: Im getting 1 Silly error can someone help please

    Np, goodluck