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);
}
}
}