There is two java file todoitem and todolist: todoItm.java package com.charan; p
ID: 3569526 • Letter: T
Question
There is two java file todoitem and todolist:
todoItm.java
package com.charan;
public class TodoItem implements Comparable<TodoItem> {
private String item;
private int month,day, priority;
public TodoItem(String i, int m, int d, int p)
{
item = i;
month = m;
day = d;
priority = p;
}
public String getItem()
{
return item;
}
public void setItem(String i)
{
item = i;
}
public int getMonth()
{
return month;
}
public void setMonth(int m)
{
if (m < 1 || m > 12)
{
System.out.println("Invalid month: " + m);
return;
}
month = m;
}
public int getDay()
{
return day;
}
public void setDay(int d)
{
if (d < 1 || d > 31)
{
System.out.println("Invalid day: " + d);
return;
}
day = day;
}
public int getPriority()
{
return priority;
}
public void setPriority(int pr)
{
if (pr < 1 || pr > 5)
{
System.out.println("Invalid day: " + pr);
return;
}
priority = pr;
}
public int compareTo(TodoItem o)
{
if (priority != o.priority)
return priority - o.priority;
if (month != o.month)
return month - o.month;
return day - o.day;
}
public String toString()
{
return "Item: " + item + " Date: " + month + "-" +
day + " Priority: " + priority;
}
}
TodoLIst.java
package com.charan;
import java.util.ArrayList;
import java.util.Collections;
public class TodoList
{
private ArrayList<TodoItem> list = new ArrayList<TodoItem>();
public void addItem(String i, int m, int d, int p)
{
list.add(new TodoItem(i, m, d, p));
}
public void sortItems()
{
Collections.sort(list);
}
public String toString()
{
return list.toString();
}
}
Test2.java
package com.charan;
public class Test2 {
public static void main(String[] args)
{
TodoList list1 = new TodoList();
list1.addItem("test1", 2, 5, 2);
list1.addItem("test2", 4, 8, 2);
list1.addItem("test3",7, 9, 7 );
list1.sortItems();
System.out.println();
System.out.println(list1.toString());
TodoList list2 = new TodoList();
list2.addItem("test4", 7, 9, 7);
list2.addItem("test5", 3, 5, 3);
list2.addItem("test6", 3, 5, 1);
list2.sortItems();
System.out.println();
System.out.println(list2.toString());
TodoList list3 = new TodoList();
list3.addItem("test1", 7, 9, 7);
list3.addItem("test2", 2, 5, 3);
list3.addItem("test3", 7, 9, 7);
list3.addItem("test4", 6, 2, 1);
list3.sortItems();
System.out.println();
System.out.println(list3.toString());
}
}
Now answer the following questions:
a) Modify your TodoList class so that it can read in a file each which each line represents a to do list item (you can decide on the format for the file), and initialize an instance of TodoList with the information in the file.
b) Write a method that writes the TodoList instance to a file in the format you chose in part (a) above.
c) Write a main method that asks the user for a to do list file, reads it into your program, sorts the to do list, and writes the sorted to do list to a file.
Explanation / Answer
contact on timacs12@gmail.com
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.