Question

In: Computer Science

Create a new project called: ToDoList Purpose: To demonstrate your ability to use a linear structure  to...

Create a new project
called:
ToDoList

Purpose:

To demonstrate your ability to use a linear structure  to insert, contain, change, and remove data elements (Strings). Also to show that you can perform the detailed work in functions with the main function containing only the major program logic.

Specifications:

Create a new project called ToDoList and save it in the appropriate Lab folder.

Step 1: To begin the main program, use an ArrayList or LinkedList, to declare a structure to hold String values. Add at least five (5) tasks to the structure(this may be done in main or in a separate function (preferred).

Add a function to print a numbered list of the tasks (numbering must start at 1). The list should display all the elements with the assigned number (1, 2, 3, … n). The numbers are not permanently associated with a tasks but are reassigned each time the list is displayed. The listed number should identify the current position the task occupies in the list.

Step 2: Provide a simple vertical menu to allow the user the option to add,  change, or  delete a task from the list. Also include the option to terminate the program. The menu options should be listed vertically. The menu display and its selection validation may be done as a separate class in its own file or via a function called by the main program.

Step 3: In the main program logic, use the menu selection to determine the next operation.

Hint: using a switch to handle the menu options provides a neat and orderly structure in the main function.

When the user opts to add a task , add it to the end of the list.

When the user opts to change or delete a task, require the user to supply the assigned task number. If the task number entered is not in the list, display an error, pause the screen to allow the user to see the error, and end the operation.

When the user opts to change a task, obtain the new task description and replace the old description with the new.

When the user opts to delete a task remove it.

After each operation (with or without an error), clear the screen and redisplay the list followed by the menu.

Note: each of the operations (add, change, delete) should be coded in its own function and called from the main function.

Provide a main function loop (while or do...while) to allow the user to continue processing until the user selects the terminate menu option.

Step 4: Using the JAVADOC format, document the program and every function (main is a function, not a constructor) as displayed in the sample programs found in the downloaded files for Self Study Activity. Completeness, accuracy, and spelling count.

Solutions

Expert Solution

import java.util.*;
import java.util.Map.Entry;
class TestClass {       
    public static void main(String args[] ) throws Exception {
        ArrayList<String> al = new ArrayList<>();
        Scanner sc = new Scanner(System.in);
        int option;
        do {
                System.out.println("Enter choice");
                System.out.println("1. Add");
                System.out.println("2. Change");
                System.out.println("3. Delete");
                System.out.println("4. Exit");
                option = sc.nextInt();
                switch(option) {
                        case 1:
                                add(al);
                                
                                print(al);
                                break;
                        case 2:
                                change(al);
                                print(al);
                                break;
                        case 3:
                                delete(al);
                                print(al);
                                break;
                        case 4:
                                System.out.println("System terminates");
                                break;
                        default: 
                                System.out.println("Invalid choice");
                }
                //System.out.print("\033[H\033[2J"); // To clear the screen.
                        System.out.flush();
        }while(option!=4);
        //sc.close();
        
    }
    static void print(ArrayList<String> al) {
        System.out.println("List :");
        for(int i=0;i<al.size();i++) {
                System.out.println((i+1)+" "+al.get(i));
        }
    }
    static void add(ArrayList<String> al) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("Enter task");
        String str = scanner.nextLine();
        al.add(str);
        
        //scanner.close();
    }
    static void change(ArrayList<String> al) {
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter task number to change");
        
        int task_number = sc.nextInt();
        if(task_number>al.size()) {
                System.out.println("Entered task number is not present in the list");
                //sc.close();
                return;
        }
        
        System.out.println("Enter new task description");
        sc.nextLine();
        String str = sc.nextLine();
        al.set(task_number-1, str);
        //sc.close();
    }
    static void delete(ArrayList<String> al) {
        System.out.println("Enter task number to remove");
        Scanner sc = new Scanner(System.in);
        int task_number = sc.nextInt();
        if(task_number>al.size()) {
                System.out.println("Entered task number is not present in the list");
                //sc.close();
                return;                 
        }
        
        al.remove((task_number-1));
        //sc.close();
    }
}

Related Solutions

"Gambling Greg" Assignment Outcomes: Demonstrate the ability to create and use structs Demonstrate the ability to...
"Gambling Greg" Assignment Outcomes: Demonstrate the ability to create and use structs Demonstrate the ability to create and use menus Demonstrate the ability to create and use an array of structs Demonstrate the ability to generate and use random numbers Program Specifications: Assume that gambling Greg often goes to the Dog Racing Track. Greg loves to bet on the puppies. In each race Greg will place a wager and pick a dog. The dog information will be stored in a...
"Gambling Greg" Assignment Outcomes: Demonstrate the ability to create and use structs Demonstrate the ability to...
"Gambling Greg" Assignment Outcomes: Demonstrate the ability to create and use structs Demonstrate the ability to create and use menus Demonstrate the ability to create and use an array of structs Demonstrate the ability to generate and use random numbers Program Specifications: Assume that gambling Greg often goes to the Dog Racing Track. Greg loves to bet on the puppies. In each race Greg will place a wager and pick a dog. The dog information will be stored in a...
Purpose The purpose of this assignment is to give you an opportunity to demonstrate your ability...
Purpose The purpose of this assignment is to give you an opportunity to demonstrate your ability to identify emerging ethical issues in business, interpret the multitude of perspectives inherent in your case study, and model appropriate behaviour by recommending specific solutions. How to Proceed Select a case. It can be one of the textbook cases that we have not discussed during the course. It can also come from the outside world, perhaps a case you have been following in the...
Policy Drivers The purpose of this assignment is to practice and demonstrate your ability to interpret...
Policy Drivers The purpose of this assignment is to practice and demonstrate your ability to interpret detailed policy. We have chosen for you to take a look at two of the most well known policies; in real life, you will have government polices such as these as well as enterprise specific policies or regulations. As you build information systems, it is key to early on in the process to identify all relevant policy drivers and understand them. In the module,...
c++ The purpose of this project is to test your ability to use files, class design,...
c++ The purpose of this project is to test your ability to use files, class design, operator overloading, and Strings or strings effectively in program design Create a program which will read a phrase from the user and create a framed version of it for printing. For example, the phrase "hello world"would result in: ********* * hello * * world * ********* Whereas the phrase "the sky is falling"might be: *********** * the * * sky * * is *...
Playing with strings Assignment Outcomes: Demonstrate the ability to create strings. Demonstrate the ability to manipulate...
Playing with strings Assignment Outcomes: Demonstrate the ability to create strings. Demonstrate the ability to manipulate strings. Demonstrate the ability to write well written code. Program Specifications: DESIGN and IMPLEMENT a short program that will: Allow the user to enter a string with up to 100 letters. Display the user-entered string: Forward Backward Vertical As a triangle made from the letters of the string Display the number of letters in the string. Once everything above is displayed, the program will...
Its purpose is to provide you an opportunity to demonstrate your ability to think like an...
Its purpose is to provide you an opportunity to demonstrate your ability to think like an economist by applying economic principles to interpret the logic of a real-world phenomenon. Please identify any ONE of the monetary policies during COVID 19 in the world, use macroeconomic theories to demonstrate the economic logic behind this monetary policy. Also, please discuss how different schools of economics think of this monetary policy. Do you agree or disagree with this monetary policy? Please use the...
Its purpose is to provide you an opportunity to demonstrate your ability to think like an...
Its purpose is to provide you an opportunity to demonstrate your ability to think like an economist by applying economic principles to interpret the logic of a real-world phenomenon. Please identify any ONE of the monetary policies during COVID 19 in the world, use macroeconomic theories to demonstrate the economic logic behind this monetary policy. Also, please discuss how different schools of economics think of this monetary policy. Do you agree or disagree with this monetary policy? Please use the...
The purpose of the self-assessment paper is to demonstrate your ability to apply psychological concepts and...
The purpose of the self-assessment paper is to demonstrate your ability to apply psychological concepts and theory to your own life. It is not a research paper. The paper must be at least four (4), but no more than five (5) pages in length and address one of the following topics: How I Can Apply Psychology to My Future Life- How can the information you have learned in this class play a role in your future life. Describe how this...
Struct PERSON Assignment Outcomes: Demonstrate the ability to create structs using typedef Demonstrate the ability to...
Struct PERSON Assignment Outcomes: Demonstrate the ability to create structs using typedef Demonstrate the ability to create an array of structs Program Specifications: DESIGN and IMPLEMENT a program that will CREATE and use three different variables of type PERSON. Create a struct using the typedef command for a DATE. Create a struct for a PERSON with the following fields. name [this will be a string] birthdate [this will be a DATE] gender [this will be a char] annualIncome [this will...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT