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

Need help CREATING COUPLE CLASS/ MODIFYING CLASS PERSON! Create a new class Coup

ID: 665220 • Letter: N

Question

Need help CREATING COUPLE CLASS/ MODIFYING CLASS PERSON!

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.

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);

A few notes:

Your __add__ method needs to be part of the Person class. First, create a class Couple that consists of two Person objects, Be sure to pass Person objects to the constructor. Then the __add__method should be added to the Person class that you have been using in the previous homework. That method should take 2 Person objects as arguments and return a Couple object.

So, you should be able to run:

aCouple = person1 + person2

print(aCouple1.person1.name + " " + aCouple.person2.name)

Remember: The __add__ method needs to go into the Person class. Adding two Persons must return a Couple.

Person class:

import java.util.*;

/** Danielle Macey
* Homework 3, editing person class
* *****
*
* We are imagining a web application that supports the updating and display of information for
* employees at a university. Please modify the Person class you created and create three classes as
* follows (You’ll probably want to create these in a file with the Person class you created in HW2):
*
*
*
* A class Employee that inherits from Person with the following functions

*   
*   
*   
* A constructor __init__(self, birthday, countryOfBirth, name, employeeId). The constructor
* should first call the constructor of the super class (we did an example of this in class). Then, the
* constructor initializes instance attribute self.employeeID to the value passed in to the
* constructor. Also, self.salary and self.yearsOfService should be set to zero initially.
*/
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

// 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;
}
}
  

}

ZELLER:

public class Zeller {
public int A_Month;
public int B_Day;
public int C_Year;
private int D_Century;
  
public Zeller()
{
this.A_Month= 0;
this.B_Day= 0;
this.C_Year= 0;
this.D_Century= 0;
}
  
  
public Zeller(int A_Month, int B_Day, int C_Year) {
if(A_Month == 1 || A_Month == 2){
this.A_Month = A_Month + 10;
}
else{
this.A_Month = A_Month -2;
}
this.B_Day = B_Day;
  
if(getA_Month()== 11 || getA_Month() == 12){
this.C_Year = (C_Year-1)%100;
}
else{
// modified*****
this.C_Year=C_Year;
}
  
this.D_Century = C_Year/100;
}

public int getA_Month() {
return A_Month;
}

public int getB_Day() {
return B_Day;
}

public int getC_Year() {
//rmodified so code spits year in format such as "2005"
return C_Year;
}
  
public int getD_Century(){
return C_Year/100;
}

public void setA_Month(int A) {
int TempA;
if(A == 1 || A == 2){
TempA = (A+10);
}
else{
TempA = (A -2);
}

this.A_Month = TempA;
}

public void setB_Day(int B) {
this.B_Day = B;
}

public void setC_Year(int C) {
int TempC = 0;
if(getA_Month()== 11 || getA_Month() == 12){
TempC = (C-1);
}
this.C_Year = TempC%100;
  
}
  
public void FindDayOfWeek(){
int D = this.D_Century;
int X = this.C_Year/4;
int W = (13*this.A_Month -1)/5;
int Y = this.D_Century/4;
  
int Z = (W+X+Y+this.B_Day+this.C_Year - 2 *D);
int R = Z%7;
if(R <0){
int TempR;
TempR = R + 7;
R = TempR;
}

if (R == 0){
System.out.print("The day of the week is Sunday");
}
else if(R== 1){
System.out.print("The day of the week is Monday");
}
else if(R== 2){
System.out.print("The day of the week is Tuesday");
}
else if(R== 3){
System.out.print("The day of the week is Wednesday");
}
else if(R== 4){
System.out.print("The day of the week is Thursday");
}


else if(R== 5){
System.out.print("The day of the week is Friday");
}
else if(R == 6){
System.out.print("The day of the week is Saturday");
}
}
}

Please do not copy paste my code. need help creating couple and modifying people!

Explanation / Answer


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

    // 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;
    }
}
public static void main (String args[])
{

    Person person1 = new Person("Danielle", 07, 04, 1999, "USA");
    Person person2 = new Person("Bob", 11, 05, 1987, "USA");
    person1.add(person1);

    System.out.println("test :        " + person2);
    }
}


public class Couple extends Person
{

private String personName1;
private String personName2;


public void add(Person p)
{
this.personName1="person 1";
this.personName2="person 2";
}

public static void main (String args[]){

    Person person1 = new Couple();
    Person person2 = new Couple();
    person1.add(person2);


}

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