The Application should be able to add an entry , view an entry and delete and entry.. All other functions are working properly but my applica tion cannot delete.. Please assit where i shuld place my delete method

import com.jjpeople.addressbook.action.actionresult.ShowAddressActionResult;
import com.jjpeople.addressbook.actionargument.ShowAddressActionArgument;
import com.jjpeople.addressbook.actionargument.DeleteAddressActionArgument;
import com.jjpeople.addressbook.businessdelegate.AddressBookDelegate;
import com.jjpeople.addressbook.businessdelegate.AddressBookDelegateException;
import com.jjpeople.addressbook.businessdelegate.AddressBookDelegateImpl;
import com.jjpeople.addressbook.businessdelegate.AddressBookEntry;
import com.jjpeople.serviceworker.action.AbstractAction;
import com.jjpeople.serviceworker.action.ActionException;
import com.jjpeople.serviceworker.controller.Controller;

/**
 * This application uses a Service to Worker pattern which is located in the
 * package: com.jjpeople.serviceworker
 * <p>
 * This action adds addresses to the address book. The AddressBookDelegateImpl
 * is responsible for persisting the addresses.
 * <p>
 * AddressBookDelegateImpl serializes and deserializes AddressBookEntryImpl
 * to and from files respectively.
 *
 * @author JDickerson
 * Created on 5 Aug 2008
 */
public class DeleteAddressAction extends AbstractAction {

    private AddressBookDelegate addressBookDelegate;



    /**
     * Initializes AddressBookDelegateImpl. The initialisation includes
     * creating a directory un der the user's home directory for this
     * application if it does not exist already
     */
    private void initialize() {

        try {
            addressBookDelegate = new AddressBookDelegateImpl();
        }
        catch( AddressBookDelegateException e ) {

            throw new RuntimeException(
                    "Fatal Exception initializing Address Book", e );
        }
    }


    /**
     * Constructor
     *
     * @param controller the controller to set in thisn action
     */
    public DeleteAddressAction( Controller controller ) {

        super( controller );
        initialize();
    }


    /* (non-Javadoc)
     * @see com.jjpeople.serviceworker.action.AbstractAction#execute()
     */

    public void execute() throws ActionException {


        DeleteAddressActionArgument deleteAddressActionArgument =
            ( DeleteAddressActionArgument )actionArgument;

       String name=deleteAddressActionArgument.getName();


        try {
            AddressBookEntry addressBookEntry =
            addressBookDelegate.deleteAddressBookEntry( name );
        }
        catch( AddressBookDelegateException e ) {

            throw new ActionException( "Could not delete Address Book Entry,= " +
                    name, e );
        }
    }
}

  package com.jjpeople.addressbook.actionargument;

import com.jjpeople.addressbook.action.ActionConstants;
import com.jjpeople.addressbook.businessdelegate.AddressBookEntry;
import com.jjpeople.serviceworker.action.actionargument.AbstractActionArgument;

/**
 * This application uses a Service to Worker pattern which is located in the
 * package: com.jjpeople.serviceworker
 * <p>
 * Before calling the execute method on the AddAddressAction, the controller,
 * AbstractController sets this class in the action. This class encapsulates
 * the arguments required to run the processing in the execute method of the
 * AddAddressAction.
 *
 * @author JDickerson
 * Created on 5 Aug 2008
 */
public class DeleteAddressActionArgument extends AbstractActionArgument
    implements ActionConstants {


   String name;



    /**
     * Constructor
     */
    public DeleteAddressActionArgument(String name) {

      super();
      this.name=name;

        setActionCommand( DELETE_ADDRESS_ACTION );
    }



 /**
  * Gets the name of the person we want to delete the address details
  * for
  *
  * @return the name of the person we want to delete the address details
  * for
  */
    public String getName(){
     return name;
    }



}

package com.jjpeople.addressbook.gui;

import java.io.File;
import java.io.*;
import com.jjpeople.addressbook.action.actionresult.ShowAddressActionResult;
import com.jjpeople.addressbook.action.actionresult.ShowAllNamesInAddressBookActionResult;
import com.jjpeople.addressbook.actionargument.AddAddressActionArgument;
import com.jjpeople.addressbook.actionargument.DeleteAddressActionArgument;
import com.jjpeople.addressbook.actionargument.ShowAddressActionArgument;
import com.jjpeople.addressbook.actionargument.ShowAllNamesInAddressBookActionArgument;
import com.jjpeople.addressbook.businessdelegate.AddressBookEntry;
import com.jjpeople.addressbook.businessdelegate.AddressBookEntryImpl;
import com.jjpeople.serviceworker.action.actionresult.ActionResult;
import com.jjpeople.serviceworker.controller.Controller;
import com.jjpeople.serviceworker.controller.ControllerException;
import com.jjpeople.serviceworker.gui.AbstractCommandlineGui;
import com.jjpeople.serviceworker.gui.GuiException;

/**
 * This application uses a Service to Worker pattern which is located in the
 * package: com.jjpeople.serviceworker
 * <p>
 * This class models the Gui.
 *
 * @author JDickerson
 * Created on 4 Aug 2008
 */
public class AddressBookGuiImpl extends AbstractCommandlineGui
    implements AddressBookGui {



    /**
     * If the Add Addresses option is chosen this method is executed
     *
     * @throws GuiException
     */
    private void showAddAddress() throws GuiException {

        AddressBookEntry addressBookEntry = new AddressBookEntryImpl();

        StringBuffer sb = new StringBuffer( LINE_SEPARATOR );
        sb.append( LINE_SEPARATOR ).append( LINE_SEPARATOR );
        sb.append( DIVIDER ).append( LINE_SEPARATOR );
        sb.append( "Address Book: Adding Entry" ).append( LINE_SEPARATOR );
        sb.append( DIVIDER ).append( LINE_SEPARATOR );
        sb.append( LINE_SEPARATOR );
        sb.append( "Please enter the following details:" );
        sb.append( LINE_SEPARATOR ).append( LINE_SEPARATOR );
        sb.append( "Name : " );

        print( sb.toString() );
        addressBookEntry.setName( readInput() );

        print( "Mobile Number : " );
        addressBookEntry.setMobileNumber( readInput() );

        print( "Landline Number : " );
        addressBookEntry.setLandlineNumber( readInput() );

        print( "First line Address : " );
        addressBookEntry.setFirstLineAddress( readInput() );

        print( "Second line Address : " );
        addressBookEntry.setSecondLineAddress( readInput() );

        print( "Town or City : " );
        addressBookEntry.setTownOrCity( readInput() );

        print( "Postcode : " );
        addressBookEntry.setPostcode( readInput() );

        print( "Country : " );
        addressBookEntry.setCountry( readInput() );

        AddAddressActionArgument addAddressActionArgument =
            new AddAddressActionArgument();

        addAddressActionArgument.setAddressBookEntry( addressBookEntry );

        try {
            controller.execute( addAddressActionArgument );
        }
        catch( ControllerException e ) {

            throw new GuiException( "Could not add address", e );
        }
    }


    /**
     * If the View Address option is found this method is called
     */
    private void showViewAddress() throws GuiException{

        StringBuffer sb = new StringBuffer( LINE_SEPARATOR );
        sb.append( LINE_SEPARATOR ).append( LINE_SEPARATOR );
        sb.append( DIVIDER ).append( LINE_SEPARATOR );
        sb.append( "Address Book" ).append( LINE_SEPARATOR );
        sb.append( DIVIDER ).append( LINE_SEPARATOR );
        sb.append( LINE_SEPARATOR );

        sb.append( "Please enter the name of the person you wish " +
                "to view the address details of:" );

        sb.append( LINE_SEPARATOR ).append( LINE_SEPARATOR );

        print( sb.toString() );

        String name = readInput();

        ShowAddressActionArgument showAddressActionArgument =
            new ShowAddressActionArgument( name );

        try {
            ActionResult actionResult =
                controller.execute( showAddressActionArgument );

            ShowAddressActionResult showAddressActionResult
                = ( ShowAddressActionResult )actionResult;

            AddressBookEntry addressBookEntry =
                    showAddressActionResult.getAddressBookEntry();

            renderAddressBookEntry( addressBookEntry );
        }
        catch( ControllerException e ) {

            throw new GuiException( "Could not retrieve address entry", e );
        }
    }






    /**
     * Renders an address book entry to the Gui
     *
     * @param addressBookEntry
     */
    private void renderAddressBookEntry(
            AddressBookEntry addressBookEntry ) {

        print( LINE_SEPARATOR );

        if ( addressBookEntry != null ) {

            print( addressBookEntry.toString() );
        }
        else {

            print( "Could not find entry" );
        }
    }


    /**
     * If the Delete Address option is found this method is called
     */
    private void  showDeleteAddress() throws GuiException{

       // AddressBookEntry addressBookEntry = new AddressBookEntryImpl(); 

        StringBuffer sb = new StringBuffer( LINE_SEPARATOR );
        sb.append( LINE_SEPARATOR ).append( LINE_SEPARATOR );
        sb.append( DIVIDER ).append( LINE_SEPARATOR );
        sb.append( "Address Book" ).append( LINE_SEPARATOR );
        sb.append( DIVIDER ).append( LINE_SEPARATOR );
        sb.append( LINE_SEPARATOR );

        sb.append( "Please enter the name of the person you wish " +
        "to delete the address details of:" );

        sb.append( LINE_SEPARATOR ).append( LINE_SEPARATOR );

        //print( sb.toString() );

        String name = readInput();

        DeleteAddressActionArgument deleteAddressActionArgument =
        new DeleteAddressActionArgument(name );


        try {

            controller.execute( deleteAddressActionArgument );


        }
        catch( ControllerException e ) {

            throw new GuiException( "Could not delete address", e );
        }
        catch (NullPointerException e){           
           throw new GuiException( "The Entry Does Not Exist", e ); 
         }
         }

        /**private boolean removeAddressBookEntry(AddressBookEntry addressBookEntry ) {

        if ( addressBookEntry != null ) {

         File deleted=new File(addressBookEntry,name);


        return deleted.delete();

        }  
         else {

          print( "Could not find entry" ); 
          }
          }



      private void endApplication() throws GuiException {  


        System.exit(0); 

         }*/





    /**
     * Shows all names in the address book
     */
    private void showViewAllNamesInAddressBook() throws GuiException {

        ShowAllNamesInAddressBookActionArgument
            showAllNamesInAddressBookActionArgument =
                  new ShowAllNamesInAddressBookActionArgument();

        try {
            ActionResult actionResult =
                controller.execute( showAllNamesInAddressBookActionArgument );

            ShowAllNamesInAddressBookActionResult
                showAllNamesInAddressBookActionResult
                    = ( ShowAllNamesInAddressBookActionResult )actionResult;

            String[] addressBookNames =
                showAllNamesInAddressBookActionResult.getAddressBookNames();

            renderAllAddressBookNames( addressBookNames );
        }
        catch( ControllerException e ) {

            throw new GuiException(
                    "Could not show all address book name", e );
        }
    }



    /**
     * Renders all adress book names
     *
     * @param addressBookNames addressBookNames to render
     */
    private void renderAllAddressBookNames( String[] addressBookNames ) {

        StringBuffer sb = new StringBuffer();

        for ( String name : addressBookNames ) {
            sb.append( name ).append( LINE_SEPARATOR );
        }

        print( sb.toString() );
    }


    /**
     * Constructor
     */
    public AddressBookGuiImpl( Controller controller ) {

        super( controller );
    }


    /* (non-Javadoc)
     * @see com.jjpeople.addressbook.gui.AddressBookGui#start()
     */
    public void start() throws GuiException {

        showMenu();
    }


    /* (non-Javadoc)
     * @see com.jjpeople.addressbook.gui.AddressBookGui#showMenu()
     */
    public void showMenu() throws GuiException {

        String entryNumber = "-1";

        while ( true ) {

            if ( entryNumber.equals( "1" ) ) {

                showAddAddress();
                entryNumber = "-1";
            }
            else if ( entryNumber.equals( "2" ) ) {

                showViewAddress();
                entryNumber = "-1";
            }
            else if ( entryNumber.equals( "3" ) ) {

                showViewAllNamesInAddressBook();
                entryNumber = "-1";
            }
            else if ( entryNumber.equals( "4" ) ) {

                showDeleteAddress();
                entryNumber = "-1";
            }
            else {

                StringBuffer sb = new StringBuffer( LINE_SEPARATOR );
                sb.append( LINE_SEPARATOR ).append( LINE_SEPARATOR );
                sb.append( DIVIDER ).append( LINE_SEPARATOR );
                sb.append( "Address Book" ).append( LINE_SEPARATOR );
                sb.append( DIVIDER ).append( LINE_SEPARATOR );
                sb.append( LINE_SEPARATOR );

                sb.append( "1. Add Address " ).append( LINE_SEPARATOR );
                sb.append( "2. View Address of one person" );
                sb.append( LINE_SEPARATOR );
                sb.append( "3. View all Names in Address book" );
                sb.append( LINE_SEPARATOR );

                sb.append( "4. Delete Address" );
                sb.append( LINE_SEPARATOR );

                sb.append( LINE_SEPARATOR ).append( LINE_SEPARATOR );

                sb.append( "Please enter a number of the action " +
                        "you wish to perform" );

                print( sb.toString() );

                entryNumber = readInput();
            }
        }
    }
}

Recommended Answers

All 11 Replies

can you elaborate a bit more? what exactly are the requirements? what is the error message you are getting if you get one?

My application should be able to delete an entry... Am gettin an error cannot find symbol "Method
delete()" in AddressBookDelegateImpl.java

either you don't have a method called delete in the AddressBookDelegateImpl class, or it has another signature than the one you call (other parameters it's expecting).

but, since you don't show the code of the actual AddressBookDelegateImpl class, it's a bit impossible for us to figure out which one it is.

public interface AddressBookDelegate {

    /**
     * Retrieves the address book details for the person
     *
     * @param name the name of the person to retreive the address book details
     * of
     *
     * @return the Address book details for the person
     *
     * @throws AddressBookDelegateException
     */
    public AddressBookEntry getAddressBookEntry( String name )
        throws AddressBookDelegateException;


    /**
     * Saves the address book details of a person
     *
     * @param addressBookEntry the address book entry to save
     *
     * @throws AddressBookDelegateException
     */
    public void saveAddressBookEntry(
            AddressBookEntry addressBookEntry )
                throws AddressBookDelegateException;


    /**
     * Retrieve list of all names in address book
     *
     * @return list of all names in address book
     */
    public String[] retrieveListOfAddressBookNames();


    /**
     * Deletes the address book details of a person
     *
     * @param addressBookEntry the address book entry to save
     *
     * @throws AddressBookDelegateException
     */


  public AddressBookEntry deleteAddressBookEntry( String name )
  throws AddressBookDelegateException;





}




package com.jjpeople.addressbook.businessdelegate;

import java.io.File;
import java.io.*;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.util.StringTokenizer;
import java.util.*;


/**
 * This application uses a Service to Worker pattern which is located in the
 * package: com.jjpeople.serviceworker
 * <p>
 * This class models saving and retrieving address book details using
 * the name of a the person to which the address details relate.
 * <p>
 * The object, AddressBookEntry, is serialized and deserialized from file
 *
 * @author JDickerson
 * Created on 5 Aug 2008
 */
public class AddressBookDelegateImpl implements AddressBookDelegate {

    private File userHomeDir;

    private File addressBookDirectory;



    /**
     * Initializes this delegate.
     * <p>
     * Creates a directory for this Address Book application in the user's
     * home directory if it does not already exist
     *
     * @throws AddressBookDelegateException
     */
    private void initialize() throws AddressBookDelegateException {

        String userHomeDirPath = System.getProperty( "user.home" );
        userHomeDir = new File( userHomeDirPath );

        addressBookDirectory = new File( userHomeDir, "ADDRESS_BOOK" );

        if ( ! addressBookDirectory.exists() ) {

            if ( ! addressBookDirectory.mkdir() ) {

                throw new AddressBookDelegateException(
                        "Could not make directory, " +
                            addressBookDirectory.getAbsolutePath() );
            }
        }
    }


    /**
     * Replaces Spaces with underscores
     *
     * @param string the string to replace the spaces with underscores
     *
     * @return the
     */
    private String replaceSpacesWithUnderScores( String string ) {

        return string.replaceAll( " ", "_" ).toLowerCase();
    }


    /**
     * Constructor
     */
    public AddressBookDelegateImpl() throws AddressBookDelegateException{

        initialize();
    }


    /* (non-Javadoc)
     * @see com.jjpeople.addressbook.businessdelegates.
     *          AddressBookDelegate#getAddressBook(java.lang.String)
     */
    public AddressBookEntry getAddressBookEntry( String name )
        throws AddressBookDelegateException {

        String nameWithUnderscores = replaceSpacesWithUnderScores( name );

        File fileToUnserialize =
            new File( addressBookDirectory, nameWithUnderscores );

        if ( ! fileToUnserialize.exists() ) {

            return null;
        }

        try {
            InputStream inputStream = new FileInputStream( fileToUnserialize );

            ObjectInputStream objectInputStream
                = new ObjectInputStream( inputStream );

            AddressBookEntry addressBookEntry =
                ( AddressBookEntry )objectInputStream.readObject();

            return addressBookEntry;
        }
        catch( FileNotFoundException e ) {

            throw new AddressBookDelegateException(
                    "Could not find the following file to deserialize, " +
                        fileToUnserialize.getAbsolutePath(), e );
        }
        catch( IOException e ) {

            throw new AddressBookDelegateException(
                    "Could not read inputStream of file, " +
                        fileToUnserialize.getAbsolutePath(), e );
        }
        catch( ClassNotFoundException e ) {

            throw new AddressBookDelegateException(
                    "Could not find class, " + AddressBookEntry.class +
                        " to desrialize file, " +
                            fileToUnserialize.getAbsolutePath(), e );
        }
    }

    /* (non-Javadoc)
     * @see com.jjpeople.addressbook.businessdelegates.
     *          AddressBookDelegate#saveAddressBookEntry(
     *                  com.jjpeople.addressbook.businessdelegates.
     *                          AddressBookEntry )
     */
    public void saveAddressBookEntry( AddressBookEntry addressBookEntry )
      throws AddressBookDelegateException {

      String nameWithUnderscores =
       replaceSpacesWithUnderScores( addressBookEntry.getName() );

       File fileToSerialize =
        new File( addressBookDirectory, nameWithUnderscores );

        if ( fileToSerialize.exists() ) {

        if ( fileToSerialize.delete() ) {

         throw new AddressBookDelegateException(
                "Was trying to save file, " +
                  fileToSerialize.getAbsolutePath() + " and found " +
                    "file already existed. Tried to delete it " +
                     "but failed." );
     }
     }
        else {
             try {
                 OutputStream outputStream =
                    new FileOutputStream( fileToSerialize );

                    ObjectOutputStream objectOutputStream =
           new ObjectOutputStream( outputStream );

                objectOutputStream.writeObject( addressBookEntry );
       }
              catch( FileNotFoundException e ) {

              throw new AddressBookDelegateException(
            "Could not find file, " +
           fileToSerialize.getAbsolutePath() +
              " to serialize to", e );
       }
        catch( IOException e ) {

            throw new AddressBookDelegateException(
           "Could not serialize addressBookEntry to " +
          "file, " + fileToSerialize.getAbsolutePath(), e );
      }
       }
       }





    /* (non-Javadoc)
     * @see com.jjpeople.addressbook.businessdelegates.
     *          AddressBookDelegate#deleteAddressBookEntry(
     *                  com.jjpeople.addressbook.businessdelegates.
     *                          AddressBookEntry )
     */

