Question

Implement hashcode and equals method in java import java.util.*; public class Student { private int id; private String firstName, lastName; private boolean paidFees; public Student(int id, String firstName, String lastName, boolean paidFees) { this.id = id; this.firstName = firstName; this.lastName = lastName; this.paidFees = paidFees; } public int getId() { return id; } public String getFirstName() { return firstName; } public String getLastName() { return lastName; } public boolean hasPaidFees() { return paidFees; } public String toString() { return firstName + " " + lastName + " (ID: " + id + ")" + ( paidFees ? "" : " (Fees Owed)"); } // TODO: Implement the equals() method // this is an equals method // two students are equal if they have the same id, first name, last name and paidFees // IGNORE CASE for first name and last name @Override public boolean equals(Object obj) { return false; } // TODO: Implement the hashCode() method // this is an hashcode method, check the slides and the book for more information and requirements // REMINDER: the hashcode method must follow the following rules: // Symmetry: if a.equals(b) is true then b.equals(a) must be true // Reflexivity: a.equals(a) must be true // Transitivity: if a.equals(b) is true and b.equals(c) is true then a.equals(c) must be true // Consistency: multiple calls of a.equals(b) must return the same value @Override public int hashCode() { return 0; } }

          Implement hashcode and equals method in java
import java.util.*;
public class Student {
   
   private int id;
   private String firstName, lastName;
   private boolean paidFees;
   
   public Student(int id, String firstName, String lastName, boolean paidFees) {
      this.id = id;
      this.firstName = firstName;
      this.lastName = lastName;
      this.paidFees = paidFees;
   }
   public int getId() {
      return id;
   }
   
   public String getFirstName() {
      return firstName;
   }
   public String getLastName() {
      return lastName;
   }
   public boolean hasPaidFees() {
      return paidFees;
   }
   public String toString() {
      return firstName + " " + lastName + " (ID: " + id + ")" + ( paidFees ? "" : " (Fees Owed)");
   }
   // TODO: Implement the equals() method
   // this is an equals method
   // two students are equal if they have the same id, first name, last name and paidFees
   // IGNORE CASE for first name and last name
   @Override
   public boolean equals(Object obj) {
      return false;
      
   }
   
   // TODO: Implement the hashCode() method
   // this is an hashcode method, check the slides and the book for more information and requirements
   // REMINDER: the hashcode method must follow the following rules:
   // Symmetry: if a.equals(b) is true then b.equals(a) must be true
   // Reflexivity: a.equals(a) must be true
   // Transitivity: if a.equals(b) is true and b.equals(c) is true then a.equals(c) must be true
   // Consistency: multiple calls of a.equals(b) must return the same value
   @Override
   public int hashCode() {
      
      
      return 0;
   }
}
        
Show more…

Added by Tina C.

Computer Science and Information Technology
Computer Science and Information Technology
Trishna Knowledge Systems 2018 Edition
AceChat toggle button
Close icon
Ace pointing down

Please give Ace some feedback

Your feedback will help us improve your experience

Thumb up icon Thumb down icon
Thanks for your feedback!
Profile picture
Implement hashcode and equals method in java import java.util.*; public class Student { private int id; private String firstName, lastName; private boolean paidFees; public Student(int id, String firstName, String lastName, boolean paidFees) { this.id = id; this.firstName = firstName; this.lastName = lastName; this.paidFees = paidFees; } public int getId() { return id; } public String getFirstName() { return firstName; } public String getLastName() { return lastName; } public boolean hasPaidFees() { return paidFees; } public String toString() { return firstName + " " + lastName + " (ID: " + id + ")" + ( paidFees ? "" : " (Fees Owed)"); } // TODO: Implement the equals() method // this is an equals method // two students are equal if they have the same id, first name, last name and paidFees // IGNORE CASE for first name and last name @Override public boolean equals(Object obj) { return false; } // TODO: Implement the hashCode() method // this is an hashcode method, check the slides and the book for more information and requirements // REMINDER: the hashcode method must follow the following rules: // Symmetry: if a.equals(b) is true then b.equals(a) must be true // Reflexivity: a.equals(a) must be true // Transitivity: if a.equals(b) is true and b.equals(c) is true then a.equals(c) must be true // Consistency: multiple calls of a.equals(b) must return the same value @Override public int hashCode() { return 0; } }
Close icon
Play audio
Feedback
Powered by NumerAI
Ivan Kochetkov Kathleen Carty
Jennifer Stoner verified

Supreeta N and 101 other subject AP CS educators are ready to help you.

Ask a new question

*

Labs

-

Want to see this concept in action?

NEW

Explore this concept interactively to see how it behaves as you change inputs.

View Labs

*

Key Concepts

-
Key Concept
Premium Feature
Explore the core concept behind this problem.
Play button
Key Concept
Premium Feature
Explore the core concept behind this problem.
Your browser does not support the video tag.

*

Recommended Videos

-
construct-java-code-for-storing-a-college-database-using-an-appropriate-class-hierarchy-the-people-associated-with-the-college-are-generally-classified-as-students-or-employees-and-employees-48962

Construct Java code for storing a college database using an appropriate class hierarchy. The people associated with the college are generally classified as students or employees, and employees are further subdivided into faculty and staff. All people will have names and email addresses in the database. Write an appropriate abstract class Person that is a superclass of Student. Students have year (freshman, sophomore, junior, or senior), major (Computer Science, Mathematics, or English), and grade point average (0.0 to 4.0). Write appropriate accessor and mutator methods for displaying and modifying the data in both classes. The Dean of the college has decided that participation in band will be mandatory for all students. Students will be assigned instruments based on year: freshmen will play bells, sophomores will play trumpet, juniors will play baritone, and seniors will play tuba. Write code that will read the student database and create a new database that includes all student information (including instrument) except grade point average (a placeholder value such as 0 can be used instead, if needed). The new database should use a class that does not include mutator methods for changing anything except for the instrument, and your code should include a static method that displays the band roster. You may write a BandMember class that extends the Student class and overrides the mutator methods so that they are nonfunctional, or you may create a separate BandMember class that does not extend Student. Your code should create a student database and use it to create a new database of band members, then it should display the band roster, including name, email address, instrument, and major.

Supreeta N.

a-create-a-class-named-lease-with-fields-that-hold-an-apartment-tenants-name-apartment-number-monthly-rent-amount-and-term-of-the-lease-in-months-include-a-constructor-that-initializes-the-n-46522

a. Create a class named Lease with fields that hold an apartment tenant's name, apartment number, monthly rent amount, and term of the lease in months. Include a constructor that initializes the name to "XXX", the apartment number to 0, the rent to 1000, and the term to 12. Also include methods to get and set each of the fields. Include a non-static method named addPetFee() that adds $10 to the monthly rent value and calls a static method named explainPetPolicy() that explains the pet fee. Save the class as Lease.java. b. Create a class named TestLease whose main() method declares four Lease objects. Call a getData() method three times. Within the method, prompt a user for values for each field for a Lease, and return a Lease object to the main() method where it is assigned to one of main()'s Lease objects. Do not prompt the user for values for the fourth Lease object, but let it continue to hold the default values. Then, in main(), pass one of the Lease objects to a showValues() method that displays the data. Then call the addPetFee() method using the passed Lease object and confirm that the fee explanation statement is displayed. Next, call the showValues() method for the Lease object again and confirm that the pet fee has been added to the rent. Finally, call the showValues() method with each of the other three objects; confirm that two hold the values you supplied as input and one holds the constructor default values. Save the application as TestLease.java.

Willis J.

create-a-program-that-will-compare-two-names-the-program-prompts-the-user-to-enter-two-names-for-a-comparison-if-the-names-are-same-the-program-states-that-if-the-names-are-different-the-pro-59793

Create a program that will compare two names. The program prompts the user to enter two names for a comparison. If the names are the same, the program states that. If the names are different, the program converts both names to UPPERCASE and compares them again. If they are equal, the program displays a message stating that the names are equal if CASE is ignored. Otherwise, the program prints the names with a message that the names are not equal. HINT: Check also if there is a way to compare strings while ignoring case (upper or lower). Attach the JAVA file and the screenshot of the JAVA file running. Problem 2: Create a program that asks the user to enter three different names and then sorts and displays the names in ascending order. For example, if the names "Maria", "Kelley", and "Angie" were entered, the program will display: Names in sorted order are: FIRST: Angie SECOND: Kelley THIRD: Maria Use printf(...) method for your display.

Aarya B.


*

Recommended Textbooks

-
Computer Science and Information Technology

Computer Science and Information Technology

Trishna Knowledge Systems 2018 Edition
achievement 1,932 solutions
Introduction to Programming Using Python

Introduction to Programming Using Python

Y. Daniel Liang 1st Edition
achievement 1,899 solutions
Computer Science - An Overview

Computer Science - An Overview

Glenn Brookshear, Dennis Brylow 12th Edition
achievement 1,293 solutions

*

Transcript

-
00:01 Hello students, here is a java code that implementation for sorting a college database using a given class hierarchy.
00:11 So in this code you can see we are creating a first initially we create an abstract class called person.
00:19 So this is an abstract class, abstract class called as person with a student and the band members are the classes that extend it.
00:34 So the class student class i'll just show you here the class student class you can see a band member extends the student class.
00:44 The student class includes the additional fields and the methods specified to the students while the band members class extends the students and overrides and they overrides the memorandum for the methods to make them the non -functional.
01:04 So the college database the college database class contains the main method.
01:10 You can see the college database class it contains the main method where the student and the band member objects are created and the band roaster is displayed using the static method called the display band roast.
01:28 You can see here with the method called a display band roast.
01:32 So here in a main method this is our main class our main class of college database where you will you will just create the student database create create the student database database and like you next after that you will create you will create the band database band members database create band members members database database...
Need help? Use Ace
Ace is your personal tutor. It breaks down any question with clear steps so you can learn.
Start Using Ace
Ace is your personal tutor for learning
Step-by-step explanations
Instant summaries
Summarize YouTube videos
Understand textbook images or PDFs
Study tools like quizzes and flashcards
Listen to your notes as a podcast
Continue solving this problem
Create a free account to:
  • View full step-by-step solution
  • Ask follow-up questions with Ace AI
  • Save progress and study later
Continue Free
Join the community

18,000,000+

Students on Numerade


Trusted by students at 8,000+ universities

Numerade

Get step-by-step video solution
from top educators

Continue with Clever
or



By creating an account, you agree to the Terms of Service and Privacy Policy
Already have an account? Log In

A free answer
just for you

Watch the video solution with this free unlock.

Numerade

Log in to watch this video
...and 100,000,000 more!


EMAIL

PASSWORD

OR
Continue with Clever