Results 1 to 4 of 4
  1. #1
    Denis2k11 is offline Member
    Join Date
    Oct 2012
    Posts
    35
    Rep Power
    0

    Exclamation Logic error when there shouldn't be one? Method not executing properly.

    Grettings! I appear to be having a massive problem with just a tiny bit of code. The code takes in a login name(which is assigned to a class user) and a password. The system then checks does this return a "student" string or some other type of string via a checkLogin method in fakeSystem class. However, it keeps saying it cannot find the user but the user is in the files ( checkLogins checks a list of people registered in a Logins.txt.
    Can someone pin point the error in my logic?
    The first bit of code( takes login name and password and passes to checkLogin method
    Java Code:
    String password="",command="";
    			System.out.print("Please enter your login name: ");
    			newUser.setName(input.nextLine());
    			System.out.print("Please enter your login password: ");
    			password = input.nextLine();
    			
    			if(fakeSystem.checkLogin(newUser.getName(),password).equals("Student")){
    				fakeSystem.getAllStudents();






    This is the checkLogin method.
    Java Code:
    public String checkLogin(String name,String password)throws IOException{
    		String aLine="";
    		FileReader getLogins = new FileReader("Logins.txt");
    		Scanner input = new Scanner(getLogins);
    		while(input.hasNext())
    			 aLine=input.nextLine();
    			String[] lineComponents = aLine.split(",");
    			if(lineComponents[0].equals(name) && lineComponents[lineComponents.length-2].equals(password)){
    				return lineComponents[lineComponents.length-1];
    			}
    This is the text being read from...
    studentName,fakeemail@email.com,House fake-fake street-fake city,555555555,RS057,password,Student

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    United States
    Posts
    2,945
    Rep Power
    4

    Default Re: Logic error when there shouldn't be one? Method not executing properly.

    Did you sprinkle print statements throughout your program to verify that the variables passed, read, and checked were what you expected? In situations like this, that is the first thing you should consider.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  3. #3
    Denis2k11 is offline Member
    Join Date
    Oct 2012
    Posts
    35
    Rep Power
    0

    Default Re: Logic error when there shouldn't be one? Method not executing properly.

    Never mind. I got it. The while loop wasn't contained within curly brackets. Never mind, later basic bitches!

  4. #4
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,094
    Rep Power
    4

    Default Re: Logic error when there shouldn't be one? Method not executing properly.

    Quote Originally Posted by Denis2k11 View Post
    later basic bitches!
    What the hell?
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. Logic Error
    By Norris80 in forum New To Java
    Replies: 1
    Last Post: 02-18-2012, 06:32 AM
  2. logic error?
    By droidus in forum New To Java
    Replies: 2
    Last Post: 01-21-2012, 03:17 PM
  3. Custom method logic help
    By mwr1976 in forum New To Java
    Replies: 28
    Last Post: 11-11-2011, 04:00 AM
  4. help with a logic error
    By ShinTec in forum Advanced Java
    Replies: 11
    Last Post: 05-02-2010, 10:19 PM
  5. How to stop executing method
    By moamen in forum New To Java
    Replies: 3
    Last Post: 12-31-2009, 10:33 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •