Can someone please help complete this code in java. This is the assignment: Deve
ID: 3623641 • Letter: C
Question
Can someone please help complete this code in java. This is the assignment:Develop a program to maintain a list of homework assignments. When an assignment is assigned, add it to the list, and when it is completed, remove it. you should keep track of the due date. Your program should provide the following services:
- Add a new assignment
- Remove an assignment
- Provide a list of the assignments in the order they were assigned.
- Find the assignment(s) with the earliest due date.
Whoever can completed it the fastest, I will post this question again so you can get more karma points.
Thanks alot
Explanation / Answer
I've provided the basic classes and methods that you'll need, and a "main" method that tests them out. I wasn't sure if your problem called for providing the user with a menu for entering and retrieving assignments; if it does I've left that part for you to finish.
--------------
AssignmentList.java:
import java.text.*;
import java.util.*;
public class AssignmentList {
// List of the assignments sorted by due date, earliest to latest
private List<Assignment> data = new ArrayList<Assignment>();
public void add(Assignment a) {
for (int i=0; i<data.size(); i++) {
if (a.earlierThan(data.get(i))) {
data.add(i,a);
return;
}
}
// there weren't any assignments later than a,
// so add it at the end.
data.add(a);
}
public void remove(Assignment a) {
data.remove(a);
}
public List<Assignment> list() {
return data;
}
public Assignment firstAssignmentDue() {
return data.get(0);
}
public static void main(String[] args) throws Exception {
AssignmentList l = new AssignmentList();
DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
Assignment first = new Assignment("hockey",df.parse("2/21/2011"));
l.add(new Assignment("news",df.parse("02/28/11")));
l.add(first);
l.add(new Assignment("ridicule",df.parse("03/01/11")));
l.add(new Assignment("impetus",df.parse("02/27/11")));
l.remove(first);
System.out.println("Earliest assignment is: "+l.firstAssignmentDue());
System.out.println("The assignments in order are: ");
for (Assignment a : l.list()) {
System.out.println(a);
}
}
}
----------------------------------------
Assignment.java
import java.util.*;
public class Assignment {
private String description;
private Date dueDate;
public Assignment(String description, Date dueDate) {
this.description = description;
this.dueDate = dueDate;
}
public boolean earlierThan(Assignment a) {
return dueDate.before(a.dueDate);
}
public String toString() {
return description;
}
}