Add an equals method to this class that returns true if the current Dog and passed Dog have the same name. The code should print false twice then true twice. Dog.java 1 public class Dog 2 { 3 private String name; 4 5 public Dog(String name) 6 { 7 this.name = name; 8 } 9 10 public boolean equals(Object other) 11 { 12 // ADD CODE HERE 13 } 14 15 public static void main(String[] args) 16 { 17 Dog d1 = new Dog("Rufus"); 18 Dog d2 = new Dog("Sally"); 19 Dog d3 = new Dog("Rufus"); CONSOLE SHELL
Added by Heather M.
Close
Step 1
We need to use the instanceof operator to check this. If the object is not a Dog, we should return false immediately. Show more…
Show all steps
Your feedback will help us improve your experience
Harriet O'Brien and 91 other AP CS educators are ready to help you.
Ask a new question
Labs
Want to see this concept in action?
Explore this concept interactively to see how it behaves as you change inputs.
Key Concepts
Recommended Videos
IN JAVA- Write a method named compare that accepts two String arrays as parameters and returns a boolean. The method should return true if both arrays contain the same values (case sensitive), otherwise returns false. Note - the two arrays must be the same length and the values must be in the same order to return true.
Oswaldo 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 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.
Title: Java Assignments - Working on IntelliJ In this assignment, you will be implementing a doubly linked list. You will write unit tests and use Git locally on your machine to make at least 12 commits with meaningful commit messages. Steps: 1. Create a new class named Album that implements Comparable. It should have a numerical ID, be able to store multiple artists' names, a title, and the number of songs on the album. 2. The toString method should return "ID: NUM_SONGS -- [ARTISTS NAMES]". 3. The compare method should compare only the number of songs. 4. This will be the class that we will use to test our linked list. 5. Implement the following functionality in your DLL (Doubly Linked List) and write unit tests in a separate file: - Empty constructor - append(data): Should run in O(1) time and return the appended node. - insert(location, data): Should insert at that point in the list (0 is the head, 1 is right after the head). Throw an IllegalArgumentException if the location is out of the bounds of the list. Return the inserted node. - delete(location): Delete the item at that location (delete 0 deletes the head). Throw an IllegalArgumentException if it doesn't exist. Return the deleted node. - getIndex(data): Return the first index of the item. Return -1 if it isn't in the list. - toString: Return a string representation of the items separated by "->" and terminate with "NULL". - shuffle(): Return the head of a shuffled list. Shuffling should take a list 1->2->3->4->5->6->NULL and return 2->1->4->3->6->5->NULL. - partition(data): This should return a new list that contains everything in the list that is greater than or equal to the given data. 6. Ensure that the unit tests cover all of the logic for each function. 7. Make sure that you have committed everything in Git. 8. Take a screenshot of the results of the "git status" command and the "git log" command.
Akash M.
Recommended Textbooks
Computer Science and Information Technology
Introduction to Programming Using Python
Computer Science - An Overview
18,000,000+
Students on Numerade
Trusted by students at 8,000+ universities
Watch the video solution with this free unlock.
EMAIL
PASSWORD