Today you are going to implement a simple to-do list. We will instantiate a hash
ID: 3915009 • Letter: T
Question
Today you are going to implement a simple to-do list. We will instantiate a hashmap for you and set up some empty lists. We will even print the contents of these lists out for you. (A few less things for you "to do" All you have to do is add items to the appropriate lists Details Download the ZIP files named FilesNeeded.zip for use in Inteliu. When you are happy with your solution, upload the files into the src folder and run. You are going to finish off PoD.java to populate the appropriate to- do lists. Input Input will consist of a number of lines of comma-separated data, consisting of the to-do list to add a task to followed by the task item to add to that list: To-do list A, task itan A1 To-do list 8, task iten 81 To-do list A, task iten A2 To-do list 8. task iten 82 Processing For each line of input, you should add the items to the appropriate to-do list Output Output will be handled for you and will display the contents of the various to-do lists. To-do list A t task itam A1, task itn 2 To-do list B task item 81 task itm 821 END OF OUTPUTExplanation / Answer
Solution :
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class PoD
{
public static void main( String [] args )
{
Scanner in = new Scanner( System.in );
Map<String, ArrayList<String>> toDoLists = new HashMap<>();
// START WORK HERE ****************************************************
//Create a arraylist for sort the tasks of A
ArrayList<String> taskA = new ArrayList<String>();
taskA.add("task item A1");
taskA.add("task item A2");
//Create a arraylist for sort the tasks of B
ArrayList<String> taskB = new ArrayList<String>();
taskB.add("task item B1");
taskB.add("task item B2");
toDoLists.put("To-do List A",taskA);
toDoLists.put("To-do List B",taskB);
// END WORK HERE ****************************************************
for (String key : toDoLists.keySet())
{
System.out.println(key + ":");
System.out.println(toDoLists.get(key));
System.out.println();
}
in.close();
System.out.print("END OF OUTPUT");
}
}
output
To-do List A:
[task item A1, task item A2]
To-do List B:
[task item B1, task item B2]
END OF OUTPUT
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class PoD
{
public static void main( String [] args )
{
Scanner in = new Scanner( System.in );
Map<String, ArrayList<String>> toDoLists = new HashMap<>();
// START WORK HERE ****************************************************
//Create a arraylist for sort the tasks of A
ArrayList<String> taskA = new ArrayList<String>();
taskA.add("task item A1");
taskA.add("task item A2");
//Create a arraylist for sort the tasks of B
ArrayList<String> taskB = new ArrayList<String>();
taskB.add("task item B1");
taskB.add("task item B2");
toDoLists.put("To-do List A",taskA);
toDoLists.put("To-do List B",taskB);
// END WORK HERE ****************************************************
for (String key : toDoLists.keySet())
{
System.out.println(key + ":");
System.out.println(toDoLists.get(key));
System.out.println();
}
in.close();
System.out.print("END OF OUTPUT");
}
}
output
To-do List A:
[task item A1, task item A2]
To-do List B:
[task item B1, task item B2]
END OF OUTPUT