1
eDepotシステムのログイン機能(Eclipseを使用しています)には含まれていますが、ログアウト機能の実行方法がわかりません。私はそれを研究した後にいくつか試しましたが、うまくいかないようです。ログアウト機能を追加するにはどうすればよいですか?
これは私のコードです:
package uk.ac.livjm.cms; //Name of package
import java.util.Scanner; //Imports scanner
import java.io.IOException; //Imports IOException
public class Depot { //Name of Program
static Scanner console = new Scanner(System.in);
@SuppressWarnings("unused")
public static void main(String[] args) throws IOException {
String User = "SFoster"; //Username of Manager 1
String Pass = "001"; //Password of Manager 1
String Username = "BSamuel"; //Username of Manager 2
String Password = "002"; //Password of Manager 2
String User1 = "1"; //Username of Driver 1
String Pass1 = "111"; //Password of Driver 1
String Username1 = "2"; //Username of Driver 2
String Password1 = "222"; //Password of Driver 2
String User2 = "3"; //Username of Driver 3
String Pass2 = "333"; //Password of Driver 3
String inputuser; // Input when user is typing their username in
String inputpass; // Input when user is typing their password in
int menu = 0; //Displays menu
int count = 0;
int input;
System.out.println(
"Are you a Manager or a Driver or are you Creating a new account?"
+ "\n"
+ "1. Manager"
+ "\n"
+ "2. Driver"
+ "\n"
+ "3. Creating a new account"); //Displays message
input = console.nextInt();
if (input == 3) {
DepotSystem.Account();
}
if (input == 1) { //Login for Manager
System.out.println("Managers Login"); //Displays message
System.out.println(
"Please Note: You will only be allowed to re-enter your Username and Password three times."); //Displays message
while (count < 3) // 3 menu options
{
System.out.println("Enter your Username:"); //Displays message
inputuser = console.next();
System.out.println("Enter your Password:"); //Displays message
inputpass = console.next();
if (inputuser.equals(User) && inputpass.equals(Pass)
|| (inputuser.equals(Username) && inputpass.equals(Password))) {
System.out.println(
"You have successfully logged in."
+ "\n"
+ "Welcome to the Managers Section!"
+ "\n"
+ "Enter the Number that corresponds to the option you wish to choose:");
System.out.println(
"1. Transfer available depot to another vehicle."
+ "\n"
+ "2. Set up new work schedule."
+ "\n"
+ "3. Search for available driver and vehicle."
+ "\n"
+ "4. Log out.");
menu = console.nextInt();
if (menu == 1) {
System.out.println("Transfer available depot to another vehicle.");
Transfer.transfer();
count = 0;
break;
} else if (menu == 2) {
System.out.println("Set up new work schedule.");
WorkSchedule WorkSchedule = new WorkSchedule();
uk.ac.livjm.cms.WorkSchedule.work();
count = 0;
break;
} else if (menu == 3) {
System.out.println("Search for available driver and vehicle.");
Vehicle Vehicle = new Vehicle();
uk.ac.livjm.cms.Vehicle.vehi();
count = 0;
break;
}
if (menu == 4) {
System.out.println("Log out.");
count = 0;
break;
} else {
System.out.println(menu + ": Invalid option.");
count++;
}
} else {
System.out.println("Incorrect Username or Password");
count++;
}
}
}
if (input == 2) {
System.out.println("Drivers Login");
System.out.println(
"Please Note: You will only be allowed to re-enter your Username and Password three times.");
while (count < 3) {
System.out.println("Enter your Username: ");
inputuser = console.next();
System.out.println("Enter your Password: ");
inputpass = console.next();
if (inputuser.equals(User1) && inputpass.equals(Pass1)
|| (inputuser.equals(Username1) && inputpass.equals(Password1))
|| (inputuser.equals(User2) && inputpass.equals(Pass2))) {
System.out.println(
"You have successfully logged in."
+ "\n"
+ "Welcome to the Drivers Section!"
+ "\n"
+ "Enter the Number that corresponds to the option you wish to choose: ");
System.out.println("1. View Work Schedule." + "\n" + "2. Log Out.");
menu = console.nextInt();
if (menu == 1) {
System.out.println("View Work Schedule.");
WorkScheduleDriver.workdriver();
count = 0;
break;
} else if (menu == 2) {
System.out.println("Log out.");
count = 0;
break;
} else {
System.out.println("Incorrect Username or Password");
count++;
}
}
}
}
}
}