Part 2: Sorting the WorkOrders via dates Another error that will still be showing is that there is not Comparable/compareTo() method setup on the WorkOrder class file. That is something you need to fix and code. Implement the use of the Comparable interface and add the compareTo() method to the WorkOrder class. The compareTo() method will take a little work here. We are going to compare via the date of the work order. The dates of the WorkOrder are saved in a MM-DD-YYYY format. There is a dash '-' in between each part of the date. You will need to split both the current object's date and the date sent through the compareTo() parameters. You will have three things to compare against. You first need to check the year. If the years are the same value then you need to go another step to check the months, otherwise you compare them with less than or greater than and return the corresponding value. If you have to check the months it would be the same for years. If the months are the same you go another step to check the days. Otherwise you compare the months and return the value depending on which is less than. Lastly if you get to the days you can do a simple compare and return the -1, 0 or 1 as there are no further steps to check. Example: When you look at the following date what do you do?  Well you compare the years, they are both 2024, so you can't base it off that, You have to then go and check the months. One is 02 and the other is 03. So you can stop there and return a 1 since the other date is ahead of the current. Current object date: 02-13-2024Date sent in the method parameter:  03-13-2024 Use whatever method you want. Remember that these are in String format, so you could try the compareTo() on String but what happens if the date is 09 for month, does it compare that correctly.  Otherwise think about parsing the data to ints and compare the values that way.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Part 2: Sorting the WorkOrders via dates

Another error that will still be showing is that there is not Comparable/compareTo() method setup on the WorkOrder class file. That is something you need to fix and code. Implement the use of the Comparable interface and add the compareTo() method to the WorkOrder class.

The compareTo() method will take a little work here. We are going to compare via the date of the work order. The dates of the WorkOrder are saved in a MM-DD-YYYY format. There is a dash '-' in between each part of the date. You will need to split both the current object's date and the date sent through the compareTo() parameters.

You will have three things to compare against. You first need to check the year. If the years are the same value then you need to go another step to check the months, otherwise you compare them with less than or greater than and return the corresponding value. If you have to check the months it would be the same for years. If the months are the same you go another step to check the days. Otherwise you compare the months and return the value depending on which is less than. Lastly if you get to the days you can do a simple compare and return the -1, 0 or 1 as there are no further steps to check.

Example:

When you look at the following date what do you do?  Well you compare the years, they are both 2024, so you can't base it off that, You have to then go and check the months. One is 02 and the other is 03. So you can stop there and return a 1 since the other date is ahead of the current.

Current object date: 02-13-2024
Date sent in the method parameter:  03-13-2024

Use whatever method you want. Remember that these are in String format, so you could try the compareTo() on String but what happens if the date is 09 for month, does it compare that correctly.  Otherwise think about parsing the data to ints and compare the values that way.

Expert Solution
steps

Step by step

Solved in 5 steps

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education