Question: I ' m doing a project for a password generator in java. The program works as it should, but I ' m confused by some

I'm doing a project for a password generator in java. The program works as it should, but I'm confused by some specifications and I don't know if the formatting is right. Basically I think I have too much in the main method. I'll list the specifications and then insert my code.
-the main method should only contain the following 6 statements: the scanner object declaration, the method calls to 4 programmer defined methods that i write, and one method call to the scanner object that does NOT read from the input buffer.
-other notes: 2 input non-void methods, one process non-void method, one output void method. 7 total methods must be written, but only 4 should be called in the main method- the process method should call 3 other process methods. use as few variables as possible (eliminate variables used only once).
import java.util.Scanner;
public class PasswordGenerator {
public static void main(String[] args){
// Instantiate the scanner.
Scanner scanner = new Scanner(System.in);
/* The program welcome message is displayed, the user is prompted
* to select one of two menu options, and the user-selected menu
* option is stored as a variable.
*/
System.out.println("Welcome to the Password Generator Program.
");
System.out.println("Select from the following menu:");
System.out.print("1) enter \"1\" for a regularly-modified ");
System.out.println("password or");
System.out.println("2) enter \"2\" for a super-modified password.");
int choice = getInputChoice(scanner);
// The user is prompted for a password, and it's stored as a string.
System.out.println("
Please enter a password.");
String ogPassword = getOriginalPassword(scanner);
// A string for the modified password is created based on the user's
// menu choice and original password.
String modifiedPassword = generatePassword(choice, ogPassword);
displayModifiedPassword(modifiedPassword);
// Close the scanner.
scanner.close();
}
// Method to get the user's choice and moves the scanner to the next line.
public static int getInputChoice(Scanner scanner){
int choice = scanner.nextInt();
scanner.nextLine();
return choice;
}
// Method to get the original password from the user.
public static String getOriginalPassword(Scanner scanner){
return scanner.nextLine();
}
// This method will output the new password based on the menu choice the
// user originally selected.
public static String generatePassword(int choice, String ogPassword){
String modifiedPassword = ogPassword.substring(0,1).toLowerCase()
+ ogPassword.substring(1, ogPassword.length()-1)+
ogPassword.substring(ogPassword.length()-1).toUpperCase()+
ogPassword.length();
if (choice ==2){
modifiedPassword =(int) ogPassword.charAt(0)+
modifiedPassword.substring(1);
}
return modifiedPassword;
}
// Method to display the modified password
public static void displayModifiedPassword(String modifiedPassword){
System.out.println("The new password is \""+ modifiedPassword +"\".");
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!