Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

HELP! I NEED THIS WRITTEN IN JAVA!! Part II. Use Linked List in Java APl to Mana

ID: 3756414 • Letter: H

Question

HELP! I NEED THIS WRITTEN IN JAVA!!

Part II. Use Linked List in Java APl to Manage Course Assignments Write Java programs to maintain a linked list of assignments in the courses taken by a student Assignments for different courses are stored in the same linked list. When an assignment is given, add it to the linked list. When an assignment is completed, remove it from the linked list. You need to keep track of the due date of each assignment. Each assignment need to have at least these data items: course id like cis2 168, assignment name like assign#1, due date like 10/5/2018 Your program must provide these services to the user: Add a new assignment. (Hint: append to the linked list) Remove an assignment after it is completed Provide a list of the assignments in the order they were assigned. (Hint: dump all items in the linked list) Find the assignment(s) with the earliest due date and display its(their) information. NOTE: the assignment that is given first may not have the earliest due date. So you have to go through the list and find the assignment(s) with the earliest due date. Assignments in different courses may have the same due date Hints: you need to find the earliest due date first, then find all assignments with this date and print their information. Show a menu to the user, listing the above list of operations and Quit option. After the use makes a selection, your program acts accordingly. You can use text menu or GUI menu Coding REQUIREMENTS/HINTS You must use java.util.LinkedList class for the linked list. You must use java.util.Date class for the due date. You DON'T NEED TO TRACK DUE TIMES. You must write a Java class called Assignment to represent each assignment. Define at lease these data fields for course id, assignment name, due date. Add a constructor and a getter and setter method for each data field. Optionally you can add a toString) method You must write a Java application class that contains a main() method. This class can be called like ManageAssignments. This class does the actual management of assignments. In this class, first create a linked list of Assignments. Then add a menu and handle the menu using a branching statement like switch/if-else-if. Then add the code to handle each option

Explanation / Answer

assignment.java

package task;

import java.util.Date;


public class assignment {
  
String course_id,assignment_name;
Date due_date;
  
public assignment(String course_id,String assignment_name,Date due_date)
{
this.course_id=course_id;
this.assignment_name=assignment_name;
this.due_date=due_date;
}

public String getCourse_id() {
return course_id;
}

public void setCourse_id(String course_id) {
this.course_id = course_id;
}

public String getAssignment_name() {
return assignment_name;
}

public void setAssignment_name(String assignment_name) {
this.assignment_name = assignment_name;
}

public Date getDue_date() {
return due_date;
}

public void setDue_date(Date due_date) {
this.due_date = due_date;
}
  
  
}

============================================================================

Task.java


package task;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.LinkedList;
import java.util.Scanner;


public class Task {

String course_id,assignment_name;
Date due_date;
LinkedList<assignment> l = new LinkedList<assignment>();

  
public void add() throws ParseException
{
Scanner sc = new Scanner(System.in);
String mydate;
  
System.out.println("Please enter course id:");
course_id=sc.nextLine();
  
System.out.println("Please enter assignment name:");
assignment_name=sc.nextLine();
  
System.out.println("Please enter due date:");
mydate=sc.nextLine();
due_date = new SimpleDateFormat("dd/MM/yyyy").parse(mydate);
  
l.add(new assignment(course_id,assignment_name,due_date));
  
}
  
public void remove()
{

String my_assignment_name;
  
System.out.println("Please enter the assignment name of the assignment that you want to remove:");
Scanner sc = new Scanner(System.in);
my_assignment_name=sc.nextLine();
  
for(assignment a:l)
{
if(a.assignment_name.equals(my_assignment_name))
{
l.remove(a);
break;
}
}
  
System.out.println("The assignment with assignment name " + my_assignment_name + " has been removed");
}
  
public void show()
{
System.out.println(" ");
for(assignment a:l)
{
System.out.println("Course id:" + a.course_id);
System.out.println("Assignment name:" + a.assignment_name);
System.out.println("Due date:" + a.due_date);
System.out.println(" ");
}
}
  
public void earliest()
{
  
Date current_date=new Date();
  
for(assignment a:l)
{
current_date=a.due_date;
break;
}
  
for(assignment a:l)
{
if(a.due_date.compareTo(current_date)<0)
{
current_date=a.due_date;
}
}
  
System.out.println("The assignments with earliest due dates");
for(assignment a:l)
{
if(a.due_date.compareTo(current_date)==0)
{
System.out.println(" ");
System.out.println("Course id:" + a.course_id);
System.out.println("Assignment name:" + a.assignment_name);
System.out.println("Due date:" + a.due_date);
}
}
}

public static void main(String[] args) throws ParseException {
  
int choice;
Task t = new Task();
  
  
do
{
  
System.out.println("Please choose any one of the following:");
System.out.println("1. Add a new assignment");
System.out.println("2. Remove an assignment");
System.out.println("3. List of the assignments in order they were assigned");
System.out.println("4. Assignment with the latest due date");
System.out.println("5. quit");
  
System.out.println("Your choice:");
Scanner sc = new Scanner(System.in);
choice=sc.nextInt();
  
switch(choice)
{
case 1:
t.add();
break;
  
case 2:
t.remove();
break;
  
case 3:
t.show();
break;
  
case 4:
t.earliest();
break;
  
default:
System.out.println("Invalid choice");
}
System.out.println("=====================================================");
}while(choice<=4);
}
  
}

============================================================================

Output:

run:
Please choose any one of the following:
1. Add a new assignment
2. Remove an assignment
3. List of the assignments in order they were assigned
4. Assignment with the latest due date
5. quit
Your choice:
1
Please enter course id:
cs123
Please enter assignment name:
as345
Please enter due date:
25/10/2018
=====================================================
Please choose any one of the following:
1. Add a new assignment
2. Remove an assignment
3. List of the assignments in order they were assigned
4. Assignment with the latest due date
5. quit
Your choice:
1
Please enter course id:
rs444
Please enter assignment name:
ww234
Please enter due date:
12/10/2018
=====================================================
Please choose any one of the following:
1. Add a new assignment
2. Remove an assignment
3. List of the assignments in order they were assigned
4. Assignment with the latest due date
5. quit
Your choice:
1
Please enter course id:
rr445
Please enter assignment name:
ee456
Please enter due date:
12/10/2018
=====================================================
Please choose any one of the following:
1. Add a new assignment
2. Remove an assignment
3. List of the assignments in order they were assigned
4. Assignment with the latest due date
5. quit
Your choice:
1
Please enter course id:
hh345
Please enter assignment name:
yy546
Please enter due date:
15/10/2018
=====================================================
Please choose any one of the following:
1. Add a new assignment
2. Remove an assignment
3. List of the assignments in order they were assigned
4. Assignment with the latest due date
5. quit
Your choice:
1
Please enter course id:
uu777
Please enter assignment name:
we234
Please enter due date:
20/10/2018
=====================================================
Please choose any one of the following:
1. Add a new assignment
2. Remove an assignment
3. List of the assignments in order they were assigned
4. Assignment with the latest due date
5. quit
Your choice:
3
  
Course id:cs123
Assignment name:as345
Due date:Thu Oct 25 00:00:00 IST 2018

Course id:rs444
Assignment name:ww234
Due date:Fri Oct 12 00:00:00 IST 2018

Course id:rr445
Assignment name:ee456
Due date:Fri Oct 12 00:00:00 IST 2018

Course id:hh345
Assignment name:yy546
Due date:Mon Oct 15 00:00:00 IST 2018

Course id:uu777
Assignment name:we234
Due date:Sat Oct 20 00:00:00 IST 2018

=====================================================
Please choose any one of the following:
1. Add a new assignment
2. Remove an assignment
3. List of the assignments in order they were assigned
4. Assignment with the latest due date
5. quit
Your choice:
2
Please enter the assignment name of the assignment that you want to remove:
we234
The assignment with assignment name we234 has been removed
=====================================================
Please choose any one of the following:
1. Add a new assignment
2. Remove an assignment
3. List of the assignments in order they were assigned
4. Assignment with the latest due date
5. quit
Your choice:
3
  
Course id:cs123
Assignment name:as345
Due date:Thu Oct 25 00:00:00 IST 2018

Course id:rs444
Assignment name:ww234
Due date:Fri Oct 12 00:00:00 IST 2018

Course id:rr445
Assignment name:ee456
Due date:Fri Oct 12 00:00:00 IST 2018

Course id:hh345
Assignment name:yy546
Due date:Mon Oct 15 00:00:00 IST 2018

=====================================================
Please choose any one of the following:
1. Add a new assignment
2. Remove an assignment
3. List of the assignments in order they were assigned
4. Assignment with the latest due date
5. quit
Your choice:
4
The assignments with earliest due dates
  
Course id:rs444
Assignment name:ww234
Due date:Fri Oct 12 00:00:00 IST 2018
  
Course id:rr445
Assignment name:ee456
Due date:Fri Oct 12 00:00:00 IST 2018
=====================================================
Please choose any one of the following:
1. Add a new assignment
2. Remove an assignment
3. List of the assignments in order they were assigned
4. Assignment with the latest due date
5. quit
Your choice:
5
Invalid choice
=====================================================
BUILD SUCCESSFUL (total time: 2 minutes 27 seconds)

=============================================================================Description:

So there is a class: assignment. java.

This class holds the details of the assignment such as course_id, assignment_name and due date in the form of variables. I have added constructors as well as getters and setters to the class.

Now there is another class which contains the logic: task.java

The class has declared few variables course_id,assignment_name and due_date

It has created an object of the linked list.

LinkedList<assignment> l = new LinkedList<assignment>();

lets move through each functions:

1) main()

Main() shows the menu to the user, it takes the input from the user in the variable choice. and with the help of switch statements it is calling each function as per the user input. we are using do while loop here. so as soon as the user enters 5 or greater value the loop breaks and the program stops.

2) Add()

We need to add a new assignment to our existing list. for that we take input from the user for all course_id, assignment_name and due date. here date is inputed as a string then converted to date type as:

due_date = new SimpleDateFormat("dd/MM/yyyy").parse(mydate);

Then the data is added to the list object by creating and adding the data to the assignment class

l.add(new assignment(course_id,assignment_name,due_date));

(3) Remove()

Here it will ask the user the assignment name of the assignment that we need to remove. we are using for each loop here and when the assignment name of the element in the linked list is equal to the assignment name provided by the user, that element is removed.

(4) show()

Again we are using for each loop to print the details of each assignment on the screen.

(5)earliest()

here we need to find the assignment with the earliest due date. so we are creating a new date variable current_date and assigning it the 1st value of the date using for each loop.

then we are comparing the date of the current element in the linked list to the current date using compare_to funtion. if the function returns negative value that means the date in the linked list is earlier so the new curent_date is the date in the linked list.

again we are printing the details whose due date is earliest with the help of current date.