Question

(file ToDo.java) Add code for an equals method that checks the description of a ToDo item...

  1. (file ToDo.java) Add code for an equals method that checks the description of a ToDo item with a passed ToDo item’s description. The method should return true if they are identical and false if the descriptions are not identical.

public class Lab8Interfaces {

   /**
   * @param args
   * the command line arguments
   */
   public static void main(String[] args) {
       ToDoItem[] arr = new ToDoItem[5];
       ToDoItem toDo1 = new ToDoItem("Hospital Project");
       toDo1.setPriority(2);
       ToDoItem toDo2 = new ToDoItem("Meet Pat for lunch");
       toDo2.setPriority(Priority.LOW);
       ToDoItem toDo3 = new ToDoItem("Attend CS1 class");
       toDo3.setPriority(Priority.TOP);
       ToDoItem toDo4 = new ToDoItem("Finish English Paper");
       toDo4.setPriority(Priority.MEDIUM);
       ToDoItem toDo5 = new ToDoItem("Play Games");
       toDo4.setPriority(Priority.TOP);

       arr[0] = toDo1;
       arr[1] = toDo2;
       arr[2] = toDo3;
       arr[3] = toDo4;
       arr[4] = toDo5;
       for (ToDoItem t : arr)
           System.out.println(t);
   }

}

// Priority

/**
* Interface Priority.... 1 top priority 2 medium priority 3 least priority
*
* @author prof aw
*/
interface Priority {
   static final int TOP = 1;
   static final int MEDIUM = 2;
   static final int LOW = 3;

   /**
   * Sets the object's priority level.
   */
   public void setPriority(int value);

   /**
   * Returns the object's priority level.
   */
   public int getPriority();
}

// ToDoItem

class ToDoItem implements Priority {

   String description;
   private int priority;

   /**
   * Sets up this task with a medium priority level.
   *
   * @param taskName
   */
   public ToDoItem(String taskName) {
       description = taskName;
       priority = MEDIUM;
   }

   /**
   * Mutator: setDescription
   *
   */
   public void setDescription(String inDescription) {
       description = inDescription;
   }

   /**
   * Returns this ToDo item's description
   *
   * @return
   */
   String getDescription() {
       return description;
   }

   /**
   * Sets this ToDo item priority level.
   */
   public void setPriority(int value) {
       priority = value;
   }

   /**
   * Returns this ToDo item priority level.
   */
   public int getPriority() {
       return priority;
   }

   @Override
   public String toString() {
       return description + ": " + priority;
   }

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

interface Priority {
   static final int TOP = 1;
   static final int MEDIUM = 2;
   static final int LOW = 3;

   /**
   * Sets the object's priority level.
   */
   public void setPriority(int value);

   /**
   * Returns the object's priority level.
   */
   public int getPriority();
   }

   // ToDoItem

   class ToDoItem implements Priority {

   String description;
   private int priority;

   /**
   * Sets up this task with a medium priority level.
   *
   * @param taskName
   */
   public ToDoItem(String taskName) {
   description = taskName;
   priority = MEDIUM;
   }

   /**
   * Mutator: setDescription
   *
   */
   public void setDescription(String inDescription) {
   description = inDescription;
   }

   /**
   * Returns this ToDo item's description
   *
   * @return
   */
   String getDescription() {
   return description;
   }

   /**
   * Sets this ToDo item priority level.
   */
   public void setPriority(int value) {
   priority = value;
   }

   /**
   * Returns this ToDo item priority level.
   */
   public int getPriority() {
   return priority;
   }

   @Override
   public String toString() {
   return description + ": " + priority;
   }

   @Override
   public int hashCode() {
       final int prime = 31;
       int result = 1;
       result = prime * result + ((description == null) ? 0 : description.hashCode());
       return result;
   }

   @Override
   public boolean equals(Object obj) {
       if (this == obj)
           return true;
       if (obj == null)
           return false;
       if (getClass() != obj.getClass())
           return false;
       ToDoItem other = (ToDoItem) obj;
       if (description == null) {
           if (other.description != null)
               return false;
       } else if (!description.equals(other.description))
           return false;
       return true;
   }

   }

Add a comment
Know the answer?
Add Answer to:
(file ToDo.java) Add code for an equals method that checks the description of a ToDo item...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Priority Queue Demo import java.util.*; public class PriorityQueueDemo {    public static void main(String[] args) {...

    Priority Queue Demo import java.util.*; public class PriorityQueueDemo {    public static void main(String[] args) {        //TODO 1: Create a priority queue of Strings and assign it to variable queue1               //TODO 2: Add Oklahoma, Indiana, Georgia, Texas to queue1                      System.out.println("Priority queue using Comparable:");        //TODO 3: remove from queue1 all the strings one by one        // with the "smaller" strings (higher priority) ahead of "bigger"...

  • JAVA - Circular Doubly Linked List Does anybody could help me with this method below(previous)? public...

    JAVA - Circular Doubly Linked List Does anybody could help me with this method below(previous)? public E previous() { // Returns the previous Element return null; } Explanation: We have this class with these two implemented inferfaces: The interfaces are: package edu.ics211.h04; /** * Interface for a List211. * * @author Cam Moore * @param the generic type of the Lists. */ public interface IList211 { /** * Gets the item at the given index. * @param index the index....

  • Please help me to solve this source code. Use the following file: InterfaceRunner.java import java.util.ArrayList; public...

    Please help me to solve this source code. Use the following file: InterfaceRunner.java import java.util.ArrayList; public class InterfaceRunner { public static void main(String[] args) { ArrayList<GeometricSolid> shapes = new ArrayList<>(); shapes.add(new Sphere(10)); shapes.add(new Sphere(1)); shapes.add(new Cylinder(1, 5)); shapes.add(new Cylinder(10, 20)); shapes.add(new RightCircularCone(1, 5)); shapes.add(new RightCircularCone(10, 20)); /* * Notice that the array list holds different kinds of objects * but each one is a GeometricSolid because it implements * the interface. * */ for (GeometricSolid shape : shapes) { System.out.printf("%.2f%n",shape.volume());...

  • In a file named LLBag.java, write a class called LLBag that implements the Bag interface using...

    In a file named LLBag.java, write a class called LLBag that implements the Bag interface using a linked list instead of an array. You may use a linked list with or without a dummy head node. Bag interface code: /* * Bag.java * * Computer Science 112, Boston University */ /* * An interface for a Bag ADT. */ public interface Bag { /*    * adds the specified item to the Bag. Returns true on success    * and...

  • public class Item implements Comparable { private String name; private double price; /** * Constructor for...

    public class Item implements Comparable { private String name; private double price; /** * Constructor for objects of class Item * @param theName name of item * @param thePrice price of item */ public Item(String theName, double thePrice) { name = theName; price = thePrice; }    /** * gets the name * @return name name of item */ public String getName() { return name; }    /** * gets price of item * @return price price of item */...

  • In addition to the base files, three additional files are attached: EmptyCollectionException.java, LinearNode.java, and StackADT.java. These...

    In addition to the base files, three additional files are attached: EmptyCollectionException.java, LinearNode.java, and StackADT.java. These files will need to be added to your Java project. They provide data structure functionality that you will build over. It is suggested that you test if these files have been properly added to your project by confirming that Base_A05Q1.java compiles correctly. Complete the implementation of the ArrayStack class. Specifically, complete the implementations of the isEmpty, size, and toString methods. See Base_A05Q1.java for a...

  • PLEASE COMPLETE THE CODES. package javaprogram; import java.io.PrintStream; import java.util.ArrayList; import java.util.Scanner; /** * Movie class...

    PLEASE COMPLETE THE CODES. package javaprogram; import java.io.PrintStream; import java.util.ArrayList; import java.util.Scanner; /** * Movie class definition. * * @author David Brown * @version 2019-01-22 */ public class Movie implements Comparable { // Constants public static final int FIRST_YEAR = 1888; public static final String[] GENRES = { "science fiction", "fantasy", "drama", "romance", "comedy", "zombie", "action", "historical", "horror", "war" }; public static final int MAX_RATING = 10; public static final int MIN_RATING = 0; /** * Converts a string of...

  • Suppose there is a hospital with a waiting room filled with several patients. Patients are prioritized...

    Suppose there is a hospital with a waiting room filled with several patients. Patients are prioritized based on how severe their casualities are. For instance, car crash andgun shot patients are priority level 1, so they go straight to the front of the queue. Patients with heavy chest pain or mild heart attacks are priority level 2, and so on. Create a hospital that manages patients in a list. Implement it using the LinkedList API. (You may import ArrayList or...

  • I need to write a program in java that reads a text file with a list...

    I need to write a program in java that reads a text file with a list of numbers and sorts them from least to greatest. This is the starter file. import java.util.*; import java.io.*; public class Lab3 { static final int INITIAL_CAPACITY = 5; public static void main( String args[] ) throws Exception { // ALWAYS TEST FOR REQUIRED INPUT FILE NAME ON THE COMMAND LINE if (args.length < 1 ) { System.out.println("\nusage: C:\\> java Lab3 L3input.txt\n"); System.exit(0); } //...

  • In each of the following questions, first use NetBeans IDE to run the code (if there...

    In each of the following questions, first use NetBeans IDE to run the code (if there is an error fix it) then take a screenshot of the output and paste it under (A). In (B), justify the output you obtained in (A). - 9. Given the following: public class WorkingSheet {     public static void main(String[] args) {        B myB = new B();        A myA = new B();        System.out.print(myB instanceof A);        System.out.print(myB instanceof C);        System.out.print(myA...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT