Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 5th, 2012  |  syntax: None  |  size: 4.01 KB  |  hits: 9  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Email method not working
  2. case 2:
  3.                System.out.println("Search by Email.");
  4.                Employee employeeSearchEmail = MenuMethods.userInputByEmail();
  5.                  Store.searchByEmail(employeeSearchEmail.getEmployeeEmail());
  6.        
  7. //Imports
  8. import java.util.Scanner;
  9. //********************************************************************
  10.  
  11. public class MenuMethods
  12. {
  13.     private static Scanner keyboard = new Scanner(System.in);
  14.  
  15.  
  16.  
  17.     //Methods for the Company Application menu.
  18.     //Method for validating the choice.
  19.          public static int getMenuChoice(String menuString, int limit, String prompt, String errorMessage)
  20.          {
  21.                 System.out.println(menuString);
  22.                 int choice = inputAndValidateInt(1, limit, prompt, errorMessage);
  23.                 return choice;
  24.          }
  25.     //********************************************************************
  26.     //This method is used in the getMenuChoice method.
  27.             public static int inputAndValidateInt(int min, int max, String prompt, String errorMessage)
  28.             {
  29.                 int number;
  30.                 boolean valid;
  31.                 do {
  32.                     System.out.print(prompt);
  33.                     number = keyboard.nextInt();
  34.                     valid = number <= max && number >= min;
  35.                     if (!valid) {
  36.                         System.out.println(errorMessage);
  37.                     }
  38.                 } while (!valid);
  39.                 return number;
  40.             }
  41.     //********************************************************************
  42.     public static Employee userInput()
  43.     {
  44.          String temp = keyboard.nextLine();
  45.          Employee e = null;
  46.          System.out.println("Please enter the Employee Name:");
  47.          String employeeName = keyboard.nextLine();
  48.          System.out.println("Please enter the Employee ID:");
  49.          int employeeId = keyboard.nextInt();
  50.          temp = keyboard.nextLine();
  51.          System.out.println("Please enter the Employee E-mail address:");
  52.          String employeeEmail  = keyboard.nextLine();
  53.          return e = new Employee(employeeName , employeeId, employeeEmail);
  54.  
  55.     }
  56.     //********************************************************************
  57.     public static Employee userInputByName()
  58.     {
  59.         //String temp is for some reason needed.  If it is not included
  60.         //The code will not execute properly.
  61.          String temp = keyboard.nextLine();
  62.          Employee e = null;
  63.          System.out.println("Please enter the Employee Name:");
  64.          String employeeName = keyboard.nextLine();
  65.  
  66.          return e = new Employee(employeeName);
  67.  
  68.     }
  69.     //********************************************************************
  70.     public static Employee userInputByEmail()
  71.     {
  72.         //String temp is for some reason needed.  If it is not included
  73.         //The code will not execute properly.
  74.          String temp = keyboard.nextLine();
  75.          Employee e = null;
  76.          System.out.println("Please enter the Employee Email:");
  77.          String employeeEmail = keyboard.nextLine();
  78.         //This can use the employeeName's constructor because java accepts the parameters instead
  79.          //of the name's.
  80.          return e = new Employee(employeeEmail);
  81.  
  82.     }
  83.     //********************************************************************
  84.  
  85.  
  86. }
  87.        
  88. public boolean searchByEmail(String employeeEmail)
  89.     {
  90.             //(for(Employee e : map.values()) {...})
  91.             //and check for each employee if his/her email matches the searched value
  92.             boolean employee = map.equals(employeeEmail);    
  93.             System.out.println(employee);
  94.             return employee;
  95.  
  96.     }
  97.        
  98. map.equals(employeeEmail);
  99.        
  100. Employee findByEmail(String email) {
  101.     for (Employee employee : yourMap.values())
  102.         if (employee.getEmail().equals(email))
  103.             return employee;
  104.  
  105.     // Not found.
  106.     return null;
  107. }
  108.        
  109. public boolean searchByEmail(String employeeEmail) {
  110.     boolean employee = findByEmail(employeeEmail) != null;
  111.     System.out.println(employee);
  112.     return employee;
  113. }