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

FBS.java All people have a full name, birth date, and sex. Create a FBS class wi

ID: 3623432 • Letter: F

Question

FBS.java All people have a full name, birth date, and sex. Create a FBS class with a constructor that will have the person's Full Name, Birth Date, and sex (M/F). Test it by creating a main method that will ask the user to enter his/her full name, birth date, and sex. Your program should print the person's information in the format shown below.

> java FBS

Please enter name: Juan Paolo N. Dela Cruz
Please enter your birth date (dd-mm-yyyy): 23-02-1978
Please enter sex (M/F): M

Dela Cruz, Juan Paolo N.
Male, 32 years old

 

P.S. I need a code that uses import java.io.*

Explanation / Answer

please rate - thanks

I don't see how your distingushing where to break the name into first middle last, you don't specify anything about initials

import java.io.*;
public class BirthDateTest
{static String dob;
public static void main(String[] args)throws IOException
{BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
int emonth,eday,eyear;
String sday,smonth,syear,name;
char sex;
System.out.print("Please enter name: ");
name=in.readLine();
System.out.print("Please enter your birth date dd-mm-yyyy: ");
dob=in.readLine();
smonth=dob.substring(0,2);
sday=dob.substring(3,5);
syear=dob.substring(6,10);
emonth=Integer.parseInt(smonth);
eday=Integer.parseInt(sday);
eyear=Integer.parseInt(syear);
System.out.print("Please enter sex (M/F): ");
sex=in.readLine().charAt(0);

BirthDate date=new BirthDate(emonth,eday,eyear,name,sex);

System.out.println(date.getName()+" "+date.getSex()+", "+date.getAge()+" years old ");
}
}

--------------------------------------------------------------

import java.util.*;
public class BirthDate
{private int month,day,year;
private String Name;
private char sex;
public BirthDate(int m,int d,int y,String N, char s)
   {month=m;
    day=d;
    year=y;
    Name=N;
    sex=s;
   
   
    }
public int getAge()
{Calendar cal = Calendar.getInstance();
int d,m,y,emonth,eday,eyear;
d = cal.get(Calendar.DATE);
m = cal.get(Calendar.MONTH) + 1;
y = cal.get(Calendar.YEAR);
   if(m>month)
     return y-year;
if(m==month&&d>=day)
     return y-year;
return y-year-1;


}
public String getSex()
{if(sex=='M')
      return "Male";
else
      return "Female";
    }
public String getName()
{return Name;
}
}