Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8255871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T01:40:30+00:00 2026-06-08T01:40:30+00:00

Hey my Delete and SearchByEmail methods are not working. Delete basically asks all the

  • 0

Hey my Delete and SearchByEmail methods are not working. Delete basically asks all the right questions but does not delete the Employee the user chooses. SearchByEmail returns all of the employees rather than the one the user has asked for.

Here is my code:
MainApp

//Imports.
import java.util.Scanner;
//********************************************************************  
public class MainApp
{
    //The Scanner is declared here for use throughout the whole MainApp.
    private static Scanner keyboard = new Scanner(System.in);

    public static void main(String[] args)
    {
        new MainApp().start();

    }
    public void start()
    {
//Create a Store named Store and add Employee's to the Store.
        EmployeeStore Store = new EmployeeStore();
        Store.add(new Employee ("James O' Carroll", 18,"hotmail.com"));

        Store.add(new Employee ("Andy Carroll", 1171,"yahoo.com"));

        Store.add(new Employee ("Luis Suarez", 7,"gmail.com"));
//********************************************************************      

…………………………

        case 3:
             System.out.println("Delete");
              Employee employeeDelete = MenuMethods.userInputByName();
              Store.searchByName(employeeDelete.getEmployeeName());
             Store.remove(employeeDelete);


                break;

        case 4:
                System.out.println("Delete All");
                Store.clear();

                break;
        case 5:
           System.out.println("Edit");
           Employee employeeEdit = MenuMethods.userInputByName();
           Store.searchByName(employeeEdit.getEmployeeName());
         if (employeeEdit != null)
        {
            employeeEdit.setEmployeeName("Joe");
            employeeEdit.setEmployeeId(1);
            employeeEdit.setEmployeeEmail("webmail.com");
           Store.edit(employeeEdit);
        }

            break;
        case 6:
            int searchChoice; 
            searchChoice =MenuMethods.getMenuChoice("1.Search by Name.\n2.Search by Email.", 2, "Please enter your choice:", "Error [1,2] Only");
            String temp = keyboard.nextLine();
            System.out.println("Search");
           switch (searchChoice) {
               case 1:
                   System.out.println("Search by Name.");
                   Employee employeeSearchName = MenuMethods.userInputByName();
                 Store.searchByName(employeeSearchName.getEmployeeName());

           break;

           case 2:
               System.out.println("Search by Email.");
               Employee employeeSearchEmail = MenuMethods.userInputByEmail();
               Store.searchByEmail(employeeSearchEmail.getEmployeeEmail());
           break;


             //Test Code.
            /*System.out.println("Search");
                Employee employee1 = MenuMethods.userInputByName();
                Employee foundEmployee = Store.searchByName(employee1.getEmployeeName());

                if (foundEmployee != null) {
                    System.out.println("Found employee!");
                } else {
                    System.out.println("Not Found!");
                }*/
           }

            break;
        case 7:
             System.out.println("Print");
            Store.print();

            break;
        case 8:
             System.out.println("Exit");

            break;
        }


        } while (choice != 8);

     }
}

MenuMethods

//Imports
import java.util.Scanner;
//********************************************************************

public class MenuMethods 
{
    private static Scanner keyboard = new Scanner(System.in);


..............................
    public static Employee userInput()
    {
         String temp = keyboard.nextLine();
         Employee e = null;
         System.out.println("Please enter the Employee Name:");
         String employeeName = keyboard.nextLine();
         System.out.println("Please enter the Employee ID:");
         int employeeId = keyboard.nextInt();
         temp = keyboard.nextLine();
         System.out.println("Please enter the Employee E-mail address:");
         String employeeEmail  = keyboard.nextLine();
         return e = new Employee(employeeName , employeeId, employeeEmail);

    }
    //********************************************************************
    public static Employee userInputByName()
    {
        //String temp is for some reason needed.  If it is not included
        //The code will not execute properly.
         String temp = keyboard.nextLine();
         Employee e = null;
         System.out.println("Please enter the Employee Name:");
         String employeeName = keyboard.nextLine();

         return e = new Employee(employeeName);

    }
    //********************************************************************
    public static Employee userInputByEmail()
    {
        //String temp is for some reason needed.  If it is not included
        //The code will not execute properly.
         String temp = keyboard.nextLine();
         Employee e = null;
         System.out.println("Please enter the Employee Email:");
         String employeeEmail = keyboard.nextLine();
        //This can use the employeeName's constructor because java accepts the parameters instead
         //of the name's.
         return e = new Employee(employeeEmail);

    }
    //********************************************************************


}

EmployeeStore

