Results 1 to 2 of 2
  1. #1
    silvia is offline Member
    Join Date
    Jul 2007
    Posts
    35
    Rep Power
    0

    Default My error is: ')' expected

    This is my code in AddressBookEntry.java:

    Java Code:
    public class AddressBookEntry{
    private String name;
    private String address;
    private String tel;
    private String email;
    
    AddressBookEntry(String name, String address, String tel, String email){
    this.name = name;
    this.address = address;
    this.tel = tel;
    this.email = email;
    }
    
    public String getName(){
    return name;
    }
    public void setName(String n){
    name = n;
    }
    
    public String getAddress(){
    return address;
    }
    public void setAddress(String a){
    address = a;
    }
    
    public String getTel(){
    return tel;
    }
    public void setTel(String t){
    tel = t;
    }
    
    public String getEmail(){
    return email;
    }
    public void setEmail(String e){
    email = e;
    }
    
    
    }
    This is my code in AddressBook:
    Java Code:
    public class AddressBook{
    private AddressBookEntry[] abe;
    private final int BOOK_SIZE = 100;
    private int count;
    
    AddressBook(){
    abe = new AddressBookEntry[BOOK_SIZE];
    count = 0;
    }
    
    public void addEntry(AddressBookEntry abe){
    this.abe[count++] = abe;
    }
    
    public void delEntry(String name){
    for (int i = 0; i<count; i++){
    
    if(abe[i].getName().equals(name)){
    abe[i] = abe[--count];
    }
    }
    }
    
    public void viewAll(){
    for(int i = 0; i<count; i++){
    System.out.println("Name: " + abe[i].getName());
    System.out.println("Address: " + abe[i].getAddress());
    System.out.println("Telno: " + abe[i].getTel());
    System.out.println("E-mail: " + abe[i].getEmail());
    }
    }
    
    public boolean update(String name, String address, String tel, String email){
    boolean found = false;
    for(int i = 0; i<count; i++){
    if(abe[i].getName().equals(name)){
    abe[i].setAddress(address);
    abe[i].setTel(tel);
    abe[i].setEmail(email);
    }
    }
    return found;
    }
    
    public static void main(String[] args){
    AddressBook abe = new AddressBook();
    AddressBookEntry ab = new AddressBookEntry(String name, String address, String tel, String email);
    ab.getName(abe);
    }
    }
    My error is:
    Java Code:
    Configuration: <Default>
    C:\Documents and Settings\gen\Desktop\myjavaprogram\AddressBook.java:47: ')' expected
    AddressBookEntry ab = new AddressBookEntry(String name, String address, String tel, String email);
    ^
    1 error
    Process completed.
    Thanks

  2. #2
    JavaBean's Avatar
    JavaBean is offline Moderator
    Join Date
    May 2007
    Posts
    1,270
    Rep Power
    9

    Default

    You have two errors there.

    First of all while calling a method or constructor, you dont write the types of the parameters. So use like this:

    Java Code:
    AddressBookEntry ab = new AddressBookEntry(name, address, tel, email);
    When you fix this and try to compile, you will see that you get another error: "can not find symbol". This is because you did not define and initialize your parameters (e.g. name) in that constructor. Define and initialize those parameters to fix this error:

    Java Code:
    String name = "John";

Similar Threads

  1. Identifier expected error
    By vasu18 in forum New To Java
    Replies: 1
    Last Post: 01-01-2008, 05:49 PM
  2. Error: ')' expected
    By baltimore in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 06:32 AM
  3. Error: <identifier> expected
    By barney in forum AWT / Swing
    Replies: 2
    Last Post: 07-31-2007, 07:38 AM
  4. Error: '{' expected
    By romina in forum New To Java
    Replies: 1
    Last Post: 07-26-2007, 09:34 AM
  5. MSG ERROR: : expected
    By Marty in forum New To Java
    Replies: 1
    Last Post: 05-31-2007, 02:21 AM

Posting Permissions

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