Answered step by step
Verified Expert Solution
Question
1 Approved Answer
public class Store { public static ArrayList users; / / creating the array lists. public static ArrayList storeitems; / / a method to save array
publicclassStore
publicstaticArrayListusers; creating the array lists.
publicstaticArrayListstoreitems;
a method to save array list to file
publicstaticvoidsaveInfoArrayListusersArrayListstoreitemsStringbagstore
throwsIOException
FileWriterefnull;
try
efnewFileWriterbagstore;
forUsersu:users
efwriteutoString;
efwriteSystemlineSeparator;
efwriteSystemlineSeparator;
efwrite;
efwriteSystemlineSeparator;
forStoreItemss:storeitems
efwritestoString;
efwriteSystemlineSeparator;
finally
ifefnull
efclose;
checking the users id and password
publicstaticUsersauthenticateintIdStringNameStringpassword
forUsersuser:users
ifusergetIdId&&userequalsName&&userPasswordpassword
returnuser;
returnnull;
checking the users id and password customer
publicstaticUsersauthenticateintIdStringName
forUsersuser:users
ifusergetIdId&&userequalsName
returnuser;
returnnull;
lists the items
publicstaticArrayListItemsByCategoryStringcategory
ArrayListByCategorynewArrayList;
forStoreItemsItem:storeitems
ifItemgetCategoryequalscategory
ByCategory.addItem;
returnByCategory;
search an item
publicstaticArrayListsearchItemsStringsearched
ArrayListsearchnewArrayList;
forStoreItemsItem:storeitems
ifItemgetNametoLowerCasecontainssearchedtoLowerCase
search.addItem;
returnsearch;
adds an item to the array list
publicstaticArrayListaddItemStringnamedoublepriceStringcategoryStringcolor
StoreItemsaddnewStoreItemsnamepricecategorycolor;
storeitems.addadd;
returnstoreitems;
creates a new customer account
publicstaticArrayListcreateCustomerAccintIdStringName
UserscustomernewCustomerIdName;
users.addcustomer;
returnusers;
adds a new user to the array list
publicstaticArrayListaddUserintIdStringName
UsersusernewCustomerIdName;
users.adduser;
returnusers;
the user logging out method
publicstaticvoidlogOutStringName
System.out.printfs Logged out",Name;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started