Answered step by step
Verified Expert Solution
Question
1 Approved Answer
For this assignment, you will use the built - in String and Scanner classes of Java to do some simple String manipulations. Download the given
For this assignment, you will use the builtin String and Scanner classes of Java to do
some simple String manipulations.
Download the given Java source code file Programjava. This file contains the stubs
of five methods. You must write the appropriate code to fillin each of these five methods,
which are described below. The main method will call each of these five methods, in turn. You
can comment out all but one of these calls while you develop the code for that one method.
phoneNumber
This method should prompt the user to type in a digit phone number, such as
Your method should read in this value as a String not an int Your
method should output the phone number using the common dash notation. For
example, the phone number above should be displayed as:
Note there is a blank space after the symbol. Your method is not required to do any
error checking. We assume that the user will type in exactly digits.
formatNameCase
This method should prompt the user to enter their first name, and then prompt the user
again to enter their last name. That is your program should read in two String values.
For example, the user might enter JohN and doE Your method should output a
greeting to the user, where the first letter of each name is a capital letter, and the
remaining letters are lowercase. For example, your output for the name above should be:
Nice to meet you John Doe
Your method is not required to do any error checking. We assume that the user will type
in alphabetic letters, and not any other symbols.
formatNameOrder
This method should prompt the user to type in their full name on a single line in the
format: FirstName MiddeInitial LastName. For example, the user might enter Jane Q
Citizen. Note that the user must enter a dot period after the middle initial.
Your method should output a greeting to the user, where the format of the name is
changed to put the last name first. For example, the output corresponding to the example
above would be note the inclusion of a comma:
Nice to meet you Citizen, Jane Q
Your method is not required to do any error checking. We assume that the user will type
in valid input.
shortenName
This method should prompt the user to type in their full name on a single line in the
format: FirstName MiddleName LastName. For example, the user might enter John
Quincy Adams.
Your method should output a greeting to the user, where the format of the name is
changed so that both the first name and the middle name are only the initial including the
period For example, the output corresponding to the example above would be:
Nimport java.util.Scanner;
public class Project
public static void main String args
System.out.println "Hello world" ;
You can test each of the different
methods by uncommenting the method name below
that is remove the slashslash
phoneNumber;
formatNameCase;
formatNameOrder;
shortenName;
checkProtection;
System.out.println "Goodbye" ;
public static void phoneNumber
System.out.println "Delete these System.out statements and";
System.out.println "replace them with code ;
System.out.println "that will ask the user ;
System.out.printlnto type in digits, and then";
System.out.println "output the phone number in the";
System.out.println "correct format";
public static void formatNameCase
public static void formatNameOrder
public static voidice to meet you J Q Adams
Your method is not required to do any error checking. We assume that the user will type
in valid input.
checkProtection
Computers are frequently used in checkwriting systems, such as payroll. The check
writing system may have a limit on the amount of the check. For this problem, we will
assume that limit is $ ie there are at most digits in the amount. Smaller
amounts are also legal, such as:
$
Notice that the dollar sign always appears on the far left, followed by three locations,
followed by a dot, followed by two locations. It is possible for a person to commit fraud
by writing in a value in the blank spaces above, changing $ to $
To prevent this fraud, payroll systems automatically add asterisks stars in any blank
spaces between the dollar sign and the leftmost digit. For example, the amount above
would be printed as:
$
Your method should prompt the user to type in a monetary amount as a floatingpoint
number not as a String This value should not be larger than Your method
should output that monetary amount in the fraud protection format described above. If
the input value has more than two digits to the right of the decimal point, then the faction
of a cent should be truncated and ignored.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started