THINK FIRST·CODE LATER

← All labs

Email address parts

Problem

Write EmailParts: read an email address (one line), trim it and convert it to lower case, then print the user name, the domain, the extension (after the last dot), a masked version and whether it ends with wku.edu.cn:

Email:     lina.chen@wku.edu.cn
User:      lina.chen
Domain:    wku.edu.cn
Extension: cn
Masked:    l***@wku.edu.cn
Student address: true

Use indexOf, lastIndexOf, substring, charAt and endsWith.

Data for this lab

Your program reads its data from standard input. Download the file, then give it to your program as shown below. Start with data set 1: its expected output is given.

l5-2-data-1.txt

Lina.Chen@WKU.edu.cn
What your program must print for l5-2-data-1.txt
Email:     lina.chen@wku.edu.cn
User:      lina.chen
Domain:    wku.edu.cn
Extension: cn
Masked:    l***@wku.edu.cn
Student address: true

Run your program first, then open this and compare line by line: your output must contain these lines exactly.

How to give the file to my program

Terminal (macOS, Linux, or Windows Command Prompt), after compiling:

java Main < l5-2-data-1.txt

Windows PowerShell does not understand <:

Get-Content l5-2-data-1.txt | java Main

IntelliJ IDEA: Run → Edit Configurations → Redirect input from. Or simply paste the content of the file into the console when the program waits for input.

Write it here or in your IDE, then paste it. Compile and test it yourself before comparing. Your code stays in your browser — it is never sent to or stored on the server.