Advertisement
binibiningtinamoran

Module2

Oct 23rd, 2019
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.97 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Module2 {
  4.     private String firstName, middleName, lastName;
  5.  
  6.     public Module2() {
  7.         this.firstName = "";
  8.         this.middleName = "";
  9.         this.lastName = "";
  10.     }
  11.  
  12.     public String monogram(String s, String t) {
  13.         return s.charAt(0) + "" + t.charAt(0);
  14.     }
  15.     public String monogram(String s, String t, String u) {
  16.         return this.monogram(s, t) + "" + u.charAt(0);
  17.     }
  18.     public String completeName(String s, String t) {
  19.         return s + " " + t;
  20.     }
  21.     public String completeName(String s, String t, String u) {
  22.         return this.completeName(s,t) + " " + u;
  23.     }
  24.     public String getName(String prompt) {
  25.         Scanner scan = new Scanner(System.in);
  26.         System.out.print("Enter your name: ");
  27.         return scan.nextLine();
  28.     }
  29.  
  30.     public static void main(String[] args) {
  31.         Scanner read = new Scanner(System.in);
  32.         Module2 m = new Module2();
  33.         System.out.println("____Starting application____");
  34.  
  35.         m.firstName = m.getName("Please enter your first name: ");
  36.         m.middleName = m.getName("Please enter your middle name: ");
  37.         m.lastName = m.getName("Please enter your last name: ");
  38.  
  39.         System.out.print("Enter either 2 or 3: ");
  40.         int choice = read.nextInt();
  41.         if (choice == 2) {
  42.             System.out.printf("2-name monogram for %s\n",m.monogram(m.firstName, m.lastName));
  43.             System.out.printf("Complete name: %s\n", m.completeName(m.firstName, m.lastName));
  44.         } else if (choice == 3) {
  45.             System.out.printf("3-name monogram for %s\n",m.monogram(m.firstName, m.middleName,
  46.                     m.lastName));
  47.             System.out.printf("Complete name: %s\n", m.completeName(m.firstName, m.middleName,
  48.                     m.lastName));
  49.         } else {
  50.             System.out.println("Invalid choice made.");
  51.         }
  52.         System.out.println("______ Ending application ______");
  53.  
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement