Answered step by step
Verified Expert Solution
Link Copied!

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
publicstaticvoidsaveInfo(ArrayListusers,ArrayListstoreitems,Stringbagstore)
throwsIOException{
FileWriteref=null;
try{
ef=newFileWriter(bagstore);
for(Usersu:users){
ef.write(u.toString());
ef.write(System.lineSeparator());
}
ef.write(System.lineSeparator());
ef.write("--------------------");
ef.write(System.lineSeparator());
for(StoreItemss:storeitems){
ef.write(s.toString());
ef.write(System.lineSeparator());
}
}finally{
if(ef!=null){
ef.close();
}
}
}
// checking the users id and password
publicstaticUsersauthenticate(intId,StringName,Stringpassword){
for(Usersuser:users){
if(user.getId()==Id&&user.equals(Name)&&user.Password(password)){
returnuser;
}
}
returnnull;
}
// checking the users id and password (customer)
publicstaticUsersauthenticate2(intId,StringName){
for(Usersuser:users){
if(user.getId()==Id&&user.equals(Name)){
returnuser;
}
}
returnnull;
}
// lists the items
publicstaticArrayListItemsByCategory(Stringcategory){
ArrayListByCategory=newArrayList<>();
for(StoreItemsItem:storeitems){
if(Item.getCategory().equals(category)){
ByCategory.add(Item);
}
}
returnByCategory;
}
// search an item
publicstaticArrayListsearchItems(Stringsearched){
ArrayListsearch=newArrayList<>();
for(StoreItemsItem:storeitems){
if(Item.getName().toLowerCase().contains(searched.toLowerCase())){
search.add(Item);
}
}
returnsearch;
}
// adds an item to the array list
publicstaticArrayListaddItem(Stringname,doubleprice,Stringcategory,Stringcolor){
StoreItemsadd=newStoreItems(name,price,category,color);
storeitems.add(add);
returnstoreitems;
}
// creates a new customer account
publicstaticArrayListcreateCustomerAcc(intId,StringName){
Userscustomer=newCustomer(Id,Name);
users.add(customer);
returnusers;
}
// adds a new user to the array list
publicstaticArrayListaddUser(intId,StringName){
Usersuser=newCustomer(Id,Name);
users.add(user);
returnusers;
}
// the user logging out method
publicstaticvoidlogOut(StringName){
System.out.printf("%s Logged out",Name);
}
}
convert it to gui code

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions