CodeHS java 9.5.7 code example
Example 1: CodeHS java 9.5.7
public class Person {
private String name;
private String birthday;
public Person (String name, String birthday)
{
this.name = name;
this.birthday = birthday;
}
public String getBirthday(){
return birthday;
}
public String getName(){
return name;
}
public boolean equals(Person person){
if(person.getName().equals(this.name) && person.getBirthday().equals(this.birthday)){
return true;
}else{
return false;
}
}
}
Example 2: CodeHS java 9.5.7
import java.util.Scanner;
public class PersonTester
{
public static void main(String[] args)
{
Scanner scanner = new Scanner(System.in);
System.out.print("Please enter the Person's name: ");
String tempName = scanner.nextLine();
System.out.print("Please enter the Person's birthday: ");
String tempBirthday = scanner.nextLine();
Person person = new Person(tempName, tempBirthday);
tempName = "";
tempBirthday = "";
System.out.print("Please enter the Student's name: ");
tempName = scanner.nextLine();
System.out.print("Please enter the Student's birthday: ");
tempBirthday = scanner.nextLine();
System.out.print("Please enter the Student's grade: ");
int tempGrade = scanner.nextInt();
Person student = new Student(tempName, tempBirthday, tempGrade);
System.out.println(person.equals(student));
}
}