Can someone please help with what im doing wrong in my code for java? the questi
ID: 3857110 • Letter: C
Question
Can someone please help with what im doing wrong in my code for java?
the question is use javadoc to generate HTML documentation for the code display 5.19 Use @author and @version tag for description of entire class Add a comment for every public method or constructor using the @param and @return tags when appropriate.
package chap4and5;
import java.util.Date;
/**
*
* @author coleen
*/
public class Person {
private String name;
private Date born;
private Date died;//null indicates still alive
{
System.out.println("ITMP 2650 Java Programming summer 2017");
System.out.println("author: Coleen Feador");
System.out.println("Assignment: Chapter 5 question 9");
}
public Person(String initialName,Date birthDate, Date deathDate, born, died)
{
if(consistent(birthDate, deathDate))
{
name = initialName;
born = new Date(birthDate);
if(deathDate == null)
died = null;
else
died = new Date(deathDate);
}
else
{
System.out.println("Inconsistent dates. aborting");
System.exit(0);
}
}
public Person(Person original)
{
if(original==null)
{
System.out.println("Fatal error");
System.exit(0);
}
name = original.name;
born = new Date(original.born);
if(original.died == null)
died = null;
else
died = new Date(original.died);
}
public void set(String newName, Date birthDate, Date deathDate)
{
if(consistent(birthDate,deathDate))
{
name = newName;
born = new Date(birthDate);
if(deathDate == null)
died = null;
else
died = new Date(deathDate);
}
else
{
System.out.println("inconsistent dates. aborting.");
System.exit(0);
}
}
public String toString()
{
String diedString;
if(died == null)
diedString="";//empty string
else
diedString = died.toString();
return (name+","+born+"-"+diedString);
}
public boolean equals(Person otherPerson)
{
if(otherPerson == null)
return false;
else
return(name.equals(otherPerson.name)
&&born.equals(otherPerson.born)
&& datesMatch(died, otherPerson.died));
}
private static boolean datesMatch(Date date1, Date date2)
{
if(date1 == null)
return(date2 == null);
else if(date2 == null)//&& date1 !=null
return false;
else // both dates are not null
return(date1.equals(date2));
}
public void setBirthDate(Date newDate)
{
if(consistent(newDate, died))
born = new Date(newDate);
else
{
System.out.println("inconsistentdates. aborting");
System.exit(0);
}
}
public void setDeathDate(Date newDate)
{
if(!consistent(born, newDate))
{
System.out.println("inconsistent dates. aborting");
System.exit(0);
}
if(newDate == null)
died = null;
else
died = new Date(newDate);
}
public void setName(String newName)
{
name = newName;
}
public void setBirthYear(int newYear)
{
if (born == null)
{
System.out.println("fata;Error.Aborting");
System.exit(0);
}
born.setYear(newYear);
if(!consistent(born, died))
{
System.out.println("inconsistent dates. Aborting");
System.exit(0);
}
}
public void setDeathYear(int newYear)
{
if (died == null)
{
System.out.println("fata; Error.aboring");
System.exit(0);
}
died.setYear(newYear);
if(!consistent(born, died))
{
System.out.println("inconsistent dates. aborting");
System.exit(0);
}
}
Public String getName()
{
return name;
}
Public Date Person()
{
return new Date(born);
}
public Date getDeathDate()
{
if(died == null)
return null;
else
return new Date(died);
}
private static boolean consistent(Date birthDate, Date deathDate)
{
if (birthDate == null)
return false;
else if (deathDate == null)
return true;
else
return(birthDate.precedes(deathDate)|| birthDate.equals(deathDate));
}
}
Explanation / Answer
Hi, Please find the updated code with required changes.
1. Java Util Date always takes the long as the parameter, will consider that as time in milli sec.
2. public key word should start with lower case "p" instead of upper case @ methods
public String getName() {
return name;
}
public Date Person() {
return new Date(born.getTime());
}
===================
import java.util.Date;
/**
*
* @author coleen
*/
public class Person {
private String name;
private Date born;
private Date died;// null indicates still alive
{
System.out.println("ITMP 2650 Java Programming summer 2017");
System.out.println("author: Coleen Feador");
System.out.println("Assignment: Chapter 5 question 9");
}
public Person(String initialName, Date birthDate, Date deathDate,
Date born, Date died) {
if (consistent(birthDate, deathDate)) {
name = initialName;
born = new Date(birthDate.getTime());
if (deathDate == null)
died = null;
else
died = new Date(deathDate.getTime());
} else {
System.out.println("Inconsistent dates. aborting");
System.exit(0);
}
}
public Person(Person original) {
if (original == null) {
System.out.println("Fatal error");
System.exit(0);
}
name = original.name;
born = new Date(original.born.getTime());
if (original.died == null)
died = null;
else
died = new Date(original.died.getTime());
}
public void set(String newName, Date birthDate, Date deathDate) {
if (consistent(birthDate, deathDate)) {
name = newName;
born = new Date(birthDate.getTime());
if (deathDate == null)
died = null;
else
died = new Date(deathDate.getTime());
} else {
System.out.println("inconsistent dates. aborting.");
System.exit(0);
}
}
public String toString() {
String diedString;
if (died == null)
diedString = "";// empty string
else
diedString = died.toString();
return (name + "," + born + "-" + diedString);
}
public boolean equals(Person otherPerson) {
if (otherPerson == null)
return false;
else
return (name.equals(otherPerson.name)
&& born.equals(otherPerson.born) && datesMatch(died,
otherPerson.died));
}
private static boolean datesMatch(Date date1, Date date2) {
if (date1 == null)
return (date2 == null);
else if (date2 == null)// && date1 !=null
return false;
else
// both dates are not null
return (date1.equals(date2));
}
public void setBirthDate(Date newDate) {
if (consistent(newDate, died))
born = new Date(newDate.getTime());
else {
System.out.println("inconsistentdates. aborting");
System.exit(0);
}
}
public void setDeathDate(Date newDate) {
if (!consistent(born, newDate)) {
System.out.println("inconsistent dates. aborting");
System.exit(0);
}
if (newDate == null)
died = null;
else
died = new Date(newDate.getTime());
}
public void setName(String newName) {
name = newName;
}
public void setBirthYear(int newYear) {
if (born == null) {
System.out.println("fata;Error.Aborting");
System.exit(0);
}
born.setYear(newYear);
if (!consistent(born, died)) {
System.out.println("inconsistent dates. Aborting");
System.exit(0);
}
}
public void setDeathYear(int newYear) {
if (died == null) {
System.out.println("fata; Error.aboring");
System.exit(0);
}
died.setYear(newYear);
if (!consistent(born, died)) {
System.out.println("inconsistent dates. aborting");
System.exit(0);
}
}
public String getName() {
return name;
}
public Date Person() {
return new Date(born.getTime());
}
public Date getDeathDate() {
if (died == null)
return null;
else
return new Date(died.getTime());
}
private static boolean consistent(Date birthDate, Date deathDate) {
if (birthDate == null)
return false;
else if (deathDate == null)
return true;
else
return (birthDate.before(deathDate) || birthDate.equals(deathDate));
}
}