Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a Java program NameInput.java with the behavior shown below. The user inpu

ID: 3670006 • Letter: W

Question

Write a Java program NameInput.java with the behavior shown below. The user input should be after the colon.

Enter first name: Sam

Enter last name: Student

Enter age: 18

Enter birth month: September

Enter birth day: 15

Enter birth year: 1997

As an output, you should print “Sam Student is 18 years old and was born on September 15, 1997.” (without the quotes).

I think my teacher wants us to write this code using methods but I'm not sure how to do so using import java.util.Scanner. Thank you in advance.

Explanation / Answer

import java.util.Scanner;

public class NameInput {

public static void main(String[] args) {

String firstName;
String lastName;
int age;
String birthmonth;
int birthday;
int birthyear;
//Create scanner to obtain user input
Scanner scanner1 = new Scanner( System.in );

//obtain user input
System.out.print("Enter your first name: ");
firstName = scanner1.nextLine();

System.out.print("Enter your last name: ");
lastName = scanner1.nextLine();

System.out.println("enter age:");
age=scanner1.nextInt();

System.out.println("Enter your birth month: ");
birthmonth = scanner1.nextLine();

System.out.print("Enter your birth day: ");
birthday = scanner1.nextInt();

System.out.print("Enter your birth year: ");
birthyear = scanner1.nextInt();

//output information
System.out.print(firstName+" "+lastName+"is"+age+"old and he was born on"+birthmonth +" "+birthday +","+birthyear);

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote