Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Module2 {
- private String firstName, middleName, lastName;
- public Module2() {
- this.firstName = "";
- this.middleName = "";
- this.lastName = "";
- }
- public String monogram(String s, String t) {
- return s.charAt(0) + "" + t.charAt(0);
- }
- public String monogram(String s, String t, String u) {
- return this.monogram(s, t) + "" + u.charAt(0);
- }
- public String completeName(String s, String t) {
- return s + " " + t;
- }
- public String completeName(String s, String t, String u) {
- return this.completeName(s,t) + " " + u;
- }
- public String getName(String prompt) {
- Scanner scan = new Scanner(System.in);
- System.out.print("Enter your name: ");
- return scan.nextLine();
- }
- public static void main(String[] args) {
- Scanner read = new Scanner(System.in);
- Module2 m = new Module2();
- System.out.println("____Starting application____");
- m.firstName = m.getName("Please enter your first name: ");
- m.middleName = m.getName("Please enter your middle name: ");
- m.lastName = m.getName("Please enter your last name: ");
- System.out.print("Enter either 2 or 3: ");
- int choice = read.nextInt();
- if (choice == 2) {
- System.out.printf("2-name monogram for %s\n",m.monogram(m.firstName, m.lastName));
- System.out.printf("Complete name: %s\n", m.completeName(m.firstName, m.lastName));
- } else if (choice == 3) {
- System.out.printf("3-name monogram for %s\n",m.monogram(m.firstName, m.middleName,
- m.lastName));
- System.out.printf("Complete name: %s\n", m.completeName(m.firstName, m.middleName,
- m.lastName));
- } else {
- System.out.println("Invalid choice made.");
- }
- System.out.println("______ Ending application ______");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement