Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: I'm a noob, noob questions.

  1. #1
    Junior Member
    Join Date
    Oct 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default I'm a noob, noob questions.

    import java.util.Scanner;
    import java.util.ArrayList;
    public class SMS
    {
        public static void main (String[] args)
        {
     
    		ArrayList<Member> someStuff = new ArrayList<Member>();
            Scanner scan = new Scanner(System.in);
    		int option = 0;
    		boolean check = true;
    while(check){
     
    	System.out.println("Welcome to the SMSer 4000!");
    	System.out.println("Please choose what you would like to do");
    	System.out.println("1. Log into my account");
    	System.out.println("2. Create a new account");
    	System.out.println("3. Exit");
    	option = scan.nextInt();
     
    switch(option) {
     
    	case 1: option = 1;
    	   String password;
        int mobile_number;
    	System.out.println("Account Login is opening");
    	System.out.println("--");
    	System.out.println("Account Login has opened");
    	System.out.println("--");
    	System.out.print("\n Please enter your phone number: ");
        mobile_number = scan.nextInt();
        System.out.print(" Please enter your password: ");
        password = scan.next();
     
     
    	break;
    	case 2: option = 2;
    	System.out.println("Account Creation is opening");
    	System.out.println("--");
    	System.out.println("Account Creation has opened");
    	System.out.println("--");
            char quit = 'Y';
                while (quit == 'Y')
                {
                    System.out.print("\n Number: ");
                    mobile_number = scan.nextInt();
                    System.out.print(" Password: ");
                    password = scan.next();
                    someStuff.add (new Member(mobile_number, password));
                    System.out.print(" Would you like to register another account? (Y/N)");
                    String word = scan.next();
                    word = word.toUpperCase();
                    quit= word.charAt(0);
                }
                for(Member stuff : someStuff)
                System.out.println(stuff);
    	break;
    	case 3: option = 3;
    	check = false;
    	System.out.println("SMSer 4000 is now closing.");
    	break;
    	}
    	}
     
     
    }
    }

    How can I create a login feature that checks through the array to see if it exists?


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    4,827
    My Mood
    Mellow
    Thanks
    177
    Thanked 628 Times in 615 Posts

    Default Re: I'm a noob, noob questions.

    I imagine you'd have a User class and the array (or some other collection) would contain the existing User instances. When a user, new or existing, tries to logon, the collection of User instances will be examined, looking for the userName. If the userName is found using something like:

    if ( user[i].getUserName().equals( logonName ) ) { . . . }

    then the logon will continue. Otherwise, options to check/reenter the logonName or to create a new user account will be given.

    Good luck!

  3. #3
    Junior Member
    Join Date
    Oct 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I'm a noob, noob questions.

    if ( user[i].getUserName().equals( logonName ) ) { . . . }

    Is the user[i] my array name?

  4. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    4,827
    My Mood
    Mellow
    Thanks
    177
    Thanked 628 Times in 615 Posts

    Default Re: I'm a noob, noob questions.

    Yes, "user[]" is a generic name for an array that holds User objects. You can name the class 'User' and the array of user objects anything you'd like. You might also consider using a collection other than an array, like an ArrayList, but the array will work.

  5. #5
    Junior Member
    Join Date
    Oct 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I'm a noob, noob questions.

    Should this be going in my SMS.java or my Member.java where the Member class is?

  6. #6
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    4,827
    My Mood
    Mellow
    Thanks
    177
    Thanked 628 Times in 615 Posts

    Default Re: I'm a noob, noob questions.

    If your Member class is similar to my User class concept, then not there. Between the two options, the SMS class would perform the login function, but maybe the login should be done by another class entirely. A separate class that provides the login function would be aware of the existing Member objects and the initial Login parameters. Using another class to do this function gives you the opportunity to reuse it later, and this is a common function.

  7. #7
    Junior Member
    Join Date
    Oct 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I'm a noob, noob questions.

    This is making my brain hurt. 10/10 regret doing a course to do with software development. Cheers for your help so far though.

Similar Threads

  1. Most noob question ever.
    By SkyAphid in forum Java Theory & Questions
    Replies: 1
    Last Post: December 8th, 2011, 07:14 AM
  2. Noob needs help!
    By kram in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 2nd, 2011, 05:03 AM
  3. Programming a Card Game (noob questions)
    By Taliesin in forum Java Theory & Questions
    Replies: 17
    Last Post: August 31st, 2011, 12:49 PM
  4. Programming noob here, need help!
    By artenuga54 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: September 18th, 2010, 04:04 PM
  5. helloworld noob
    By LostFury2012 in forum What's Wrong With My Code?
    Replies: 12
    Last Post: July 14th, 2010, 06:29 AM