Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.FileReader;
- import java.io.File;
- import java.io.FileWriter;
- import java.io.FileNotFoundException;
- import java.io.IOException;
- import java.io.PrintWriter;
- import java.io.*;
- //import java.security.*;
- import java.util.*;
- public class Program_logreg {
- public static Scanner userInput1 = new Scanner(System.in); //holds string
- public static Scanner userInput2 = new Scanner(System.in); //holds char
- public static void main(String[] arg) throws IOException{
- System.out.println("Please log in first\n");
- System.out.println("\n-----");
- System.out.println("LOGIN");
- System.out.println("-----");
- Employee temp = null;
- while(true){
- System.out.print("Username: ");
- String username = userInput1.nextLine();
- System.out.print("Password: ");
- String password = userInput1.nextLine();
- temp = ReadFile.getEmployeeInfo(username);
- if(temp == null){
- System.out.println("\nThis username does not exist!\n");
- continue;
- }
- if(!temp.getPassword().equals(password)){
- System.out.println("\nThis password is not correct!\n");
- continue;
- }
- //tempUser.setLoggedIn(true);
- if(temp != null) {
- System.out.println("\nWelcome!\n");
- break;
- }
- }
- if(temp.getRole().equals("Manager")){
- while (true){
- System.out.println("\nDo you want to register new waiter? Y or N? ");
- char choice = userInput2.next().charAt(0);
- if(choice == 'Y'){
- Manager.registerWaiter();
- }else if (choice != 'Y'& choice != 'N'){
- System.out.println("Not a valid option");
- }else{
- break;
- }
- }
- while (true){
- System.out.println("\nDo you want to de-register new waiter? Y or N? ");
- char choice = userInput2.next().charAt(0);
- if(choice == 'Y'){
- Employee remove = null;
- System.out.println("\nWhich waiter (Username) do you want to de-register?");
- String username = userInput1.nextLine();
- //remove = ReadFile.getEmployeeInfo(username);
- try{
- BufferedReader br= new BufferedReader(new FileReader("Employee.txt"));
- String sCurrentLine;
- String[] uCurrentLine = new String[5];
- File f = new File("tempFile.txt");
- PrintWriter wr = new PrintWriter(new BufferedWriter (new FileWriter(f, true)));
- int idCount = -1;
- while((sCurrentLine = br.readLine()) != null){
- uCurrentLine = sCurrentLine.split(";");
- //System.out.println(uCurrentLine[4]);
- if (uCurrentLine.length == 5){
- if(!uCurrentLine[1].toLowerCase().equals(username.toLowerCase())){
- remove = new Employee(Integer.parseInt(uCurrentLine[0]),
- uCurrentLine[1],
- uCurrentLine[2],
- uCurrentLine[3],
- uCurrentLine[4]
- );
- idCount++;
- String tempLine = idCount +";"+ remove.getUsername() +";"+ remove.getName() +";"+ remove.getPassword() + ";" + remove.getRole();
- wr.println(tempLine);
- }
- }
- }
- wr.close();
- br.close();
- boolean success = (new File("Employee.txt")).delete();
- if (success) {
- File fileNew = new File("Employee.txt");
- f.renameTo(fileNew);
- //System.out.println("The file has been xรณa");
- }
- }
- catch (IOException e) {
- e.printStackTrace();
- }
- }else if (choice != 'Y'& choice != 'N'){
- System.out.println("Not a valid option");
- }else{
- break;
- }
- }
- //System.out.println("\nDo you want to read the report? Y or N? ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement