Question

Create a class named Module2. You should submit your source code file (Module2.java). The Module2 class...

Create a class named Module2. You should submit your source code file (Module2.java). The Module2 class should contain the following data fields and methods (note that all data and methods are for objects unless specified as being for the entire class)

  1. Data fields:
    1. A String object named firstName
    2. A String object named middleName
    3. A String object name lastName
  2. Methods:
    1. A Module2 constructor method that accepts no parameters and initializes the data fields from 1) to empty Strings (e.g., firstName = "";)
    2. A method named monogram that accepts two parameter Strings s and t and returns, as a String, the first character from s followed by the first character from t
    3. A method named monogram that accepts three parameter Strings s, t, u and returns, as a String, the first character from s followed by the first character from t followed by the first character from u
    4. A method named completeName that accepts two parameter Strings s and t and returns, as a String, s followed by a space, followed by t
    5. A method named completeName that accepts three parameter Strings s, t, u and returns, as a String, s followed by a space, followed by t, followed by a space, followed by u
    6. A method named getName that accepts a parameter String prompt and does the following: creates a Scanner object, prints prompt to the console, uses Scanner's nextLine method to read the user input, and returns the String obtained from Scanner's nextLine method
    7. A main method that, in order:
      • Creates a new Module2 object using the constructor from a)
      • Prints the text “starting application” to the console
      • Calls method f) three times with arguments "Please enter your first name", "Please enter your middle name", and "Please enter your last name", storing the results in the three String fields firstName, middleName, and lastName
      • Creates a Scanner object, prompts the user to generate monograms and complete name using either first & last or first & middle & last names, with Scanner's nextInt method
        1. If the user entered 2, calls methods b) and d) with arguments (firstName, lastName) and prints the returned Strings to the console with appropriate labels (e.g., "two name monogram" for b)
        2. If the user entered 3, calls methods c) and e) with arguments (firstName, middleName lastName) and prints the returned Strings to the console with appropriate labels (e.g., "three name monogram" for c)
      • Prints the text “ending application” to the console

The program should be implemented as a single file holding the public class Module2.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

code


import java.util.Scanner;


public class Module2 {

String firstName,lastName,middleName;

public Module2()
{
firstName="";
lastName="";
middleName="";
}
public String monogram (String s,String t)
{
return s.charAt(0)+""+t.charAt(0);
}
public String monogram (String s,String t,String u)
{
return s.charAt(0)+""+t.charAt(0)+u.charAt(0);
}
public String completeName (String s,String t)
{
return s+" "+t;
}
public String completeName (String s,String t,String u)
{
return s+" "+t+" "+u;
}
public String getName(String prompt)
{
Scanner input=new Scanner(System.in);
System.out.print(prompt);
return input.nextLine();
}
public static void main(String[] args)
{
Module2 obj=new Module2();
obj.firstName=obj.getName("Please enter your first name: ");
obj.middleName=obj.getName("Please enter your middle name: ");
obj.lastName=obj.getName("Please enter your last name: ");
Scanner sc=new Scanner(System.in);
  
System.out.println("\nEnter 2. for generate monograms and complete name using either first & last");
System.out.println("Enter 3. for generate monograms and complete name using either first & last & middle names");
System.out.print("Your Choice: ");
int userChoice=sc.nextInt();

if(userChoice==2)
{
System.out.println("\nTwo name monogram: "+obj.monogram(obj.firstName, obj.lastName));
System.out.println("Compelete name is: "+obj.completeName(obj.firstName, obj.lastName));
}
if(userChoice==3)
{
System.out.println("\nThree name monogram: "+obj.monogram(obj.firstName, obj.lastName,obj.middleName));
System.out.println("Compelete name is: "+obj.completeName(obj.firstName, obj.lastName,obj.middleName));
}
}
  
}

output

If you have any query regarding the code please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appreciates with up vote. Thank You.

Add a comment
Know the answer?
Add Answer to:
Create a class named Module2. You should submit your source code file (Module2.java). The Module2 class...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • a) In Atom, create a new program file named greetByfullName.jsin your pl folder. b) Write a...

    a) In Atom, create a new program file named greetByfullName.jsin your pl folder. b) Write a function named greetByfullName that accepts two strings (firstName and lastName), and returns a cheery greeting. c) Test the function by prompting the user to enter their first name, and storing the name in a variable, and then prompting the user for their last name, and storing it in a second variable. This page says Enter your first name Susan Cancel OK This page says...

  • Create a Java program Named LB04 with a class name HardMonogram Input:   fullName Process: getInitial(separateName): extract the...

    Create a Java program Named LB04 with a class name HardMonogram Input:   fullName Process: getInitial(separateName): extract the first character string from each part of a full name and return it. getSeparateName(fullName): separate a full name into first name, middle name, and last name. setMonogram(): using getInitial(), generate the right monogram result, then display it. main(String[] args): driver method Output: - Using JOptionPane to get a first name, middle name, and last name at once, then, on a JOptionPane dialog, show the...

  • PART I: Create an abstract Java class named “Student” in a package named “STUDENTS”. This class...

    PART I: Create an abstract Java class named “Student” in a package named “STUDENTS”. This class has 4 attributes: (1) student ID: protected, an integer of 10 digits (2) student name: protected (3) student group code: protected, an integer (1 for undergraduates, 2 for graduate students) (4) student major: protected (e.g.: Business, Computer Sciences, Engineering) Class Student declaration provides a default constructor, get-methods and set-methods for the attributes, a public abstract method (displayStudentData()). PART II: Create a Java class named...

  • JAVA HELP (ARRAYS) Assignment Create a class named Module4 containing the following data members and methods...

    JAVA HELP (ARRAYS) Assignment Create a class named Module4 containing the following data members and methods (note that all data members and methods are for objects unless specified as being for the entire class) 1) Data members: none 2) Methods a. A method named displayContents that accepts an array of type int and prints their values to the b. A method named cemoveNegatives that accepts an array of type int, copies all its non-negative the new array should be the...

  • Part 2: Processing Strings (Individual work) Processing user-entered data to follow a specific format is a...

    Part 2: Processing Strings (Individual work) Processing user-entered data to follow a specific format is a common task. Often this involves using string functions to manipulate a set of input strings. Create a MATLAB script named namephone.m and place these lines of code at the beginning: name  = input('Enter your first and last name: ','s'); phone = input('Enter your area code and phone number: ','s'); Tasks Here are useful string functions:  length, strcat, strtrim, lower, upper, strcmp, findstr, strrep As you work...

  • Write the Java code for the class WordCruncher. Include the following members:

    **IN JAVAAssignment 10.1 [95 points]The WordCruncher classWrite the Java code for the class WordCruncher. Include the following members:A default constructor that sets the instance variable 'word' to the string "default".A parameterized constructor that accepts one String object as a parameter and stores it in the instance variable. The String must consist only of letters: no whitespace, digits, or punctuation. If the String parameter does not consist only of letters, set the instance variable to "default" instead. (This restriction will make...

  • Write a class named Book containing: Two instance variables named title and author of type String....

    Write a class named Book containing: Two instance variables named title and author of type String. A constructor that accepts two String parameters. The value of the first is used to initialize the value of title and the value of the second is used to initialize author. A method named toString that accepts no parameters. toString returns a String consisting of the value of title, followed by a newline character, followed by the value of author.

  • JAVA /** * This class stores information about an instructor. */ public class Instructor { private...

    JAVA /** * This class stores information about an instructor. */ public class Instructor { private String lastName, // Last name firstName, // First name officeNumber; // Office number /** * This constructor accepts arguments for the * last name, first name, and office number. */ public Instructor(String lname, String fname, String office) { lastName = lname; firstName = fname; officeNumber = office; } /** * The set method sets each field. */ public void set(String lname, String fname, String...

  • Write a class called Course_xxx that represents a course taken at a school. Represent each student...

    Write a class called Course_xxx that represents a course taken at a school. Represent each student using the Student class from the Chapter 7 source files, Student.java. Use an ArrayList in the Course to store the students taking that course. The constructor of the Course class should accept only the name of the course. Provide a method called addStudent that accepts one Student parameter. Provide a method called roll that prints all students in the course. Create a driver class...

  • c++ I need help! create Student.h In this class, you are provided with a class skeleton...

    c++ I need help! create Student.h In this class, you are provided with a class skeleton for the Student type. This type should contain two member variables: a string called name a vector of doubles called grades Additionally, you should declare the following functions: A constructor which accepts a single string parameter called name A void function, addGrade which accepts a single double parameter and adds it to the grades vector A function which accepts no parameters and returns the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT