wm: java

Download patch

ref: 1434af4cd218fa6b2c7e09acf0720a3421f778c7
parent: b0e7cab307f99283490c5fd1d3e7d085492c4155
author: mkf <mkf@d510>
date: Sat May 27 18:46:31 EDT 2023

replace print with println where we are getting some menu input, add SearchAdmin()

--- a/Main.java
+++ b/Main.java
@@ -141,7 +141,7 @@
 		// String AskBook();
 
 		/* search foolan menu */
-		// void SearchAdmin();
+		void SearchAdmin();
 		void SearchUser();
 		void SearchBook();
 
@@ -1012,11 +1012,11 @@
 			"15) logout\n" +
 			"99) quit!\n");
 
-			System.out.print("menu> ");
+			System.out.print("Admin Menu> ");
 			while(!s.hasNextInt())
 			{
 				System.err.println("Please enter a valid input");
-				System.out.print("menu> ");
+				System.out.print("Admin Menu> ");
 				s.nextLine();
 			}
 			in = s.nextInt();
@@ -1039,7 +1039,6 @@
 				case 3:
 					this.AddBook();
 					break;
-/*
 				case 4:
 					this.SearchAdmin();
 					break;
@@ -1046,7 +1045,6 @@
 				case 5:
 					this.SearchUser();
 					break;
-*/
 				case 6:
 					this.SearchBook();
 					break;
@@ -1145,7 +1143,58 @@
 		return Integer.toString(pass.hashCode());
 	}
 
+	public void SearchAdmin()
+	{
+		String attr, patt;
+		Pattern pattern;
+		AdminAttr ua;
+		Scanner s = new Scanner(System.in);
 
+		System.out.println("Attr: Username, Reserved, ID, RegTime, Age, Active");
+		System.out.print("Find Admin> What?> ");
+		attr = s.nextLine();
+
+		if(attr.equalsIgnoreCase("Username"))
+			ua = AdminAttr.Username;
+		else if(attr.equalsIgnoreCase("Reserved"))
+			ua = AdminAttr.Reserved;
+		else if(attr.equalsIgnoreCase("ID"))
+			ua = AdminAttr.ID;
+		else if(attr.equalsIgnoreCase("RegTime"))
+			ua = AdminAttr.RegTime;
+		else if(attr.equalsIgnoreCase("Active"))
+			ua = AdminAttr.Active;
+		else
+		{
+			System.err.println("Invalid Attr");
+			return;
+		}
+
+		System.out.print("Find Admin> Pattern?> ");
+		patt = s.nextLine();
+		pattern = Pattern.compile(patt, Pattern.CASE_INSENSITIVE);
+
+
+		if(FindAdmin(ua, pattern))
+		{
+			for(Admin i : AdminList.values())
+			{
+				for(AdminAttr j : AdminAttr.values())
+					System.out.print(j + " | ");
+				System.out.println();
+
+				for(Admin j : AdminQuery)
+				{
+					for(AdminAttr a : i.toMap().keySet())
+						System.out.print(j.toMap().get(a) + " | ");
+					System.out.println();
+				}
+			}
+		}
+		else
+			System.err.println("No match has found");
+	}
+
 	public void SearchUser()
 	{
 		String attr, patt;
@@ -1154,7 +1203,7 @@
 		Scanner s = new Scanner(System.in);
 
 		System.out.println("Attr: Username, Reserved, ID, RegTime, Age, Active");
-		System.out.print("Find> What?> ");
+		System.out.print("Find User> What?> ");
 		attr = s.nextLine();
 
 		if(attr.equalsIgnoreCase("Username"))
@@ -1175,7 +1224,7 @@
 			return;
 		}
 
-		System.out.println("Find> Pattern?> ");
+		System.out.print("Find User> Pattern?> ");
 		patt = s.nextLine();
 		pattern = Pattern.compile(patt, Pattern.CASE_INSENSITIVE);
 
@@ -1208,7 +1257,7 @@
 		Scanner s = new Scanner(System.in);
 
 		System.out.println("Attr: Status, Name, Abstract, ISBN, AgeGroup etc.");
-		System.out.print("Find> What?> ");
+		System.out.print("Find Book> What?> ");
 		attr = s.nextLine();
 
 		if(attr.equalsIgnoreCase("Status"))
@@ -1229,7 +1278,7 @@
 			return;
 		}
 
-		System.out.println("Find> Pattern?> ");
+		System.out.print("Find Book> Pattern?> ");
 		patt = s.nextLine();
 		pattern = Pattern.compile(patt, Pattern.CASE_INSENSITIVE);
 
@@ -1261,6 +1310,7 @@
 
 		System.out.println("Setting up Admin:");
 
+		/* ensure there is no admin with the same username */
 		do
 		{
 			System.out.print("Add admin> ");
@@ -1381,7 +1431,7 @@
 		
 		do
 		{
-			System.out.println("Take> ISBN?> ");
+			System.out.print("Take> ISBN?> ");
 			isbn = s.nextLine();
 
 			if(isbn.equals(""))
@@ -1410,7 +1460,7 @@
 		
 		do
 		{
-			System.out.println("Take> ISBN?> ");
+			System.out.print("Take> ISBN?> ");
 			isbn = s.nextLine();
 
 			if(isbn.equals(""))