//Imports.
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
//********************************************************************
public class EmployeeStore implements Serializable
{
    HashMap<String, Employee> map;
    private static Scanner keyboard = new Scanner(System.in);

//Constructor.  
    public EmployeeStore()
    {
        map = new HashMap<String,Employee>();
    }
//********************************************************************
//Hashmap Methods.
//Add to the Hashmap : Employee.
    public void add(Employee employee)
    {

        map.put(employee.getEmployeeName(), employee);
    }
//********************************************************************
//Remove from the Hashmap : Employee.
    public Employee remove(Employee key)
    {
      //Remove the Employee by name.
        if(map.containsKey(key))
            return map.remove(key); //if its there remove and return
        else
            return null; //if its not there return 0x00000000 address
    }
//********************************************************************
//Clear the Hashmap : Employee.
    public void clear()
    {
        map.clear();
    }
    //********************************************************************
//Print the Hashmap : Employee. 
    public void print()
    {
        System.out.println("\n********Employee's in the Company.********");
        for (Employee employee : map.values())
        {
            //System.out.println(employee); to print the toString of Employee class
            //or:
            System.out.println("Employee Name:\t" + employee.getEmployeeName());
            System.out.println("Employee Id:\t" + employee.getEmployeeId());
            System.out.println("E-mail:\t"+ employee.getEmployeeEmail());
        }

    }
    public Employee get(String name){
        return map.get(name);
    }
    /*public void searchByName ()
    {
        //(for(Employee e : map.values()) {...}) 
        //and check for each employee if his/her email matches the searched value
        for(Employee e : map.values())
        {
            System.out.println(e);
            map.equals(getClass());

        }
    }*/
//********************************************************************
    public Employee searchByName(String employeeName) 
    {
        Employee employee = map.get(employeeName);    
        System.out.println(employee);
        return employee;
    }
//********************************************************************
    Employee findByEmail(String email) {
        for (Employee employee : map.values())
            if (employee.getEmployeeEmail().equals(email))
                return employee;

        // Not found.
        return null;
    }

    public boolean searchByEmail(String employeeEmail) {
        boolean employee = findByEmail(employeeEmail) != null;
        System.out.println(employee);
        return employee;
    }


    /*public void searchByName ()
    {
        //(for(Employee e : map.values()) {...}) 
        //and check for each employee if his/her email matches the searched value
        for(Employee e : map.values())
        {
            System.out.println(e);
            map.equals(getClass());
            System.out.println(e);
                map.equals(employee.getEmployeeEmail());

        }
    }*/
//********************************************************************
    public void edit(Employee employee)
    {
        map.put(employee.getEmployeeName(), employee);
    }


//********************************************************************
    public EmployeeStore copy()
    {
        //instanciate the destination copy and give same name
        EmployeeStore Copy = new EmployeeStore();

        //by specifying the type of the entry in the for loop i.e. <>
        // we don't have to typecast the getKey() and getValue() methods
        //as shown in the commented out line inside the for loop
        for(Map.Entry<String, Employee> entry : map.entrySet())
        {
            //getting each key-value and putting into the copy
            //theCopy.add((MovieKey)entry.getKey(), (Movie)entry.getValue());
            Copy.add(entry.getValue());
        }
        //return address of the new MovieStore object
        return Copy;
    }
//********************************************************************


//********************************************************************  
//********************************************************************


}

Employee

//Imports:

//********************************************************************
//Employee Class.
public class Employee
{
//Variables.
    private String employeeName;
    private int employeeId;
    private String employeeEmail;
//********************************************************************  
//Constructors.
    public Employee(String employeeName, int employeeId, String employeeEmail) 
    {
        this.employeeName = employeeName;
        this.employeeId = employeeId;
        this.employeeEmail = employeeEmail;
    }
//Overloading the constructor for the use with userInputByName method.
    public Employee(String employeeName) 
    {
        this.employeeName = employeeName;
    }

//********************************************************************
//Getters.
    public String getEmployeeEmail() 
    {
        return employeeEmail;
    }

    public String getEmployeeName() 
    {
        return employeeName;
    }
    public int getEmployeeId() 
    {
        return employeeId;
    }
//********************************************************************
//Setters.
    public void setEmployeeEmail(String employeeEmail) 
    {
        this.employeeEmail = employeeEmail;
    }
    public void setEmployeeName(String employeeName) 
    {
        this.employeeName = employeeName;
    }
    public void setEmployeeId(int employeeId)
    {
        this.employeeId = employeeId;
    }

//********************************************************************
//toString method.
    public String toString() 
    {
        return "\t\t\tEmployee\n" +
                "********************************************************************\n"+
                "Employee Name: "+ employeeName +"\n"+ 
                "Employee Id: " + employeeId +"\n"+  
                "Employee Email: " + employeeEmail;
    }
//********************************************************************
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T01:40:33+00:00Added an answer on June 8, 2026 at 1:40 am

    If you have provided your Employee class it should be more clear, anyways.

    The problem has to be the following:

    return e = new Employee(employeeEmail);
    

    So it is about your Employee Constructor which is defined for employeeName but you initialize employee object with employeeEmail. Therefore, it assigns email as a name..

    Just return the search phrase as a String don’t create new Employee objects for searches or other operations.

    Without destructing your structure, I would suggest you to add another constructor to Employee class

    public Employee(String employeeName,String employeeEmail) 
    {
        this.employeeName = employeeName;
        this.employeeEmail = employeeEmail;
    }
    

    and

    public static Employee userInputByEmail()
    {
         ...
         ...
         return e = new Employee(null,employeeEmail);
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey all i am trying to delete a key from the registery but i
Hey, I need to delete all images from a string and I just can't
Hey, I need to delete a part of a string (I'm not a :
Hey all i am trying to figure out a way to delete something inside
Hey, all. Working on my first Rails app. I've searched all around - read
hey guys having this really simple problem but cant seem to figure out have
Hey guys I wanted to create a JScrollPane but it won't work... and I
Hey, I was trying to delete an item form a list (without using set
Hey, I'm learning an ecommerce package (Spree). The problem arises after I delete a
Hey, I'm having some trouble here... How can I delete an entire text from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.