     public AddressBookEntry deleteAddressBookEntry( String name )
    throws AddressBookDelegateException {

    String nameWithUnderscores = replaceSpacesWithUnderScores( name );

    File fileToDelete =
    new File( addressBookDirectory, nameWithUnderscores );

    if ( ! fileToDelete.exists() ) {

    return null;
    }

    try {
    InputStream inputStream = new FileInputStream( fileToDelete );

    ObjectInputStream objectInputStream
    = new ObjectInputStream( inputStream );

    AddressBookEntry addressBookEntry =
    ( AddressBookEntry )objectInputStream.readObject();

   return addressBookEntry.delete();
    }
    catch( FileNotFoundException e ) {

     throw new AddressBookDelegateException(
     "Could not find the following file to deserialize, " +
      fileToDelete.getAbsolutePath(), e );
     }
     catch( IOException e ) {

      throw new AddressBookDelegateException(
      "Could not read inputStream of file, " +
        fileToDelete.getAbsolutePath(), e );
     }
      catch( ClassNotFoundException e ) {

     throw new AddressBookDelegateException(
      "Could not find class, " + AddressBookEntry.class +
      " to desrialize file, " +
      fileToDelete.getAbsolutePath(), e );
     }
     }

    /* (non-Javadoc)
     * @see com.jjpeople.addressbook.businessdelegate.
     *          AddressBookDelegate#retrieveListOfAddressBookNames()
     */
    public String[] retrieveListOfAddressBookNames() {

        String[] addressBookNames = addressBookDirectory.list();

        String[] formattedAddressBookNames =
            new String[ addressBookNames.length ];

        String unFormattedName;
        StringTokenizer tokenizer;
        String token;
        String formattedName = "";

        for( int i=0; i<addressBookNames.length; i++ ) {

            // convert e.g. "john_dickerson" to "john dickerson"
            unFormattedName = addressBookNames[ i ].replaceAll( "_", " " );
            tokenizer = new StringTokenizer( unFormattedName, " " );

            // convert "john dickerson" to "John Dickerson"
            while ( tokenizer.hasMoreTokens() ) {

                token = tokenizer.nextToken();

                formattedName =
                    formattedName + " " +
                        Character.toUpperCase( token.charAt( 0 ) ) +
                            token.substring( 1 );
            }

            formattedAddressBookNames[ i ] = formattedName.trim();
            formattedName = "";
        }

        return formattedAddressBookNames;
    }
}
public AddressBookEntry deleteAddressBookEntry( String name )
throws AddressBookDelegateException {

that is the delete method in your class, but you according to the error message you are getting, you are calling delete(), which isn't there. that's your problem.

also: I must say, I don't really understand the architecture of your application. a more logical one, to me personally, would be something like:

    public class MyList{

      private ArrayList<MyObject> list = new ArrayList<MyObject>();

      public void addObject(MyObject toAdd){
        list.add(toAdd);
      }

      public void addIfNotYetInList(MyObject toAdd){
        if ( !list.contains(toAdd);
          list.add(toAdd);
      }
      // you can make this a void too, the boolean just lets you know if the element
      // wasn't in the list, or if the delete failed
      public boolean deleteObject(MyObject toDelete){
          return list.remove(toDelete);
      }
    }

Do i create a delete method and where should i place it..given other methods below i have tried to implement it but still not deleting..

public interface AddressBookEntry {

    /**
     * Gets name of the person we wish to retrieve or save the Address Book
     * Entry under
     *
     * @return name of the person we wish to retrieve or save the Address Book
     * Entry under
     */
    public String getName();


    /**
     * Sets the name of the person we wish to retrieve or save the Address Book
     * Entry under
     *
     * @param name name of the person we wish to retrieve or save the
     * Address Book Entry under
     */
    public void setName( String name );


    /**
     * Get mobile number
     *
     * @return mobile number
     */
    public String getMobileNumber();


    /**
     * Set thne mobile number
     *
     * @param mobileNumber mobile number to set
     */
    public void setMobileNumber( String mobileNumber );


    /**
     * Gets the land line number
     *
     * @return land line number
     */
    public String getLandlineNumber();


    /**
     * Sets the land line number
     *
     * @param landlineNumber the land line number to set
     */
    public void setLandlineNumber( String landlineNumber );


    /**
     * Gets the first line of the address
     *
     * @return the first line of the address
     */
    public String getFirstLineAddress();


    /**
     * Sets the first line of the address
     *
     * @param firstLineAddress the first line of the address to set
     */
    public void setFirstLineAddress( String firstLineAddress );


    /**
     * Gets the second line of the address
     *
     * @return the second line of the address
     */
    public String getSecondLineAddress();


    /**
     * Sets the second line of the address
     *
     * @param secondLineAddress second line of the address to set
     */
    public void setSecondLineAddress( String secondLineAddress );


    /**
     * Gets the town or city
     *
     * @return the town or city
     */
    public String getTownOrCity();


    /**
     * Sets the town or city
     *
     * @param townOrCity town or city to set
     */
    public void setTownOrCity( String townOrCity );


    /**
     * Gets then postcode
     *
     * @return the postcode
     */
    public String getPostcode();


    /**
     * Sets the postcode
     *
     * @param postcode the postcode to set
     */
    public void setPostcode( String postcode );


    /**
     * Gets the country
     *
     * @return the country
     */
    public String getCountry();


    /**
     * Sets the country
     *
     * @param country the country to set
     */
    public void setCountry( String country );




 public void delete();


}



public class AddressBookEntryImpl
    implements AddressBookEntry, LineFormatter, Serializable {

    private String name;
    private String landlineNumber;
    private String mobileNumber;
    private String firstLineAddress;
    private String secondLineAddress;
    private String townOrCity;
    private String postcode;
    private String country;


    /**
     * Constructor
     */
    public AddressBookEntryImpl() {
    }


    /* (non-Javadoc)
     * @see com.jjpeople.addressbook.businessdelegates.AddressBook#getCountry()
     */
    public String getCountry() {

        return country;
    }


    /* (non-Javadoc)
     * @see com.jjpeople.addressbook.businessdelegates.
     *          AddressBook#getFirstLineAddress()
     */
    public String getFirstLineAddress() {

        return firstLineAddress;
    }


    /* (non-Javadoc)
     * @see com.jjpeople.addressbook.businessdelegates.
     *          AddressBook#getLandlineNumber()
     */
    public String getLandlineNumber() {

        return landlineNumber;
    }


    /* (non-Javadoc)
     * @see com.jjpeople.addressbook.businessdelegates.
     *          AddressBook#getMobileNumber()
     */
    public String getMobileNumber() {

        return mobileNumber;
    }


    /* (non-Javadoc)
     * @see com.jjpeople.addressbook.businessdelegates.AddressBook#getName()
     */
    public String getName() {

        return name;
    }


    /* (non-Javadoc)
     * @see com.jjpeople.addressbook.businessdelegates.
     *          AddressBook#getPostcode()
     */
    public String getPostcode() {

        return postcode;
    }


    /* (non-Javadoc)
     * @see com.jjpeople.addressbook.businessdelegates.
     *          AddressBook#getSecondLineAddress()
     */
    public String getSecondLineAddress() {

        return secondLineAddress;
    }


    /* (non-Javadoc)
     * @see com.jjpeople.addressbook.businessdelegates.
     *          AddressBook#getTownOrCity()
     */
    public String getTownOrCity() {

        return townOrCity;
    }


    /* (non-Javadoc)
     * @see com.jjpeople.addressbook.businessdelegates.
     *          AddressBook#setCountry(java.lang.String)
     */
    public void setCountry( String country ) {

        this.country = country;
    }


    /* (non-Javadoc)
     * @see com.jjpeople.addressbook.businessdelegates.
     *          AddressBook#setFirstLineAddress(java.lang.String)
     */
    public void setFirstLineAddress( String firstLineAddress ) {

        this.firstLineAddress = firstLineAddress;
    }


    /* (non-Javadoc)
     * @see com.jjpeople.addressbook.businessdelegates.
     *          AddressBook#setLandlineNumber(java.lang.String)
     */
    public void setLandlineNumber( String landlineNumber ) {

        this.landlineNumber = landlineNumber;
    }


    /* (non-Javadoc)
     * @see com.jjpeople.addressbook.businessdelegates.
     *          AddressBook#setMobileNumber(java.lang.String)
     */
    public void setMobileNumber( String mobileNumber ) {

        this.mobileNumber = mobileNumber;
    }


    /* (non-Javadoc)
     * @see com.jjpeople.addressbook.businessdelegates.
     *          AddressBook#setName(java.lang.String)
     */
    public void setName( String name ) {

        this.name = name;
    }


    /* (non-Javadoc)
     * @see com.jjpeople.addressbook.businessdelegates.
     *          AddressBook#setPostcode(java.lang.String)
     */
    public void setPostcode( String postcode ) {

        this.postcode = postcode;
    }


    /* (non-Javadoc)
     * @see com.jjpeople.addressbook.businessdelegates.
     *          AddressBook#setSecondLineAddress(java.lang.String)
     */
    public void setSecondLineAddress( String secondLineAddress ) {

        this.secondLineAddress = secondLineAddress;
    }


    /* (non-Javadoc)
     * @see com.jjpeople.addressbook.businessdelegates.
     *          AddressBook#setTownOrCity(java.lang.String)
     */
    public void setTownOrCity( String townOrCity ) {

        this.townOrCity = townOrCity;
    }

  /** public void deleteEntry(String name){
      this.name=name;
       name.delete();}*/

   public void delete(){

    if(name == null) return null;

    for (int i = 0; i <  counter; i++) {
        // make sure we have an entry
         // we know name is not null 
       if (addressBookEntry != null && name.equals(addressBookEntry.getName())) {
            // null out the deleted entry 
            addressBookEntry = null;
             break; // If you know you have unique names, you can leave the for loop now 
        } // end if 
    } // end for i
   this.addressBookEntry=addressBookEntry;
}




     /**
     * Provides String representation of this object
     *
     * @return string representation of this object
     */
    public String toString() {

        StringBuffer sb = new StringBuffer();

        sb.append( "Name : " ).append( name ).append( LINE_SEPARATOR );

        sb.append( "Landline Number : " ).append( landlineNumber );
        sb.append( LINE_SEPARATOR );

        sb.append( "Mobile Number : " ).append( mobileNumber );
        sb.append( LINE_SEPARATOR );

        sb.append( "First Line Address : " ).append( firstLineAddress );
        sb.append( LINE_SEPARATOR );

        sb.append( "Second Line Address : " ).append( secondLineAddress );
        sb.append( LINE_SEPARATOR );

        sb.append( "Town Or City : " ).append( townOrCity );
        sb.append( LINE_SEPARATOR );

        sb.append( "Postcode : " ).append( postcode );
        sb.append( LINE_SEPARATOR );

        sb.append( "Country : " ).append( country );
        sb.append( LINE_SEPARATOR );

        return sb.toString();
    }
}

actually, you do have a delete method, you just have to call it using the correct name and correct paramets for your code.

Do i use the deleteEntry() method

public void deleteEntry(String name){
      this.name=name;
       name.delete();}

or the delete() method

public void delete(){

    if(name == null) return null;

    for (int i = 0; i <  counter; i++) {
        // make sure we have an entry
         // we know name is not null 
       if (addressBookEntry != null && name.equals(addressBookEntry.getName())) {
            // null out the deleted entry 
            addressBookEntry = null;
             break; // If you know you have unique names, you can leave the for loop now 
        } // end if 
    } // end for i
   this.addressBookEntry=addressBookEntry;
}
 public void deleteEntry(String name){
       this.name=name;
        name.delete();}

how do you expect this to work? the String class doesn't have a delete method.

How do i call the method?

what method are you trying to call?
if you're calling it from within the same class:
<mehodName>(<Parameters>);

if it's from within another class
<instanceName>.<methodName>(<Parameters>);

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.