Question

In: Computer Science

need to add these functions to my code: • show only important tasks • show all...

need to add these functions to my code: • show only important tasks • show all completed tasks

My code in java:

import java.util.ArrayList;
import java.util.*;
public class TodoList {
    String date="";
    String work="";
    boolean completed=false;
    boolean important=false;
    public TodoList(String a,String b,boolean c,boolean d){
        this.date=a;
        this.work=b;
        this.completed=c;
        this.important=d;
    }
    public boolean isCompleted(){
        return this.completed;
    }
    public boolean isImportant(){
        return this.important;
    }
    public String getDate(){
        return this.date;
    }
    public String getTask(){
        return this.work;
    }



}
 class Main{
    public static void main(String[] args) {
        ArrayList<TodoList> t1=new ArrayList<TodoList>();
        TodoList t2=null;
        Scanner s=new Scanner(System.in);
        int a;
        String b="",c="";
        boolean d,e;
        char g;
        do{
            System.out.println("1 Add a Task\n2 Show All Task\n3 Show Completed Task\n4 Delete a task");
            a=s.nextInt();
            switch(a){
                case 1:
                    System.out.println("enter the date");
                    b=s.next();
                    System.out.println("enter the task");
                    c=s.next();
                    System.out.println("enter the task is important true/false");
                    e=s.nextBoolean();
                    System.out.println("enter the task is completed true/false");
                    d=s.nextBoolean();
                    t2=new TodoList(b,c,d,e);
                    t1.add(t2);
                    break;
                case 2:
                    for(int i=0;i<t1.size();i++)
                    {
                        b=t1.get(i).getDate();
                        c=t1.get(i).getTask();
                        d=t1.get(i).isCompleted();
                        e=t1.get(i).isImportant();
                        System.out.println("Date: "+b+"\tTask: "+c+"\tCompleted: "+d+"\tImportant: "+e);
                    }
                    break;
                case 3:
                    for(int i=0;i<t1.size();i++)
                    {
                        b=t1.get(i).getDate();
                        c=t1.get(i).getTask();
                        d=t1.get(i).isCompleted();
                        e=t1.get(i).isImportant();
                        if(d){
                            System.out.println("Date: "+b+"\tTask: "+c+"\tCompleted: "+d+"\tImportant: "+e);
                        }
                    }
                    break;
                case 4:
                    System.out.println("Enter task number to delete");
                    int f=s.nextInt();
                    for(int i=f;i<t1.size()-1;i++){
                        t1.set(i,t1.get(i+1));
                    }
                    break;
                default:
                    System.out.println("Error");
                    break;
            }
            System.out.println("Continue: Y/N");
            g=s.next().charAt(0);
        }while((g=='y')||(g=='Y'));
    }
}

Solutions

Expert Solution

//I have made some improvments in code along with requirements............please review it....

//Java Code

import java.util.ArrayList;
import java.util.*;
public class TodoList {
    private String date="";
    private String work="";
    private boolean completed=false;
    private boolean important=false;
    public TodoList(String a,String b,boolean c,boolean d){
        this.date=a;
        this.work=b;
        this.completed=c;
        this.important=d;
    }
    public boolean isCompleted(){
        return this.completed;
    }
    public boolean isImportant(){
        return this.important;
    }
    public String getDate(){
        return this.date;
    }
    public String getTask(){
        return this.work;
    }

    @Override
    public String toString() {
        return "Date: "+date+"\tTask: "+work+"\tCompleted: "+completed+"\tImportant: "+important;
    }
}
class Main{
    public static void main(String[] args) {
        ArrayList<TodoList> t1=new ArrayList<TodoList>();
        TodoList t2=null;
        Scanner s=new Scanner(System.in);
        int a;
        String b="",c="";
        boolean d,e;
        char g='Y';
        do{
            try {
                System.out.println("1 Add a Task\n2 Show All Task\n3 Show Completed Task\n4. Show Only Important Tasks \n5. Delete a task");
                a = s.nextInt();
                s.nextLine();
                switch (a) {
                    case 1:
                        System.out.println("enter the date");
                        b = s.nextLine();
                        System.out.println("enter the task");
                        c = s.nextLine();
                        System.out.println("enter the task is important true/false");
                        e = s.nextBoolean();
                        System.out.println("enter the task is completed true/false");
                        d = s.nextBoolean();
                        s.nextLine();
                        t2 = new TodoList(b, c, d, e);
                        t1.add(t2);
                        System.out.println("task added...");
                        break;
                    case 2:
                        //Show all tasks
                        for (TodoList todoList : t1) {
                            System.out.println(todoList);
                        }
                        break;
                    case 3:
                        boolean found1 = false;
                        //Show completed Tasks
                        for (TodoList todo : t1) {
                            if (todo.isCompleted()) {
                                found1 = true;
                                System.out.println(todo);
                            }
                        }
                        if (!found1) {
                            System.out.println("No completed task to show...");
                        }
                        break;
                    case 4:
                        //show only important tasks
                        boolean found = false;
                        for (TodoList todo : t1
                        ) {
                            if (todo.isImportant()) {
                                found = true;
                                System.out.println(todo);
                            }

                        }
                        if (!found) {
                            System.out.println("No important task to show...");
                        }
                        break;
                    case 5:
                        System.out.println("Enter task number to delete");
                        int f = s.nextInt();
                        s.nextLine();
                        if (f >= 0 && f < t1.size()) {
                            System.out.println(t1.get(f).getTask() + " deleted...");
                            t1.remove(f);

                        } else {
                            System.out.println("No task to delete...");
                        }
                        break;
                    default:
                        System.out.println("Error");
                        break;
                }
            }
            catch (InputMismatchException|ArrayIndexOutOfBoundsException ex)
            {
                System.out.println(ex.getMessage());
                s.nextLine();
            }
                System.out.println("Continue: Y/N");
                g = s.nextLine().toUpperCase().charAt(0);


        }while(g=='Y');
    }
}

//Output

//If you need any help regarding this solutionn...... please leave a comment........ thanks


Related Solutions

java code: adds a new regular task, delete a task , show all tasks, and show...
java code: adds a new regular task, delete a task , show all tasks, and show regular tasks, mark a task as important (possibly through ID), complete task, show all completed tasks, show important tasks. I also need a UML diagram for the code update: The "task" is like something in a to do list. example) task 1. name: get carrots important: no completed: yes. you can run my code as an example if needed
C++ Need to add the following functions to my templatized class linked list. (main is already...
C++ Need to add the following functions to my templatized class linked list. (main is already set to accommodate the functions below) --void destroy_list () deletes each node in the list, and resets the header to nullptr --bool search_list (key value) searches the list for a node with the given key. Returns true if found, false if not. --bool delete_node (key value) deletes the node which contains the given key. If there is more than one node with the same...
Please add to this Python, Guess My Number Program. Add code to the program to make...
Please add to this Python, Guess My Number Program. Add code to the program to make it ask the user for his/her name and then greet that user by their name. Please add code comments throughout the rest of the program If possible or where you add in the code to make it ask the name and greet them before the program begins. import random def menu(): print("\n\n1. You guess the number\n2. You type a number and see if the...
Below is my c program code you have to change all the functions names variables name...
Below is my c program code you have to change all the functions names variables name , every thing so it wont look same but runs the same and make sure you run the program and share the output so i get to know that the program is running thank you. #define _CRT_SECURE_NO_DEPRECATE #include #include #include #include #include struct patient { int id; int age; bool annualClaim; int plan; char name[30]; char contactNum[15]; char address[50]; }; #define MAX_LENGTH 500 struct...
I used this code for my first draft assignment. My teacher told me not to add...
I used this code for my first draft assignment. My teacher told me not to add a decrypt function. I have the variable encryptionKey holding 16. I can simply negate encryptionKey with the - in front. Then I make one key change and all the code still works properly. How do I adjust this code? import csv import sys #The password list - We start with it populated for testing purposes passwords = [["yahoo","XqffoZeo"],["google","CoIushujSetu"]] #The password file name to store...
I am trying to make a new code that uses functions to make it. My functions...
I am trying to make a new code that uses functions to make it. My functions are below the code. <?php */ $input; $TenBills = 1000; $FiveBills = 500; $OneBills = 100; $Quarters = 25; $Dimes = 10; $Nickels = 5; $Pennies = 1; $YourChange = 0; $input = readline("Hello, please enter your amount of cents:\n"); if(ctype_digit($input)) { $dollars =(int)($input/100); $cents = $input%100;    $input >= $TenBills; $YourChange = (int)($input/$TenBills); $input -= $TenBills * $YourChange; print "Change for $dollars dollars...
**Add comments to existing ARM code to explain steps** Question that my code answers: Write an...
**Add comments to existing ARM code to explain steps** Question that my code answers: Write an ARM assembly program to calculate the value of the following function: f(y) = 3y^2 – 2y + 10 when y = 3. My Code below, that needs comments added: FunSolve.s LDR R6,=y LDR R1,[R6] MOV R2,#5 MOV R3,#6 MUL R4,R1,R1 MUL R4,R4,R2 MUL R5,R1,R3 SUB R4,R4,R5 ADD R4,R4,#8 st B st y DCD 3
Please write the following swap functions and print code in main to show that the functions...
Please write the following swap functions and print code in main to show that the functions have adequately . Your code should, in main(), print the values prior to being sent to the swap function. In the swap function, the values should be swapped and then in main(), please print the newly swapped values. 1) swap integer values using reference parameters 2) swap integer values using pointer parameters 3) swap pointers to integers - you need to print the addresses,...
You will develop code in the ​StickWaterFireGame​ class only. Your tasks are indicated by a TODO....
You will develop code in the ​StickWaterFireGame​ class only. Your tasks are indicated by a TODO. You will also find more instructions in the form of comments that detail more specifically what each part of the class is supposed to do, so make sure to read them. ​Do not delete or modify the method headers in the starter code! Here is an overview of the TODOs in the class. TODO 1: Declare the instance variables of the class. Instance variables...
Show the code how to add a node to the front of a list. Draw the...
Show the code how to add a node to the front of a list. Draw the picture also that goes with the code. NOW Show the code how to add a node to the end of a list. Draw the picture also that goes with the code. EXTRA CREDIT Show the code how to add a node to a specific spot in a list. Draw the picture also that goes with the code.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT