Results 1 to 8 of 8
Thread: I'm retarded and need help.
- 10-26-2013, 04:31 AM #1
Member
- Join Date
- Oct 2013
- Posts
- 4
- Rep Power
- 0
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; } } } }
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; } }
- 10-26-2013, 04:44 AM #2
Senior Member
- Join Date
- Jan 2013
- Location
- Northern Virginia, United States
- Posts
- 6,226
- Rep Power
- 13
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,
JimThe JavaTM Tutorials | SSCCE | Java Naming Conventions
Poor planning on your part does not constitute an emergency on my part
- 10-26-2013, 05:09 AM #3
Member
- Join Date
- Oct 2013
- Posts
- 4
- Rep Power
- 0
- 10-26-2013, 05:16 AM #4
Senior Member
- Join Date
- Jan 2013
- Location
- Northern Virginia, United States
- Posts
- 6,226
- Rep Power
- 13
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();
Regards,
JimThe JavaTM Tutorials | SSCCE | Java Naming Conventions
Poor planning on your part does not constitute an emergency on my part
- 10-26-2013, 05:26 AM #5
Member
- Join Date
- Oct 2013
- Posts
- 4
- Rep Power
- 0
Re: I'm retarded and need help.
I don't want to create a new member though...
- 10-26-2013, 05:48 AM #6
Senior Member
- Join Date
- Jan 2013
- Location
- Northern Virginia, United States
- Posts
- 6,226
- Rep Power
- 13
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,
JimThe JavaTM Tutorials | SSCCE | Java Naming Conventions
Poor planning on your part does not constitute an emergency on my part
- 10-26-2013, 05:53 AM #7
Member
- Join Date
- Oct 2013
- Posts
- 4
- Rep Power
- 0
Re: I'm retarded and need help.
moving gif image removed.
JosLast edited by JosAH; 10-26-2013 at 09:02 AM.
- 10-26-2013, 05:57 AM #8
Senior Member
- Join Date
- Jan 2013
- Location
- Northern Virginia, United States
- Posts
- 6,226
- Rep Power
- 13
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,
JimThe JavaTM Tutorials | SSCCE | Java Naming Conventions
Poor planning on your part does not constitute an emergency on my part
Bookmarks