/**********************************************************
* Program Name : Program Template - Name Reader
* Author : Terry Weiss
* Date : January 22, 2016
* Course/Section : CSC264 - 001
* Program Description: This program will accept a first and last name and then
* center the name in the middle of the screen.
*
* Methods:
* -------
* Main - Reads the names and displays them
**********************************************************/
public class NameReader
{
/**********************************************************
* Method Name : NameReader - Main
* Author : Terry Weiss
* Date : January 22, 2016
* Course/Section : CSC264 - 001
* Program Description: This method will read a name entered by the user. It
* then creates a new String with the name centered for console output,
* and displays it
*
* BEGIN main
* Prompt for first name
* Prompt for last name
* Clear screen
* Calculate leading space to center title for 80 columns
* Display centered title
* Create String with name padded to be centered
* Output name
* END Read Name
**********************************************************/
public static void main (String [] args)
{
//local constants
final int COLUMNS = 80; //Number of columns for console output
//local variables
String firstName, lastName; //User's first and last name
int padding; //Number of leading spaces to center name
Library64 myLib = new Library64();
/******************** Start main method *****************/
//Prompt for first name
System.out.print("Enter first name: ");
firstName = Keyboard.readString();
//Prompt for last name
System.out.print("Enter last name: ");
lastName = Keyboard.readString();
//Clear screen
myLib.clrscr();
//Calculate leading space to center title for 80 columns
//Length of full name is first name's length + 1 space + last name's length
padding = (COLUMNS - firstName.length() - 1 - lastName.length() ) / 2;
//Display centered title
System.out.println(" Name Reader\n\n");
//Display full name
System.out.println(Util.setLeft(padding, firstName + " " + lastName));
} //end main method
} //end Template264
Comments