Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I ' m doing a project for a password generator in java. The program works as it should, but I ' m confused by some
Im doing a project for a password generator in java. The program works as it should, but Im 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 statements: the scanner object declaration, the method calls to programmer defined methods that i write, and one method call to the scanner object that does NOT read from the input buffer.
other notes: input nonvoid methods, one process nonvoid method, one output void method. total methods must be written, but only should be called in the main method the process method should call other process methods. use as few variables as possible eliminate variables used only once
import java.util.Scanner;
public class PasswordGenerator
public static void mainString args
Instantiate the scanner.
Scanner scanner new ScannerSystemin;
The program welcome message is displayed, the user is prompted
to select one of two menu options, and the userselected menu
option is stored as a variable.
System.out.printlnWelcome to the Password Generator Program.
;
System.out.printlnSelect from the following menu:";
System.out.print enter for a regularlymodified ;
System.out.printlnpassword or;
System.out.println enter for a supermodified password.";
int choice getInputChoicescanner;
The user is prompted for a password, and it's stored as a string.
System.out.println
Please enter a password.";
String ogPassword getOriginalPasswordscanner;
A string for the modified password is created based on the user's
menu choice and original password.
String modifiedPassword generatePasswordchoice ogPassword;
displayModifiedPasswordmodifiedPassword;
Close the scanner.
scanner.close;
Method to get the user's choice and moves the scanner to the next line.
public static int getInputChoiceScanner scanner
int choice scanner.nextInt;
scanner.nextLine;
return choice;
Method to get the original password from the user.
public static String getOriginalPasswordScanner scanner
return scanner.nextLine;
This method will output the new password based on the menu choice the
user originally selected.
public static String generatePasswordint choice, String ogPassword
String modifiedPassword ogPassword.substringtoLowerCase
ogPassword.substring ogPassword.length
ogPassword.substringogPasswordlengthtoUpperCase
ogPassword.length;
if choice
modifiedPassword int ogPassword.charAt
modifiedPassword.substring;
return modifiedPassword;
Method to display the modified password
public static void displayModifiedPasswordString modifiedPassword
System.out.printlnThe new password is modifiedPassword ;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started