Posts

Showing posts with the label Practice Problem

Java Interfaces and Exception Handling - Practice Problem with Solution

Problem Statement: Create a UserService Interface with following methods signatures. void addUser(User user) throws UserAlreadyExistException User getUser(int userID) throws UserAccountIsBlockedException void updateUser(User user) void deleteUser(int userID) void unblockUser(int userID) ArrayList getAllUsers() Define InMemoryUserService class that shall implement UserService interface. In InMemoryUserService class, use User ArrayList for storage of user objects.  The methods shall change/read this list to perform the required operations. Test all methods from UserTest class. Getting information from user input is encourged but optional. Define and properly encapsulate atleast id, name and status instance attributes in User class of type int , String and boolean . How you check whether a user account is blocked? If status attribute is false, it means user account is blocked. True represent the account is active. UserAlreadyExistException exception shall be thrown if...