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

Java Class person help? Can someone please help me? I\'m struggling. Create a cl

ID: 664541 • Letter: J

Question

Java Class person help?

Can someone please help me? I'm struggling.

Create a class Person as follows:

A class attribute validCountries that is a dictionary of valid countries with 2 values “USA”, CANADA” and their corresponding drinking ages: 21 for USA, 19 for Canada

A constructor which takes 3 parameters (in addition to self):

1. birthday (Datetime)

2. countryOfBirth (String)

3. name (String)

Remember to initialize all instance attributes in the constructor. The instance attributes in this case would be self.birthday, self.country, self.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. This is an example of encapsulation. You will need to get the parameters A-D by manipulating the self.birthday date into separate values for month, day, year and century. First get a String value for the date using the strftime method in Python. Remember – Google is your friend.

Java: 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”) . An instance method isOldEnoughToDrink() that returns true if the person is old enough to drink in their country of birth (false otherwise). Basically, within this method you will simply call the method isOldEnoughToDrink(country) where country is the this.country instance attribute. This is an example of method overloading.

Here is my code for zeller(you will need to call this)


/**
*
* Danielle Macey
* Exercise 1, Homework 1
*
*
* Zeller’s algorithm computes the day of the week on which a given date will fall (or fell).
In this exercise, you will write a function to run Zeller’s algorithm on a specific date. The
program should use the algorithm outlined below to compute the day of the week on
which the user’s birthday fell in the year you were born and print the result to the
screen.
*
*
*
*/
public class Zeller {
public int A_Month;
public int B_Day;
public int C_Year;
private int D_Century;

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{
this.C_Year = C_Year%100;
}
  
this.D_Century = C_Year/100;
}

public int getA_Month() {
return A_Month;
}

public int getB_Day() {
return B_Day;
}

public int getC_Year() {
return C_Year%100;
}
  
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");
}
}
}

Explanation / Answer

private int age;
private String firstName;
private string lastName;

the class needs a constructor;

public Person(String_firstName, String_lastName, int_age)

that assigns values to the private instance variables. The class should also include public methods;

public void printName() - prints the persons name
public void printAge()
public void printAgeGroup(c

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