Advertisement
SECT19N

Intro2 Class

Oct 18th, 2023 (edited)
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.13 KB | Source Code | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Intro2 {
  4.     static String FirstName;
  5.     static String LastName;
  6.  
  7.     /**
  8.      * Sets the full name of the user.
  9.      * @param fName - Users first name.
  10.      * @param lName - Users last name.
  11.      */
  12.     static void setName(String fName, String lName) {
  13.         FirstName = fName;
  14.         LastName = lName;
  15.     }
  16.  
  17.     /**
  18.      * Gets the full name of the user.
  19.      * @return - returns the full name entered by the user.
  20.      */
  21.     static String getName() {
  22.         return String.format("%s %s%n", FirstName, LastName);
  23.     }
  24.  
  25.     /**
  26.      * Takes input from the user and stores them as first and last names.
  27.      */
  28.     static void InputName() {
  29.         Scanner sc = new Scanner(System.in);
  30.  
  31.         System.out.print("Enter first name: ");
  32.         String _fname = sc.next();
  33.         System.out.print("Enter last name: ");
  34.         String _lname = sc.next();
  35.  
  36.         setName(_fname, _lname);
  37.  
  38.         System.out.printf(getName());
  39.  
  40.         sc.close();
  41.     }
  42.  
  43.     public static void main(String[] args) {
  44.         InputName();
  45.         System.out.println(FirstName);
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement