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

Need help in JAVA Create a new class Couple which is composed of two Person obje

ID: 665102 • Letter: N

Question

Need help in JAVA

Create a new class Couple which is composed of two Person objects. The constructor, __init__(self, person1, person2) should take 2 Person objects as arguments. It should then set to instance attributes self.person1 & self.person2 to the values passed in to the constructor. In Python, Overload the + operator for the Person class by defining a new instance method, __add__(self, other) that joins 2 Person objects and returns a new couple object

. As a test this method should also print out a concatenation of self.name and other.name

For Java, rather than overloading the + operator, just define the method add(Person p) as part of the person class, so the following could be called: Person person1 = new Person(…); Person person2 = new Person(…); person1.add(person2);

my person classs:

class Person extends Zeller

{

private String countryOfBirth;
private String name;

/**
* Remember to initialize all instance attributes in the constructor. The instance attributes in this case
* would be self.birthday, self.country, self.name (this in java)
*/
public Person()
{
this.countryOfBirth="unknown";
this.name=" john smith ";

}
  
  
public Person(String name, int A_Month, int B_Day, int C_Year, String countryOfBirth)
{ super ( A_Month, B_Day, C_Year);
  
this.countryOfBirth=countryOfBirth;
this.name=name;
  

}


/**
* ************Add a function getIDCardString(self) to the Person class that simply returns a string concatenation of
the self. name and self.birthday instance attributes. This is to be used on ID cards for all people
students, faculty, staff and alumni).
*/
public String getIDCardString()
{
return "ID CARD: " + this.name + " Birthdate " + getA_Month()+"/"+ getB_Day()+"/"+ getC_Year();
}

/**
* Name
*/
public void setname(String name)
{
this.name=name;

}

public String getname()
{ return this.name;
}

/**
* An instance method bornOnDay(self) that takes no parameters but simply calls the zeller(A,B,C,D)
* method that you created in HW1. You can just include the zeller method in this Person class or import it.
* bornOnDay(self) should return the string returned from zeller.

*/public String bornOnDay()
{
return getA_Month()+"/"+getB_Day()+"/"+getC_Year();
}

/**
* An instance method isOldEnoughToDrink(country) that takes a string parameter country. This will return
true if the person is eligible to drink in the country passed to the method, false otherwise. In your
example please pass into the method a value from the class attribute validCountries to ensure that we
do not use invalid values (For example “US” instead of “USA”) .

*/public boolean isOldEnoughToDrink(String countryOfBirth)
{
Calendar cal=Calendar.getInstance(TimeZone.getDefault()); //current year
Zeller dt2=new Zeller(cal.get(Calendar.MONTH),cal.get(Calendar.DAY_OF_MONTH),cal.get(Calendar.YEAR));
int yrs=dt2.getC_Year()-getC_Year(); //get difference

// current date is going by ZELLER ALGORYTHM*** (-2 for month!!).. still makes sense though.... so keeping it...

// check conditions

if(yrs>=21 && countryOfBirth.equals("USA"))
return true;

else if(yrs>=19 && countryOfBirth.equals("CANADA"))
return true;
else
return false; //otherwise return false
}

/**
* In your example please pass into the method a value from the class attribute validCountries to ensure that we
do not use invalid values (For example “US” instead of “USA”) .
*/
public boolean validCountries(String countryOfBirth)
{
if(countryOfBirth.equals("USA") || countryOfBirth.equals("CANADA"))
return true;
else {

System.out.println("Not a valid country");
return false;
}}


}

Explanation / Answer

my person classs:

class Person extends Zeller

{

private String countryOfBirth;
private String name;

/**
* Remember to initialize all instance attributes in the constructor. The instance attributes in this case
* would be self.birthday, self.country, self.name (this in java)
*/
public Person()
{
this.countryOfBirth="unknown";
this.name=" john smith ";

}
  
  
public Person(String name, int A_Month, int B_Day, int C_Year, String countryOfBirth)
{ super ( A_Month, B_Day, C_Year);
  
this.countryOfBirth=countryOfBirth;
this.name=name;
  

}


/**
* ************Add a function getIDCardString(self) to the Person class that simply returns a string concatenation of
the self. name and self.birthday instance attributes. This is to be used on ID cards for all people
students, faculty, staff and alumni).
*/
public String getIDCardString()
{
return "ID CARD: " + this.name + " Birthdate " + getA_Month()+"/"+ getB_Day()+"/"+ getC_Year();
}

/**
* Name
*/
public void setname(String name)
{
this.name=name;

}

public String getname()
{ return this.name;
}

/**
* An instance method bornOnDay(self) that takes no parameters but simply calls the zeller(A,B,C,D)
* method that you created in HW1. You can just include the zeller method in this Person class or import it.
* bornOnDay(self) should return the string returned from zeller.

*/public String bornOnDay()
{
return getA_Month()+"/"+getB_Day()+"/"+getC_Year();
}

/**
* An instance method isOldEnoughToDrink(country) that takes a string parameter country. This will return
true if the person is eligible to drink in the country passed to the method, false otherwise. In your
example please pass into the method a value from the class attribute validCountries to ensure that we
do not use invalid values (For example “US” instead of “USA”) .

*/public boolean isOldEnoughToDrink(String countryOfBirth)
{
Calendar cal=Calendar.getInstance(TimeZone.getDefault()); //current year
Zeller dt2=new Zeller(cal.get(Calendar.MONTH),cal.get(Calendar.DAY_OF_MONTH),cal.get(Calendar.YEAR));
int yrs=dt2.getC_Year()-getC_Year(); //get difference

// current date is going by ZELLER ALGORYTHM*** (-2 for month!!).. still makes sense though.... so keeping it...

// check conditions

if(yrs>=21 && countryOfBirth.equals("USA"))
return true;

else if(yrs>=19 && countryOfBirth.equals("CANADA"))
return true;
else
return false; //otherwise return false
}

/**
* In your example please pass into the method a value from the class attribute validCountries to ensure that we
do not use invalid values (For example “US” instead of “USA”) .
*/
public boolean validCountries(String countryOfBirth)
{
if(countryOfBirth.equals("USA") || countryOfBirth.equals("CANADA"))
return true;
else {

System.out.println("Not a valid country");
return false;
}}


}

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