Results 1 to 8 of 8
  1. #1
    Malcom666 is offline Member
    Join Date
    Oct 2013
    Posts
    4
    Rep Power
    0

    Default I'm retarded and need help.

    Hello all,

    I've been trying to do this all day but because I'm retarded and 10/10 regret doing a uni course involving software development I cannot work this out for the life of me. Basically, just trying to create a login function/thing that checks an array for their details and then returns true of false. One of my many attempts is on line 34 of SMS.java. If someone could help me out I would very much appreciate it, hell, I will even buy you a $10 game on Steam.

    Here is my SMS.java

    Java Code:
    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();
    	if ( Member.getMobile().equals( mobile_number ) ) { 
    	System.out.println("yes");
    	}
    
    	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;
    	}
    	}
    }
    }
    and here is my Member.java for the Member class:

    Java Code:
    public class Member
    {
        public String password;
    	public int mobile_number;
        public Member (int mobile, String pass)
        {
            mobile_number = mobile;
            password = pass;
        }
        public String toString ()
        {
            return "\n\n Name: " + password + ", " + mobile_number + "\n";
        }
        public int getMobile ()
        {
            return mobile_number;
        }
        public String getPass ()
        {
            return password;
        }
    	
    
    }

  2. #2
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,617
    Rep Power
    5

    Default Re: I'm retarded and need help.

    mobile_number is a primitive value (in this case an int) and thus should be compared using ==. Only use equals for object comparisons (e.g. String values).

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

  3. #3
    Malcom666 is offline Member
    Join Date
    Oct 2013
    Posts
    4
    Rep Power
    0

    Default Re: I'm retarded and need help.

    Quote Originally Posted by jim829 View Post
    mobile_number is a primitive value (in this case an int) and thus should be compared using ==. Only use equals for object comparisons (e.g. String values).

    Regards,
    Jim
    SMS.java:34: error: non-static method getMobile() cannot be referenced from a st
    atic context
    if ( Member.getMobile()==( mobile_number ) ) {
    ^
    1 error

  4. #4
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,617
    Rep Power
    5

    Default Re: I'm retarded and need help.

    That means you are trying to call a non-static method in a static context. In otherwords,

    Java Code:
    //You are doing this:
    
    Member.getMobile()
    
    //instead of this:
    
    Member member = new Member(<parameter list>);
    member.getMobile();
    So you need to use an instance of your class which you defined sometime before you try to compare it to something else.

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

  5. #5
    Malcom666 is offline Member
    Join Date
    Oct 2013
    Posts
    4
    Rep Power
    0

    Default Re: I'm retarded and need help.

    I don't want to create a new member though...

  6. #6
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,617
    Rep Power
    5

    Default Re: I'm retarded and need help.

    Well, then you need to access the already created instance. You had to create at least one instance since you are apparently comparing some state information of an instance of Member.

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

  7. #7
    Malcom666 is offline Member
    Join Date
    Oct 2013
    Posts
    4
    Rep Power
    0

    Default Re: I'm retarded and need help.

    moving gif image removed.

    Jos
    Last edited by JosAH; 10-26-2013 at 08:02 AM.

  8. #8
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,617
    Rep Power
    5

    Default Re: I'm retarded and need help.

    Please don't post stuff like that on this forum. I suggest you edit your post and remove it asap. Otherwise, you may incur the wrath of the moderators.

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

Posting Permissions

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