0% found this document useful (0 votes)
16 views7 pages

Aa Document Code

Uploaded by

bernardmarcella1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views7 pages

Aa Document Code

Uploaded by

bernardmarcella1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Import javax.swing.

*;

Import java.time.*;

Import java.time.format.*;

Public class Main {

Public static void main(String[] args) {

String name = JOptionPane.showInputDialog(null, “1. What is your name?”, “User


Input”, JOptionPane.QUESTION_MESSAGE);

String address = JOptionPane.showInputDialog(null, “2. What is your address?”,


“User Input”, JOptionPane.QUESTION_MESSAGE);

LocalDate dateOfBirth = null;

DateTimeFormatter inputFormatter = DateTimeFormatter.ofPattern(“MM/dd/yyyy”);

DateTimeFormatter outputFormatter = DateTimeFormatter.ofPattern(“MMMM d,


yyyy”);

While (dateOfBirth == null) {

String dateOfBirthInput = JOptionPane.showInputDialog(null, “3. What is your


date of birth (MM/DD/YYYY)?”, “User Input”, JOptionPane.QUESTION_MESSAGE);

Try {

dateOfBirth = LocalDate.parse(dateOfBirthInput, inputFormatter);

LocalDate currentDate = LocalDate.now();

If (dateOfBirth.isAfter(currentDate)) {

JOptionPane.showMessageDialog(null, “Date of birth cannot be in the future.


Please enter a valid date.”, “Input Error”, JOptionPane.ERROR_MESSAGE);

dateOfBirth = null;

} catch (DateTimeParseException e) {

JOptionPane.showMessageDialog(null, “Invalid date format. Please use


MM/DD/YYYY.”, “Input Error”, JOptionPane.ERROR_MESSAGE);

Int age = Period.between(dateOfBirth, LocalDate.now()).getYears();

String ageStatus;

If (age >= 60) {

ageStatus = “Senior”;

} else if (age >= 18) {

ageStatus = “Legally Adult”;

} else {
ageStatus = “Minor”;

String gender;

String genderOutput = “”;

While (true) {

Gender = JOptionPane.showInputDialog(null, “4. What is your gender? (M/F)”,


“User Input”, JOptionPane.QUESTION_MESSAGE);

If (gender.equalsIgnoreCase(“M”) || gender.equalsIgnoreCase(“F”)) {

If (gender.equalsIgnoreCase(“M”)) {

genderOutput = “Male”;

} else {

genderOutput = “Female”;

Break;

} else {

JOptionPane.showMessageDialog(null, “Invalid gender input. Please enter ‘M’


or ‘F’.”, “Input Error”, JOptionPane.ERROR_MESSAGE);

String output = “User Information\n” +

“Name: “ + name + “\n” +

“Address: “ + address + “\n” +

“Date of Birth: “ + dateOfBirth.format(outputFormatter) + “\n” +

“Age: “ + age + “\n” +

“Status: “ + ageStatus + “\n” +

“Gender: “ + genderOutput;

JOptionPane.showMessageDialog(null, output, “User Information Summary”,


JOptionPane.INFORMATION_MESSAGE);

System.exit(0);

Import javax.swing.*;

Import java.time.*;

Import java.time.format.*;
Public class Main {

Public static void main(String[] args) {

String name = JOptionPane.showInputDialog(null, “1. What is your name?”, “User


Input”, JOptionPane.QUESTION_MESSAGE);

String address = JOptionPane.showInputDialog(null, “2. What is your address?”,


“User Input”, JOptionPane.QUESTION_MESSAGE);

LocalDate dateOfBirth = null;

DateTimeFormatter inputFormatter = DateTimeFormatter.ofPattern(“MM/dd/yyyy”);

DateTimeFormatter outputFormatter = DateTimeFormatter.ofPattern(“MMMM d,


yyyy”);

While (dateOfBirth == null) {

String dateOfBirthInput = JOptionPane.showInputDialog(null, “3. What is your


date of birth (MM/DD/YYYY)?”, “User Input”, JOptionPane.QUESTION_MESSAGE);

Try {

dateOfBirth = LocalDate.parse(dateOfBirthInput, inputFormatter);

LocalDate currentDate = LocalDate.now();

If (dateOfBirth.isAfter(currentDate)) {

JOptionPane.showMessageDialog(null, “Date of birth cannot be in the future.


Please enter a valid date.”, “Input Error”, JOptionPane.ERROR_MESSAGE);

dateOfBirth = null;

} catch (DateTimeParseException e) {

JOptionPane.showMessageDialog(null, “Invalid date format. Please use


MM/DD/YYYY.”, “Input Error”, JOptionPane.ERROR_MESSAGE);

Int age = Period.between(dateOfBirth, LocalDate.now()).getYears();

String ageStatus;

If (age >= 60) {

ageStatus = “Senior”;

} else if (age >= 18) {

ageStatus = “Legally Adult”;

} else {

ageStatus = “Minor”;

}
String gender;

String genderOutput = “”;

While (true) {

Gender = JOptionPane.showInputDialog(null, “4. What is your gender? (M/F)”,


“User Input”, JOptionPane.QUESTION_MESSAGE);

If (gender.equalsIgnoreCase(“M”) || gender.equalsIgnoreCase(“F”)) {

If (gender.equalsIgnoreCase(“M”)) {

genderOutput = “Male”;

} else {

genderOutput = “Female”;

Break;

} else {

JOptionPane.showMessageDialog(null, “Invalid gender input. Please enter ‘M’


or ‘F’.”, “Input Error”, JOptionPane.ERROR_MESSAGE);

String output = “User Information\n” +

“Name: “ + name + “\n” +

“Address: “ + address + “\n” +

“Date of Birth: “ + dateOfBirth.format(outputFormatter) + “\n” +

“Age: “ + age + “\n” +

“Status: “ + ageStatus + “\n” +

“Gender: “ + genderOutput;

JOptionPane.showMessageDialog(null, output, “User Information Summary”,


JOptionPane.INFORMATION_MESSAGE);

System.exit(0);

import javax.swing.*;

import java.time.*;

import java.time.format.*;

public class Main {

public static void main(String[] args) {


String name = JOptionPane.showInputDialog(null, "1. What is your name?", "User
Input", JOptionPane.QUESTION_MESSAGE);

String address = JOptionPane.showInputDialog(null, "2. What is your address?",


"User Input", JOptionPane.QUESTION_MESSAGE);

LocalDate dateOfBirth = null;

DateTimeFormatter inputFormatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");

DateTimeFormatter outputFormatter = DateTimeFormatter.ofPattern("MMMM d,


yyyy");

while (dateOfBirth == null) {

String dateOfBirthInput = JOptionPane.showInputDialog(null, "3. What is your


date of birth (MM/DD/YYYY)?", "User Input", JOptionPane.QUESTION_MESSAGE);

try {

dateOfBirth = LocalDate.parse(dateOfBirthInput, inputFormatter);

LocalDate currentDate = LocalDate.now();

if (dateOfBirth.isAfter(currentDate)) {

JOptionPane.showMessageDialog(null, "Date of birth cannot be in the future.


Please enter a valid date.", "Input Error", JOptionPane.ERROR_MESSAGE);

dateOfBirth = null;

} catch (DateTimeParseException e) {

JOptionPane.showMessageDialog(null, "Invalid date format. Please use


MM/DD/YYYY.", "Input Error", JOptionPane.ERROR_MESSAGE);

int age = Period.between(dateOfBirth, LocalDate.now()).getYears();

String ageStatus;

if (age >= 60) {

ageStatus = "Senior";

} else if (age >= 18) {

ageStatus = "Legally Adult";

} else {

ageStatus = "Minor";

String gender;

String genderOutput = "";


while (true) {

gender = JOptionPane.showInputDialog(null, "4. What is your gender? (M/F)",


"User Input", JOptionPane.QUESTION_MESSAGE);

if (gender.equalsIgnoreCase("M") || gender.equalsIgnoreCase("F")) {

genderOutput = gender.equalsIgnoreCase("M") ? "Male" : "Female";

break;

} else {

JOptionPane.showMessageDialog(null, "Invalid gender input. Please enter 'M' or


'F'.", "Input Error", JOptionPane.ERROR_MESSAGE);

String output = "User Information\n" +

"Name: " + name + "\n" +

"Address: " + address + "\n" +

"Date of Birth: " + dateOfBirth.format(outputFormatter) + "\n" +

"Age: " + age + "\n" +

"Status: " + ageStatus + "\n" +

"Gender: " + genderOutput;

JOptionPane.showMessageDialog(null, output, "User Information Summary",


JOptionPane.INFORMATION_MESSAGE);

System.exit(0);

String output = “Hello, “ + name + “. You reside at “ + address +

“. Your birthday is “ + dateOfBirth.format(outputFormatter) +

“, which makes you “ + age + “ years old. “ +

“Therefore, you are classified as “ + ageStatus +

“, and you identify as “ + genderOutput + “.”;

JOptionPane.showMessageDialog(null, output);

System.exit(0);

You might also like