Menu

[Solved]Thanks Advance Java M Creating 3 Classes Named Date Person Main Date Class Follows Public Q37215877

Thanks in advance.

In Java I’m creating 3 classes named Date, Person, andMain.
My Date class is as follows:
public class Date
{
private int day;
private int month;
private int year;
  
public Date(int month, int day, int year)
{
setMonth(month);
setDay(day);
setYear(year);
}
  
public int getMonth()
{
return month;
}
public int getDay()
{
return day;   
}
public int getYear()
{
return year;
}
  
public void setMonth(int month)
{
this.month = month;
if(month < 1 || month > 12)
{
this.month = 1;
}
}
public void setDay(int day)
{
this.day = day;
if(day <= 0)
{
this.day = 1;
}
else if(month == 2)
{
this.day = day;
if(day < 1 || day > 28)
{
this.day = 1;
}
}
else if(month == 1 || month == 3 || month == 5 || month == 7 ||month == 8 || month == 10 || month == 12)
{
this.day = day;
if(day < 1 || day > 31)
{
this.day = 1;
}
}
else {
if(day < 1 || day > 30)
this.day = 1;
}
}
public void setYear(int year)
{
this.year = year;
if(year < 0)
{
this.year = 1900;
}
}
  
public String toString(int month, int day, int year)
{
String temp = null;
setMonth(month);
setDay(day);
setYear(year);
temp = (getMonth() + “/” + getDay() + “/” + getYear());
return temp;
}
}

My Person class is:
public class Person
{
private String firstName;
private String lastName;
public Date dateOfBirth;

public Person(String firstName, String lastName, Date dob)
{
this.firstName = firstName;
this.lastName = lastName;
dateOfBirth = dob;
}

public String getFirstName()
{
return firstName;
}
public String getLastName()
{
return lastName;
}
public Date getDateOfBirth()
{
return dateOfBirth;
}

public void setFirstName(String fname)
{
firstName = fname;
}
public void setLastName(String lname)
{
lastName = lname;
}
public void setDateOfBirth(Date dob)
{
dateOfBirth = dob;
}

public void setDateOfBirth(int month, int day, int year)
{
dateOfBirth.setMonth(month);
dateOfBirth.setDay(day);
dateOfBirth.setYear(year);
}
}

How do i get my getDateOfBirth() method to work when I call itin my Main class?

Expert Answer


Answer to Thanks in advance. In Java I’m creating 3 classes named Date, Person, and Main. My Date class is as follows: public clas… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *