Question

In: Computer Science

In.java Write down a program that asks the user for their full name given in the...

In.java

Write down a program that asks the user for their full name given in the format first last. The program will do the necessary processing and print the name in a table with 3 columns: Last, First, Initials. Requirements/Specifications...

  1. Your program run must be identical with the one shown as an example (both in how it reads the input and it on what it prints). The table must have the top and bottom lines as shown.
  2. The columns for Last and First must have exactly 15 spaces each.
  3. The data in the columns must be LEFT aligned
  4. You can assume that the user gives good input: two words separated by one space.
 as a Sample run 
Please enter your first and last name: Tom Cruise
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|Cruise         |Tom           |T.C.|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Solutions

Expert Solution

Summary-

The input is received by a prompt from the user in the form of Strings using two variables first and last for this purpose.

The output is generated as above as given in the question using the "printf" and "println" Statements.

By using the printf statement, left alignment of 15 spaces is given for the first name and last name in the output.

For the printing of the initials , charAt() statement is used.

Code-

import java.util.*;

public class Bts {

  
   public static void main(String[] args) {
  
   //Declaring variables for first and last names
   String first,last;
  
   //Scanner class to receive the inputs
   Scanner sc=new Scanner(System.in);
  
   //Prompting the user to enter an input
   System.out.printf("Please enter your first and last name: ");
  
   first=sc.next();
  
   last=sc.next();
  
   System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
  
   System.out.printf("|");
   System.out.printf("%-15s",last);
   System.out.printf("|");
   System.out.printf("%-15s",first);
   System.out.printf("|");
   System.out.printf(first.charAt(0)+"."+last.charAt(0)+".");
   System.out.printf("|");
  
   System.out.println();
   System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
  
   }
  
}

Output-


Related Solutions

Write a C program that performs the following: Asks the user to enter his full name...
Write a C program that performs the following: Asks the user to enter his full name as one entry. Asks the user to enter his older brothers’ names each at a time (the user should be instructed by the program to enter NULL if he does not have any older brother). Asks the user to enter his younger brothers’ names each at a time (the user should be instructed by the program to enter NULL if he does not have...
Python: Write a program that asks the user for the name of a file. The program...
Python: Write a program that asks the user for the name of a file. The program should display the contents of the file line by line.
Write a program that asks the user to enter the name of a file, and then...
Write a program that asks the user to enter the name of a file, and then asks the user to enter a character. The program should count and display the number of times that the specified character appears in the file. Use Notepad or another text editor to create a sample file that can be used to test the program. Sample Run java FileLetterCounter Enter file name: wc4↵ Enter character to count: 0↵ The character '0' appears in the file...
Tail of a File, C++ Program. write a program that asks the user for the name...
Tail of a File, C++ Program. write a program that asks the user for the name of a text file. The program should display the last 10 lines, or all lines if less than 10. The program should do this using seekg Here is what I have so far. #include<iostream> #include<fstream> #include<string> using namespace std; class File { private:    fstream file;    string name; public:    int countlines();    void printlines(); }; int File::countlines() {    int total =...
Write a program that: a. Asks the user for their first name using a JOptionPane. b....
Write a program that: a. Asks the user for their first name using a JOptionPane. b. Asks the user for their age using a JOptionPane. C. Asks the user for their last name using a JOptionPane. d. Pops up a dialog with the following information: i. Number of characters in the first & last name combined ii. The full name all-in upper-case letters iii. The full name all-in lower-case letters iv. The first letter of the name v. The age...
Write a program that asks the user for a file name. The file contains a series...
Write a program that asks the user for a file name. The file contains a series of scores(integers), each written on a separate line. The program should read the contents of the file into an array and then display the following content: 1) The scores in rows of 10 scores and in sorted in descending order. 2) The lowest score in the array 3) The highest score in the array 4) The total number of scores in the array 5)...
Python English algorithm explanation Write a program that asks the user for the name of a...
Python English algorithm explanation Write a program that asks the user for the name of a file in the current directory. Then, open the file and process the content of the file. 1)If the file contains words that appear more than once, print “We found duplicates.” 2)If the file does not contain duplicate words, print “There are no duplicates.”
Python English algorithm explanation Write a program that asks the user for the name of a...
Python English algorithm explanation Write a program that asks the user for the name of a file in the current directory. Then, open the file and process the content of the file. 1)If the file contains words that appear more than once, print “We found duplicates.” 2)If the file does not contain duplicate words, print “There are no duplicates.”
Write a Python program that asks the user to enter a student's name and 8 numeric...
Write a Python program that asks the user to enter a student's name and 8 numeric tests scores (out of 100 for each test). The name will be a local variable. The program should display a letter grade for each score, and the average test score, along with the student's name. Write the following functions in the program: calc_average - this function should accept 8 test scores as arguments and return the average of the scores per student determine_grade -...
PYTHON Write a program that asks the user to enter a student's name and 8 numeric...
PYTHON Write a program that asks the user to enter a student's name and 8 numeric assignment scores (out of 100 for each assignment). The program should output the student's name, a letter grade for each assignment score, and a cumulative average for all the assignments. Please note, there are 12 students in the class so your program will need to be able to either accept data for 12 students or loop 12 times in order to process all the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT