Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help me create a sort due date from the soonest to the latest date in Java, Here is my code so far Assignment.class import

Please help me create a sort due date from the soonest to the latest date in Java,

Here is my code so far

Assignment.class

import java.time.LocalDate; import java.util.*; // ArrayList Assignment public class Assignments { public static ArrayList myAssignment = new ArrayList(); // sort due date soonest to latest public static void main(String[] args) { int i; int userOption = menu(); while (userOption != 5) { if (userOption == 1) { addAssignment(); } else if (userOption == 2) { int indexToRemove = 0; try { myAssignment.remove(indexToRemove); System.out.println("The assignment is removed!"); } catch (Exception e) { System.out.println("The assignment number you entered is invalid! please try again!"); } } else if (userOption == 3) // print assignment { for (i = 0; i < myAssignment.size(); i++) System.out.println(myAssignment.get(i).toString()); } else if (userOption == 4) { List assignA = new List(); List assignB = new List(); assignA = myAssignment.get(1); assignB = myAssignment.get(2); for(i = 0; i < myAssignment.size() -1; i++) { myAssignment.get(i).getDueDate().compareTo(assignA.getDueDate()); // return - 1 to 0 } } userOption = menu(); } } public static int menu() { Scanner key = new Scanner(System.in); int userOption; System.out.println("Please select an option"); System.out.println("1)Add Assignment"); System.out.println("2)Remove Assignment"); System.out.println("3)Display Assignment"); System.out.println("4)Sort Assignment Order(due first and last):"); System.out.println("5)Exit program"); userOption = key.nextInt(); while (userOption < 1 || userOption > 4) { System.out.println("Error please put 1 to 5"); userOption = key.nextInt(); } return userOption; } private static void addAssignment() { Scanner key = new Scanner(System.in); // add additional Assignment System.out.println("What Assignment would you like to add??"); String name = key.nextLine(); System.out.println("Enter Assignment name: "); String assignmentName = key.nextLine(); System.out.println("When is the Assignment due: (MM, DD, YYYY) "); int month, day, year; month = key.nextInt(); day = key.nextInt(); year = key.nextInt(); try { myAssignment.add(new List(name, assignmentName, LocalDate.of(year, month, day))); System.out.println("The assignment is added! Thank you "); } catch (Exception e) { System.out.println("Invalid day! please retry !"); addAssignment(); } } } List.class
import java.time.LocalDate; public class List { private String name; public static LocalDate dueDate; private String assignmentName; // declaring constructor public List(String name, String assignmentName , LocalDate dueDate){ this.name = name; this.assignmentName = assignmentName; this.dueDate = dueDate; } public List() { } public static List dueDate() { return dueDate(); } public String getAssignmentName(){ return assignmentName; } public void setName(String name) { this.name = name; } public String getName(){ return name; } public void setDueDate(LocalDate dueDate) { this.dueDate = dueDate; } public LocalDate getDueDate(){ return dueDate; } public String setAssignmentsName(String AssignmentName){ return AssignmentName; } public String toString(){ String AssignmentSummary = "Your assignment is " + name + " Assignment name: " + assignmentName + " It is due at: " + dueDate; return AssignmentSummary; } } 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

What is DDL?

Answered: 1 week ago