Question

In: Computer Science

Write a program (name it firstMiddleLast _yourInitials.java (yourInitials represents your initials) that will: 1. Ask the...

Write a program (name it firstMiddleLast _yourInitials.java (yourInitials represents your initials) that will:

1. Ask the user (include appropriate dialog) to enter their:

first name
middle name
last name

save each of the above as a String variable as follows:

firstName
middleName
lastName


2. Print to the screen the number of characters in each of the names (first, middle and last)

3. Print to the screen total number of characters in all three names. Include appropriate dialog in your output.

4. Print to the screen the initials of the person (first letter of the first, middle and last names) in all capitals with no space or lines between them. For example JFK.

5. Print to the screen the total of the ASCII values of the initials printed in #4 above. For example the initials JFK would sum to 219 (74 + 70 + 75). Remember that the ASCII values are as follows and to find the ASCII value of a single character by casting the character to an int by using (int).

A

65

N

78

B

66

O

79

C

67

P

80

D

68

Q

81

E

69

R

82

F

70

S

83

G

71

T

84

H

72

U

85

I

73

V

86

J

74

W

87

K

75

X

88

L

76

Y

89

M

77

Z

90

Solutions

Expert Solution

import java.util.Scanner;
class Test{
   //function for charcter count of String name
   public int charCount(String nm){
       int count = 0;
       //Counts each character except space
       for(int x = 0; x < nm.length(); x++) {
           if(nm.charAt(x) != '\n')
               count++;
       }
       return count;
   }
   //function for capitalize fitst character in String name
   public String getFirstChar(String nm){
       String capCh="";
       for(int x=0;x<nm.length();x++){
String first = nm.substring(0,1); // get first character of each word
capCh = first.toUpperCase(); // capitalize first character
}
       return capCh;
   }
   //main function starts
   public static void main(String[] args){
       //taking input from user first ,middle and last names
       Scanner read =new Scanner(System.in);
       System.out.print("Enter first name : ");
       String firstName =   read.nextLine();
       System.out.print("Enter middle name : ");
       String middleName = read.nextLine();
       System.out.print("Enter last name : ");
       String lastName =   read.nextLine();

       //creating object for Test class
       Test obj = new Test();
       int fCount = obj.charCount(firstName);
       int mCount = obj.charCount(middleName);
       int lCount = obj.charCount(lastName);
       //displaying count of characters in names
       System.out.println("first name characters count : "+fCount);
       System.out.println("middle name characters count : "+mCount);
       System.out.println("last name characters count : "+lCount);
       //displaying count of all characters in 3 names
       System.out.println("number of characters in 3 names : "+ (fCount+mCount+lCount));
       //converting every first letter of name as Capitalize
       String ch1 = obj.getFirstChar(firstName);
       String ch2 = obj.getFirstChar(middleName);
       String ch3 = obj.getFirstChar(lastName);
       //displaying every first letter of name as Capitalize
       System.out.println("initials : "+ (ch1+ch2+ch3));
       //process of getting ascii value of initials
       char c1 = ch1.charAt(0);
       char c2 = ch2.charAt(0);
       char c3 = ch3.charAt(0);
       int char1=c1;
       int char2=c2;
       int char3=c3;
       //displaying initials Ascii value
       System.out.println("Ascii value : "+ ((int)char1+(int)char2+(int)char3) );

   }
}
-------------------------------------------------------------------------------------------------------------

name the File as Test.java


Related Solutions

Please name your driver program XXX_P03 where XXX are your initials. Please name your array utilities...
Please name your driver program XXX_P03 where XXX are your initials. Please name your array utilities class ArrayUtilities. Have only static methods in your ArrayUtilities class. Make sure your program will work for any array size. Write a driver program with a double array that is initialized with the following test data. You may hard code this data into your array. Echo the input in a neat table formatted exactly as below (5 elements to a line and aligned). Then...
Write a program that does the following in order: 1. Ask user to enter a name...
Write a program that does the following in order: 1. Ask user to enter a name 2. Ask the user to enter five numbers “amount1”, “amount2”, “amount3”, “amount4”, “amount5” 3. Calculate the sum of the numbers “amount1”, “amount2”, “amount3”, “amount4”, “amount5” 4. If the sum is greater than 0, print out the sum 5. If the sum is equal to zero, print out “Your account balance is zero” 6. If the sum is less than 0, print out “Your account...
(8 marks) Write a program to ask user to enter an integer that represents the number...
Write a program to ask user to enter an integer that represents the number of elements, then generate an ArrayList containing elements which are all random integers in range [75, 144] , and finally display index and value of each element. REQUIREMENTS The user input is always correct (input verification is not required). Your code must use ArrayList. Your program must use only printf(…) statements to adjust the alignment of your output. Your code must display the index in descending...
4. Please name your driver program XXX_P04 where XXX are your initials. Given the array inputArray...
4. Please name your driver program XXX_P04 where XXX are your initials. Given the array inputArray (doubles), write a method called swap which will swap any two contiguous (next to each other) elements. Swap will be passed two parameters, the index of the first element to be swapped and the array name. Write another method printArray that will print the array 5 elements to a line. PrintArray will be passed one parameter the array name. See the videos for help...
You will write a single class named WordsXX- replace the XX's with your initials. The program...
You will write a single class named WordsXX- replace the XX's with your initials. The program will have 2 overloaded methods named wordMaker. They will have to be declared as static. Both methods will not have a return type but they will print some text. The first method wordMaker signature will not accept any parameters and when invoked will simply print out the line "lower case words". The second overloaded wordMaker method will accept an integer and print "Words in...
You will write a single class named WordsXX- replace the XX's with your initials. The program...
You will write a single class named WordsXX- replace the XX's with your initials. The program will have 2 overloaded methods named wordMaker. They will have to be declared as static. Both methods will not have a return type but they will print some text. The first method wordMaker signature will not accept any parameters and when invoked will simply print out the line "lower case words". The second overloaded wordMaker method will accept an integer and print "Words in...
java programming write a program with arrays to ask the first name, last name, middle initial,...
java programming write a program with arrays to ask the first name, last name, middle initial, IDnumber and 3 test scores of 10 students. calculate the average of the 3 test scores. show the highest class average and the lowest class average. also show the average of the whole class. please use basic codes and arrays with loops the out put should look like this: sample output first name middle initial last name    ID    test score1 test score2...
Write a program using C language that -ask the user to enter their name or any...
Write a program using C language that -ask the user to enter their name or any other string (must be able to handle multiple word strings) - capture the epoch time in seconds and the corresponding nanoseconds - ask the user to type in again what they entered previously - capture the epoch time in seconds and the corresponding nanoseconds -perform the appropriate mathematical calculations to see how long it took in seconds and nanoseconds (should show to 9 decimal...
ASSIGNMENT: Write a program to ask for the name and test score for 8 students, validate...
ASSIGNMENT: Write a program to ask for the name and test score for 8 students, validate that the test score is between 0.0 and 100.0 inclusive, and store the names and test scores in 2 parallel arrays. Then, calculate and display the average of the test scores. Finally, display all the students who have test scores above the average. Example Run #1: (bold type is what is entered by the user) Enter student name #1: George Enter the score for...
Please code in c# (C-Sharp) Write a program that will ask the user for their name....
Please code in c# (C-Sharp) Write a program that will ask the user for their name. If the user does not input anything, display a warning before continuing. The program will then ask the user whether they want to have an addition, subtraction, multiplication, or division problem. Once the user indicates their choice, the program will display 2 randomly generated numbers from 1 to 9 in a math problem matching the user’s choice. Example: user selects addition, the equation presented...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT