Write an application that asks the user to enter his/her first name, last name,
ID: 3711473 • 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
PLEASE IS VERY IMPORTANT TO ME TO KNOW HOW TO WRITE BOTH FILES .JAVAEXTENSION AND BYTECODES .CLASS EXTENSION
Explanation / Answer
Hi,
Steps to create .java file
Steps to create .class file
Run your Application
Remember Files name are case sensitive, so user class name should exactly match with your filename
Code:
//MyInfo.java
import java.util.Scanner;
public class MyInfo {
public static void main(String[] args) {
// TODO Auto-generated method stub
User user = new User();
System.out.printf("Welcome!", null);
System.out.printf("What is your first name?", null);
Scanner sc = new Scanner(System.in);
String first_name =sc.nextLine();
user.setFirst_name(first_name);
System.out.printf("What is your last name?", null);
String last_name = sc.nextLine();
user.setLast_name(last_name);
System.out.printf("When is your birthday?", null);
String dob =sc.nextLine();
user.setDob(dob);
System.out.printf("Where did you born?",null);
String pob =sc.nextLine();
user.setPob(pob);
System.out.printf("Displaying your Information: %s",user);
}
}
//User.java
class User{
private String first_name;
private String last_name;
private String dob; //date of birth
private String pob; //place of birth
public String getFirst_name() {
return first_name;
}
public void setFirst_name(String first_name) {
this.first_name = first_name;
}
public String getLast_name() {
return last_name;
}
public void setLast_name(String last_name) {
this.last_name = last_name;
}
public String getDob() {
return dob;
}
public void setDob(String dob) {
this.dob = dob;
}
public String getPob() {
return pob;
}
public void setPob(String pob) {
this.pob = pob;
}
// overriding this method to display user details
public String toString() {
return "First Name: "+this.first_name+" Last Name: "+this.last_name+
" Birthday : "+this.dob+" Born in : "+this.pob;
}
}
Please let me know if you have any doubt
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.