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 3 of 3

Thread: I need help with METHODS!!!

  1. #1
    Junior Member
    Join Date
    Dec 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question I need help with METHODS!!!

    No matter how many times I've been explained the theory behind methods, I can't determine how to write them to apply to programs. Here is a simple program that work, but I need to apply 4 different methods to it.


    setUsername() – A mutator method that sets the username for the associated account. (Use any
    8 letters to represent the initial username.)

    getPassword() - An accessor method that asks for the password associated with the account.

    isUsernameValid() -This method checks whether the username entered meets the required rules
    for usernames.


    isPasswordValid() - This method checks whether the string entered is valid.




    //Using the JOptionPane class to promt the user for input
    import javax.swing.JOptionPane;
    class JavaAssignment5

    {

    public static void main(String[]args){

    //Promting the user to enter a user name and assigning it to 'x'
    String x = JOptionPane.showInputDialog(null,"Enter User Name: ", "Login", JOptionPane.QUESTION_MESSAGE);

    //Assigning 'y' as the password entered
    String y = JOptionPane.showInputDialog(null,"Password: ", "Login", JOptionPane.QUESTION_MESSAGE);

    //Setting the correct user name
    String user = new String("muzukashi");

    //Setting the correct password
    String pass = new String("Ja57pan");

    //Boolean expression to check if what the person entered is correct for both username and password
    if(user.equals(x) && pass.equals(y)){

    //Displays a message to inform them that they entered both correctly
    JOptionPane.showMessageDialog(null,"Valid user Name","Good job!", JOptionPane.WARNING_MESSAGE);
    }
    else{
    //Informs the user that they entered something wrong, but not actually telling them
    JOptionPane.showMessageDialog(null,"Invalid user Name","Dumbass", JOptionPane.WARNING_MESSAGE);
    }


    }

    }


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

  3. #3
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: I need help with METHODS!!!

    Crossposted: Really need method help - Java Forums

Similar Threads

  1. 1st time using methods
    By gonfreecks in forum What's Wrong With My Code?
    Replies: 5
    Last Post: December 1st, 2010, 02:37 PM
  2. methods help
    By hockey87 in forum AWT / Java Swing
    Replies: 1
    Last Post: March 9th, 2010, 11:57 PM
  3. Help with GUIs please & methods
    By killerknight141 in forum Java Theory & Questions
    Replies: 1
    Last Post: February 2nd, 2010, 07:12 AM
  4. Re-using methods?
    By Morevan in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 26th, 2010, 05:04 PM
  5. Using variables from different methods?
    By Morevan in forum Object Oriented Programming
    Replies: 3
    Last Post: January 5th, 2010, 07:10 PM