Total de visualizações de página

sábado, 11 de dezembro de 2010

In this assignment you will write an application that generates computer usernames and email addresses for our college

Objective

In this assignment you will write an application that generates computer usernames and email addresses for our college MassBay.edu .  

Project Specifications

1.      Provide a test program called Assignment3.
2.      Use comments to show your name, the date and the assignment number.
3.      Request a user’s first name and last name and create a username using the following rules:
a.      The username should be all lower case.
b.      Use the first letter of the first name followed by an underscore (_) and
c.      The first 5 letters of the last name (the user’s last name must be at least 5 letters).
d.      Followed by a randomly generated 3-digit number.
4.      Create an email address by combining the username and the school’s domain name. 
5.      Display a nice message for the user with their original name, the new username and the new email address.

Due Date: 

Submit your *.java file through Blackboard no later than October 14 by 11:59 pm.

IMPORTANT SUBMISSION INSTRUCTIONS: 

1.      In blackboard click on AssignmentsAssignment3 – at the bottom of the document click on View/Complete Assignment: A3 to upload your file.
2.      Use the BROWSE button to find the file.   Select it and click on the Submit button.
Start early and if you have trouble with this assignment PLEASE come to see me!
Item A3

>> View/Complete Assignment: A3
Item Solution
import java.util.Scanner;
import java.util.Random;
import java.text.DecimalFormat;
public class Username2
{
  //-----------------------------------------------------------------
  //  Produces a username based on the user's first and last names.
  //  Assumes the last name is at least five characters long
  //-----------------------------------------------------------------
  public static void main (String[] args)
  {
    String first, last, username, email;
    Scanner scan = new Scanner(System.in);
    Random rand = new Random();
   
    System.out.print ("Enter your first name: ");
    first = scan.nextLine();
    System.out.print ("Enter your last name: ");
    last = scan.nextLine();
   
    //username = first.charAt(0) + last.substring(0, 5) +
   //  (rand.nextInt(900) + 100);  
    //   OR
    DecimalFormat fmt = new DecimalFormat("000");
    username = first.charAt(0) + last.substring(0, 5) + fmt.format( (rand.nextInt(1000) ));
    username = username.toLowerCase();
    email = username + "@massbay.edu";
   
    System.out.println("Dear " + first + " " + last + "\nyour Username is: " +
                         username + "\nyour email address is: " + email);
 
  }
}

OK

Nenhum comentário:

Postar um comentário