Answers for "CodeHS java 9.5.7"

0

CodeHS java 9.5.7

//CodeHS AP Computer Science A Java, 9.5.7: Creating .equals
//DO NOT COPY AND PASTE, YOUR TEACHER CAN SEE YOUR EDIT HISTORY.
//Part 1/2

//PersonTester.java

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));
        
    }
}
Posted by: Guest on April-27-2021
0

CodeHS java 9.5.7

//CodeHS AP Computer Science A Java, 9.5.7: Creating .equals
//DO NOT COPY AND PASTE, YOUR TEACHER CAN SEE YOUR EDIT HISTORY.
//Part 2/2

//Person.java

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;
        }
    }
    
}
Posted by: Guest on April-27-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language