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...
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
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.
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,...
All Tasks are commented in the code: public class MandelbrotUtil { private MandelbrotUtil() { } /**...
All Tasks are commented in the code: public class MandelbrotUtil { private MandelbrotUtil() { } /** * Return the number of iterations needed to determine if z(n + 1) = z(n) * z(n) + c * remains bounded where z(0) = 0 + 0i. z(n + 1) is bounded if its magnitude * is less than or equal to 2. Returns 1 if the magnitude of c * is greater than 2. Returns max if the magnitude * of z(n...
Why does my code print nothing in cout? I think my class functions are incorrect but...
Why does my code print nothing in cout? I think my class functions are incorrect but I don't see why. bigint.h: #include <string> #include <vector> class BigInt { private:    int m_Input, m_Temp;    std::string m_String = "";    std::vector<int> m_BigInt; public:    BigInt(std::string s)   // convert string to BigInt    {        m_Input = std::stoi(s);        while (m_Input != 0)        {            m_Temp = m_Input % 10;            m_BigInt.push_back(m_Temp);       ...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT