English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Write a program called emailaddress that read from the standard input, keyboard input, a users first name and last name. The program should then generate an email address based on the following scheme: take the last name and make the first letter capital letter and the rest of the last name all lower case letter. Take this new last name and appended to it the first letter of the first name in lower case letter. Finally append @hotmail.com to the end of the string. Display the newly generated email address. You can assume no blanks in the first or last name.

Sample input:
Please enter first name:
Shereef
Please enter last name
abualmaati

Sample output:
Your user name is: Abualmaatis@hotmail.com

2007-03-16 06:56:02 · 5 answers · asked by LULU 1 in Computers & Internet Programming & Design

5 answers

You'd probably want to rewrite this into your own idiom, they will be able to tell its not your if you keep switching coding conventions:

import java.io.*;

class Test
{

static String fname = "fred";
static String lname = "flinstone";
static final String emailStr = "@hotmail.com";

public static void main(String args[])
{
try {
InputStreamReader isr = new InputStreamReader( System.in );
BufferedReader stdin = new BufferedReader( isr );
System.out.print( "First Name: " );
String fname = stdin.readLine();

System.out.print( "Last Name: " );
String lname = stdin.readLine();

System.out.println(lname.substring(0, 1).toUpperCase() + lname.substring(1, lname.length()).toLowerCase() + fname.substring(0, 1).toLowerCase() + emailStr );
} catch(Exception e) {
e.printStackTrace();
}
}
}

2007-03-16 07:13:43 · answer #1 · answered by Anonymous · 0 0

How difficult is it in java to use the Scanner class to obtain input and the String class to take the last name and APPEND the 1st (0) character and APPEND "@hotmail.com"?

2007-03-16 14:13:49 · answer #2 · answered by Knowledge 3 · 0 0

This is how you read input from the keyboard. The rest is basic string manipulation. Look at the String class.

This waits for input from the user:

public static String readLine() {

// Open a system.in reader
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String line = null;

// Read a line from the command-line
try {
line = br.readLine();
line = line.trim();
} catch (IOException ioe) {
System.out.println("Error reading input");
System.exit(1);
}

return line;
}

2007-03-16 14:06:14 · answer #3 · answered by SPB 6 · 1 0

Modify this to suit your needs:

String fname = "Shereef";
String lname = "abualmaati";

String email = lname + fname.charAt(0);
email = email.toUpperCase().charAt( 0 ) + email.toLowerCase().substring( 1 ) + "@hotmail.com";

2007-03-19 05:55:15 · answer #4 · answered by Liviawarty J 2 · 0 0

Sounds like someone's HW assignment.

2007-03-16 14:02:22 · answer #5 · answered by The First 3 · 0 0

fedest.com, questions and answers