Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

how to covert this code to gui code ? import java.io . File; import java.io . FileWriter; import java.io . IOException; import java.util.ArrayList; import java.util.Arrays;

how to covert this code to gui code ?
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.ConcurrentModificationException;
import java.util.InputMismatchException;
import java.util.List;
import java.util.Scanner;
public class Main extends Store {
public static void main(String[] args) throws Exception, IOException {
Scanner in = new Scanner(System.in);
users = new ArrayList<>();
// adding the users to the array list
users.add(new Manager(0, "owner", "owner"));
users.add(new Manager(1, "Nour", "Nour111"));
users.add(new Manager(2, "Ranad", "Ranad222"));
users.add(new Employee(3, "Sara", "Sara333"));
users.add(new Employee(4, "Safa", "Safa444"));
users.add(new Customer(5, "Rana"));
users.add(new Customer(6, "Rahma"));
users.add(new Customer(7, "Mona"));
storeitems = new ArrayList<>();
// adding the items to the array list
storeitems.add(new StoreItems("MiniClutch",80.5, "Clutchs", "Black"));
storeitems.add(new StoreItems("BagClutch",55.5, "Clutchs", "Black"));
storeitems.add(new StoreItems("Schoolbackpack",20.75, "Backpacks", "Red"));
storeitems.add(new StoreItems("Travelbackpack",77.25, "Backpacks", "Brown"));
storeitems.add(new StoreItems("MiniTote",120.7, "Totebags", "Silver"));
storeitems.add(new StoreItems("LargeTote",90, "Totebags", "Gold"));
storeitems.add(new StoreItems("MiniCrosebody",150.5, "Crosebody", "White"));
storeitems.add(new StoreItems("MediumCrosebody",130.5, "Crosebody", "Blue"));
// saving data in the created file.
String CarryAll = "store.data";
try {
Store.saveInfo(users, storeitems, CarryAll);
} catch (IOException e){
}
// the menu of the store
System.out.println("Menu: ");
System.out.println("1.Login ");
System.out.print("Enter your Choice: ");
int choice = in.nextInt();
while (choice !=1){
System.out.print("invaild choice.
Enter a valid choice: ");
choice = in.nextInt();
}
String N;
while (choice ==1){
System.out.print("Enter ID: "); // user interning the id
int id = in.nextInt();
// checking the id of the users
if (id >=0 && id <=2){
System.out.print("Enter Name: ");
N = in.next();
System.out.print("Enter Password: ");
String Pass = in.next();
System.out.println();
// authenticate the info. of the user.
do {
if (authenticate(id, N, Pass)== null){
System.out.println("Invalid login information. Try again!");
System.out.print("Enter ID: ");
id = in.nextInt();
System.out.print("Enter Name: ");
N = in.next();
System.out.print("Enter Password: ");
Pass = in.next();
} else {
System.out.println(authenticate(id, N, Pass));
}
} while (authenticate(id, N, Pass)!= null);
System.out.printf("Welcome Manager %s.", N);
System.out.println();
// Displaying the menu to the user
System.out.print(
"Menu:
1.Add new Customer Account.
2.RemoveUser.
3.Add Item.
4.Remove Item.
5.Update Item.
6.List Items.
7.Search Item.
8.Logout.
");
System.out.print("Enter your Choice: ");
int cm = in.nextInt();
// checking the menu choice of the manager
while (cm >=1|| cm <=8){
if (cm >8|| cm <1){
System.out.print("Wrong choice!
Enter your choice again: ");
cm = in.nextInt();
} else {
// Switching between the cases of the menu
switch (cm){
case 1: // creating a new customer acc.
try {
System.out.print("Enter the new customer Id:");
int Id = in.nextInt();
System.out.print("Enter the new cusnamer Name:");
String Name = in.next();
System.out.println("Customer is added.");
System.out.print(createCustomerAcc(Id, Name));
} catch (NullPointerException | InputMismatchException e){
}
break;
case 2: // removing user
try {
System.out.println("Select the User you want to remove:");
System.out.println(
"
0-[0, owner , owner]
1-[1, Nour, Nour111]
2-[2, Ranad, Ranad222]"
+"
3-[3, Sara, Sara333]
4-[4, Safa, Safa444]"
+"
5-[5, Rana]
6-[6, Rahma]
7-[7, Mona]"+"
Your Selection: ");
int r = in.nextInt();
System.out.println(users.remove(r));
System.out.println("The list after removing the User:
"+ users);
System.out.println("The User is removed.");
} catch (NullPointerException | InputMismatchException e){
}
break;
case 3: // adding items to the list
try {
System.out.print("Enter the Item name: ");
String name = in.next();
System.out.print("Enter the Item price: ");
double price = in.nextDouble();
System.out.print("Enter the Item category: ");
String category = in.next();
System.out.print("Enter the Item Color: ");
String color = in.next();
System.out.println("The item is added.");
System.out.print(addItem(name, price, category, color));
} catch (NullPointerException | InputMismatchException e){
}
break;
case 4: // removing item from the list
try {
System.out.println("Select the item you want to remove:");
System.out.println(
"
0-[MiniClutch,80.5, Clutchs, Black]
1-[BagClutch,55.5, Clutchs, Black]
2-[Schoolbackpack,20.75, Backpacks, Red]"
+"
3-[Travelbackpack,77.25, Backpacks, Brown]
4-[MiniTote,120.7, Totebags, Silver]"
+"
5-[LargeTote,90, Totebag

Step by Step Solution

There are 3 Steps involved in it

Step: 1

import javaawt import javaawtevent import javaxswing import javaio import javautilArrayList import javautilArrays import javautilList public class MainGUI extends JFrame private ArrayList users privat... 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

Data Communications and Networking

Authors: Behrouz A. Forouzan

5th edition

73376221, 978-0073376226

More Books

Students also viewed these Programming questions

Question

=+e) Are there eight points in a row on the same side of the mean?

Answered: 1 week ago

Question

Recognize some of the factors that contribute to obesity.

Answered: 1 week ago

Question

Identify the physical and social factors that influence hunger.

Answered: 1 week ago