JAVA Task 1: Implement the main method for the class UsernameGen. The main metho
ID: 3907933 • Letter: J
Question
JAVA
Task 1: Implement the main method for the class UsernameGen.
The main method will prompt the user running the program through the command line, at which point the user will get back through typing at the command line and end their input with the Enter (Return) key. This will be done for both inputs. Afterwards, the information prompted will be processed in order to be made to a username. You will need to use String manipulation methods to generate a username with the format [first-initial][last-name][age]. For example, a John Doe that is born at the year 2000, for example, would be assigned the username ‘jdoe17’. The first initial and last name part would be achieved through String manipulations, while the age will be an approximate calculation based on 2017 to their birth year. You can assume that the user will provide the input in the format [First Name] [Last-name] and an int for the year. After generating the username for the user, the program is then going to give the resulting String to the user through the system output by printing it.
Flow of Process Sample Program Runtime
What is your full name? John DoeYour username is jdoe17
What is your birth year? 2000
The user inputs are “John Doe” and “2000” (entered through the program command line), and the resulting output from calling the method in part 1 is “jdoe17”.
It is IMPERATIVE that you present the username through print out in the exact same format as the one in the example above (e.g. Your username is [username]). Input: fullName:“John Doe” year: 2000 Returned: Username: “jdoe17”
Explanation / Answer
Given below is the code for the question.
To indent code in eclipse , select code by pressing ctrl+a and then indent using ctrl+i
Please do rate the answer if it was helpful. Thank you
UsernameGen.java
----------
import java.util.Scanner;
public class UsernameGen {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
String firstname, lastname;
int year, age;
String username;
System.out.print("What is your full name? ");
firstname = keyboard.next();
lastname = keyboard.next();
System.out.print("What is your birth year? ");
year = keyboard.nextInt();
age = 2017 - year;
username = firstname.charAt(0) + lastname + age;
//convert it to lowercase
username = username.toLowerCase();
System.out.println("Your username is " + username);
}
}
output
---
What is your full name? John Doe
What is your birth year? 2000
Your username is jdoe17
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.