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)
The program should be implemented as a single file holding the public class Module2.
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.
Create a class named Module2. You should submit your source code file (Module2.java). The Module2 class...
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 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 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 (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 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...
**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. 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 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 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 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...