Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1066903
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T20:04:53+00:00 2026-05-16T20:04:53+00:00

I am creating a java application and I need to get the user PINs

  • 0

I am creating a java application and I need to get the user PINs from the text file. I used the following code below, but is it not working properly. Could anyone please help me out soon…..

    String typedPIN="";   
    Menus obj1=new Menus();
    BufferedReader getIt=new BufferedReader(new InputStreamReader(System.in));
    String userPIN="";
    try{
        BufferedReader br = new BufferedReader(new FileReader(new File("D:\\Studies\\BCAS\\HND\\Semester 1\\Programming Concepts\\Assignment\\AccountPIN.tab")));
        String strLine=null                    ;
        System.out.println("Enter PIN");
        userPIN=getIt.readLine();  
        while ((strLine = br.readLine()) != null)   {          
            if(userPIN.equals(strLine)){
                System.out.println("You have login!");
                obj1.MainMenu();
            }
        }    
    }catch (Exception e){//Catch exception if any
            System.err.println("Error: " + e.getMessage());
    }
 }   
  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T20:04:54+00:00Added an answer on May 16, 2026 at 8:04 pm

    Assuming this is your input data

    PIN AccountNo Balance
    1598 01-10-102203-0 95000
    4895 01-10-102248-0 45000
    9512 01-10-102215-0 125000
    6125 01-10-102248 85000
    

    You will need to split each line into its consituent parts, you could use the Scanner class to do this, as it will let you extract the pin / account number as Strings and the balance as a Double/Integer.

    At the moment you are comparing the user input against the whole line, so you would need to enter a pin 1598 01-10-102203-0 95000 rather than 1598 in order to login.

    I suggest you split this into to two methods, one which when given a file returns a Collection of Account objects, and another which handles the login.

    You could re-write your while loop to enable you to give a useful error message if you don’t get a valid pin, e.g.

    final File data = new File("D:\\Studies\\BCAS\\HND\\Semester 1\\Programming Concepts\\Assignment\\AccountPIN.tab");
    Account userAcc = null;
    for (Account acc : getAccounts(data)) {          
        if(userPIN.equals(acc.getPin())){
            userAcc = acc;
        }
    }
    if (userAcc == null) {
        obj1.MainMenu();
    } else {
        // display error
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating a web application in Java in which I need to run
I'm creating a Java application where the user can search through a list of
Im creating an application that gets a list of .java and .class files from
I am creating a Java application in which I need to read the first
In my Java application I need to select a path using JFileChooser. The code
I am creating a Java application that will take in .tar files and retrieve
I am creating a java application with RestFB. At this url, Facebook explains how
i am creating a java application which is will be GUI for a bash
I am in the process of creating a java application that will be running
I've creating a Java Swing application and I realized that I have many many

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.