Develop a to-do list

I need help with my java. I'm beginner in java, don't judge my strictly

Task. Develop a to-do list that is command-driven in the console. Commands: LIST, ADD, EDIT, DELETE.

LIST - displays cases with their serial numbers; ADD - adds a case to the end of the list or a case to a certain place, moving the rest of the cases forward, if you specify a number; EDIT - replaces the case with the specified number; DELETE - deletes.

Command examples

LIST ADD Something ADD 4 Something's in fourth place EDIT 3 New case title DELETE 7

I have few questions:

  1. How to enter in console command with argument like "ADD 4"?
  2. Why my added thing prints only one word? For example, I want to add "Sleep all day", console outputs only "Sleep"

My code:

import java.util.ArrayList;
import java.util.Scanner;
import java.io.IOException;


public class Main {
  public static void main(String[] args) throws IOException {

    ArrayList<String> todoList = new ArrayList<>() {{
  add(0, "Get up in the morning");
  add(1, "Wash up");
  add(2, "Put yourself in order");
  add(3, "Put the planet in order");
  add(4, "Weed out the baobabs");
   }};

   String nameOfDeal;
   int dealNumber ;
   String editName;
   int deleteDeal;

   String text = "WELCOME TO THE DAY TO-DO LIST. SELECT THE ACTION: \n\nLIST - display the to-do list 
   on the screen" +
    "\nADD - add to the to-do list" +
    "\nEDIT - replace the case with the specified number;" +
    "\nDELETE - delete a case from the list" +
    "\nEXIT - exit";
    System.out.println(text);

   System.out.println("\nENTER: ");


   while (true) {
     Scanner sc = new Scanner(System.in);
     switch (sc.nextLine())
   {
    case "LIST":
      System.out.println("TO-DO LIST: ");
      for (String s : todoList) {
        System.out.println(todoList.indexOf(s) +" "+ s);
      }

      continue;

    case "ADD":
      System.out.println("Enter which case you want to add ");
      Scanner scanner1 = new Scanner(System.in);
      nameOfDeal = scanner1.next();
      todoList.add(nameOfDeal);
      System.out.println("The case has been added and is listed under No.: " + todoList.size());
      System.out.println();
      for (String s : todoList) {
        System.out.println(todoList.indexOf(s) +" "+ s);
      }

      continue;

    case "DELETE":
      System.out.println("Enter the index of the case you want to delete");
      Scanner scanner4 = new Scanner(System.in);
      deleteDeal = scanner4.nextInt();
      todoList.remove(deleteDeal);
      for (String s : todoList) {
        System.out.println(todoList.indexOf(s) +" "+ s);
      }
      continue;

    case "EDIT":

      System.out.println("Enter index of the case you want to change");
      Scanner scanner2 = new Scanner(System.in);
      dealNumber = scanner2.nextInt();
      todoList.remove(dealNumber);
      System.out.println("Enter a new task instead of the old one");
      Scanner scanner3 = new Scanner(System.in);
      editName = scanner3.nextLine();
      todoList.add(dealNumber, editName);
      for (String s : todoList) {
        System.out.println(todoList.indexOf(s) +" "+ s);
      }
      continue;

    default:
      System.out.println("Try again");
      break;

    case "EXIT":
      System.out.println("UP TO NEW MEETINGS!");
      break;
  }
  sc.close();
}

} }



Read more here: https://stackoverflow.com/questions/64467055/develop-a-to-do-list

Content Attribution

This content was originally published by ILYA SINTATSKY at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: