Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.io.*;
- import javax.swing.*;
- import java.lang.*;
- public class CreateUserMethod{
- public static void main(String[] args) throws Exception {
- User LoggedInUser=new User();
- String[] details= LoginMethod();
- double tempBal = Double.parseDouble(details[2]);
- LoggedInUser.setEmail(details[0]);
- LoggedInUser.setpassword(details[1]);
- LoggedInUser.setbalance(tempBal);
- System.out.println(LoggedInUser.getbalance());
- }
- public static String[] LoginMethod() throws IOException //login method
- {
- String username, password, filepath;
- filepath="Users.txt"; //sets filepath
- Scanner x;
- username=JOptionPane.showInputDialog(null,"Please Enter Your Username");
- password=JOptionPane.showInputDialog(null,"Please Enter Your Password");
- String tempUsername=""; //empty strings
- String tempPassword="";
- String tempBalance="";
- boolean found=false;
- boolean LoggedIn=false;
- while (LoggedIn==false)
- {
- x= new Scanner(new File(filepath)); // new scanner object
- x.useDelimiter("[,\n]"); // breaks strings at ,
- while (x.hasNext() && !found) // makes it loop through whole file
- {
- tempUsername=x.next();
- tempPassword=x.next();
- tempBalance=x.next();
- if (tempUsername.trim().equals(username.trim()) && tempPassword.trim().equals(password.trim()))
- {
- found=true; // to be used in order to trigger menu possibly
- }
- }
- x.close(); // closes program
- if (found==true){
- JOptionPane.showMessageDialog (null, "You Have Successfully Logged In as A User");
- String num[] = {username,password,tempBalance};
- return (num);
- }
- else
- {
- int RetryLogin = JOptionPane.showConfirmDialog(
- null,
- "Would You Like to try login again?",
- "Yes No Dialog",
- JOptionPane.YES_NO_OPTION);
- if (RetryLogin == JOptionPane.NO_OPTION)
- { JOptionPane.showMessageDialog(null, "Thank You For Using My Program");
- }
- else
- { JOptionPane.showMessageDialog(null, "You choose to try again");
- LoginMethod();
- }
- }
- }
- return null;
- }
- public static void UserMenu() throws IOException
- {
- Object[] menuItems = {"View Bookings","View Account Statement","Quit"};
- Object selection = JOptionPane.showInputDialog(null,"Options","Menu",1,null,menuItems,menuItems[0]);
- if(selection != null)
- {
- if (selection.equals("View Bookings"))
- {
- JOptionPane.showMessageDialog(null, "You choose to try again");
- UserMenu();
- }
- else if (selection.equals("View Account Statement"))
- {
- String Message;
- String Bal= LoggedInUser.getbalance();
- Message= ("Your Balance is "+Bal+" Euros, Have a Nice day");
- UserMenu();
- }
- else if (selection.equals("Quit"))
- {System.exit(1);}
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement