Write an application that asks the user to enter his/her first name, last name,
ID: 3876379 • Letter: W
Question
Write an application that asks the user to enter his/her first name, last name, birthday, and where you born (all fields type String) and prints their information to the console. Use the techniques discuss in class. The application should use printf.
For reference you could read Chapter 2 from the textbook. Remember to use the class Scanner and the method next() or nextLine() for String fields.
You must use a text editor, like notepad.exe, notepad++.exe, etc (you can not used any IDE).
You must submit four files, two source codes (.java extension) and two bytecodes (.class extension).
____________________________________________________
____________________________________________________
Open a terminal or command prompt (Ctrl+R cmd this is for Windows OS). Then open a text editor, like notepad MyInfo.java
To compile the application from console type:
C:> javac MyInfo.java
To run or test your application from console (type the name of your bytecodewithout the extension):
C:> java MyInfo
The output must be something like these:
__________________________________________________________
Welcome!
What is your first name? Carlos
What is your last name? Lopez
When is your birthday? 08/12/1979
Where did you born? Jamaica
Display my info:
First Name: Carlos
Last Name: Lopez
Birthday : 08/12/1979
Born in : Jamaica
Explanation / Answer
Java code :
import java.util.Scanner;
import java.io.*;
class Work {
public static void main (String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
System.out.println("Welcome");
System.out.println("Enter First Name : ");
String firstName = sc.nextLine();
System.out.println("Enter Last Name : ");
String lastName = sc.nextLine();
System.out.println("Enter Your Birthday : ");
String birthday = sc.nextLine();
System.out.println("Enter Your Place of Birth : ");
String placeBirth = sc.nextLine();
System.out.println();
System.out.println("Display my info :") ;
System.out.println("Name: " + firstName + " " + lastName);
System.out.println("Birthday: " + birthday);
System.out.println("Place of Birth: " + placeBirth);
}
}
Link to demo :
https://ide.geeksforgeeks.org/5czaK0Qg7x
Note: I had done everything in one file. Since, you haven't mentioned the required layout. You just need to break the above code into different files as per your requirement.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.