java - SearchByEmail print -
i have employeestore
class stores details employee's in company such name, id , e-mail. need method search hashmap e-mail addresses of employees , print out individual employee matching address.
i got code search map in answer can't manage print employee.
here code:
public class employeestore { hashmap<string, employee> map; public employeestore() { map = new hashmap<string, employee>(); } //.... public void add(employee employee) { map.put(employee.getemployeename(), employee); } public employee searchbyname(string name) { employee employee = map.get(name); system.out.println(employee); return employee; } public employee searchbyemail(string email) { (employee employee : map.values()) { if (email.equals(employee.getemployeeemail())) { return employee; } system.out.println(employee); } employee employee = map.get(email); system.out.println(employee); return employee; } }
to changed code this:
public employee searchbyemail(string email) { (employee employee : map.values()) { if (email.equals(employee.getemployeeemail())) { system.out.println(employee); return employee; } } return null; }
main:
public class mainapp { private static scanner keyboard = new scanner(system.in); public static void main(string[] args) { new mainapp().start(); } public void start() { 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")); store.searchbyname("james o' carroll"); //store.print(); } }
your searchbyxxx
methods return employee
should read value easy print it:
employee james = store.searchbyname("james o' carroll"); employee andy = store.searchbyemail("yahoo.com"); system.out.println(james); system.out.println(andy);
and need clean searchbyxxx
methods little , remove unnecessary print statements.
Comments
Post a Comment