Java program: Your job is to write a program that does the following: Prompts the user to enter their name. Displays a greeting to the user with their first name only

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Java program:

Your job is to write a program that does the following:

  1. Prompts the user to enter their name.
  2. Displays a greeting to the user with their first name only.

 

Sample run
Input:
Snoopy
Run:
What is your name? Snoopy
Hello Snoopy!
Notes
• In the sample run, there is a space between the question mark and the input entered by the user. Since you are supposed to exactly
match the output, don't forget to include a space there. Also, make sure to use a println Sstatement to print the last line of the output.
• There are two methods that you can use to read in strings from the console. The first is called nextLine. This method reads the rest
of the entire line. This is good when you know you want to read a few pieces of information or that there is only a single piece of
information on that line. However, this method would not be good if you wanted to just read in the word "Donald" when the user
inputs "Donald Trump". In this case, nextLine would read in the entire full name. The other method for reading is called next. This
method reads up until a whitespace (e.g., blank). This method is great when you just need to read in a piece of data on a line that's a
string. In other words, using next after the user types in "Donald Trump" would give just the "Donald". That should be the approach
you take here for this program since we are not guaranteed the user will enter just a first name . they might enter a full name and we
only want the first name.
Transcribed Image Text:Sample run Input: Snoopy Run: What is your name? Snoopy Hello Snoopy! Notes • In the sample run, there is a space between the question mark and the input entered by the user. Since you are supposed to exactly match the output, don't forget to include a space there. Also, make sure to use a println Sstatement to print the last line of the output. • There are two methods that you can use to read in strings from the console. The first is called nextLine. This method reads the rest of the entire line. This is good when you know you want to read a few pieces of information or that there is only a single piece of information on that line. However, this method would not be good if you wanted to just read in the word "Donald" when the user inputs "Donald Trump". In this case, nextLine would read in the entire full name. The other method for reading is called next. This method reads up until a whitespace (e.g., blank). This method is great when you just need to read in a piece of data on a line that's a string. In other words, using next after the user types in "Donald Trump" would give just the "Donald". That should be the approach you take here for this program since we are not guaranteed the user will enter just a first name . they might enter a full name and we only want the first name.
It is highly likely that the output is still not exactly as specified. Note that the sample run above includes both output (what the program
prints out) and input (what the user enters). Remember that when the user enters a value, they will press Enter key after the value is typed.
Hence, a more detailed sample run would be the following where the <Enter> is represented by e.
Keep in mind that the user types "Snoopy", not your program.
What is_your name? Snoopy!
HelloISnoopy!
----
But on this line you echo back whatever the user typed in as the name..it may not be "Snoopy".
If the user types Snoopy and presses Enter, then the input part of the sample run above is Snoopye. That would mean the output part would
be everything else: the question "What is your name? " (including the space after the question mark) and the sentence, "Hello Snoopy". This
is why the expected output of the first test case in Submit mode is the following, which doesn't include the input:
What is your name? Hello Snoopy.
Transcribed Image Text:It is highly likely that the output is still not exactly as specified. Note that the sample run above includes both output (what the program prints out) and input (what the user enters). Remember that when the user enters a value, they will press Enter key after the value is typed. Hence, a more detailed sample run would be the following where the <Enter> is represented by e. Keep in mind that the user types "Snoopy", not your program. What is_your name? Snoopy! HelloISnoopy! ---- But on this line you echo back whatever the user typed in as the name..it may not be "Snoopy". If the user types Snoopy and presses Enter, then the input part of the sample run above is Snoopye. That would mean the output part would be everything else: the question "What is your name? " (including the space after the question mark) and the sentence, "Hello Snoopy". This is why the expected output of the first test case in Submit mode is the following, which doesn't include the input: What is your name? Hello Snoopy.
Expert Solution
steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Knowledge Booster
Function Arguments
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education