repl.it
@bbenefield89/

CLI Todo List

Java

No description

fork
loading
Files
  • Main.java
  • jdt.ls-java-project
  • Models
  • todolist.txt
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import java.util.List;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;

import Models.Todo;

class Main {
    public static void main(String[] args) throws FileNotFoundException {
        List<Todo> todos = new ArrayList<>();
        System.out.println(todos);  // []

        Todo walkDog = new Todo("Walk Dog", false);
        todos.add(walkDog);

        Todo vacuumHouse = new Todo("Vacuum House", false);
        todos.add(vacuumHouse);

        System.out.println(todos);  // [Models.Todo, Models.Todo]

        // save ArrayList of Todo's to todolist.json
        saveTodosToFile("todolist.txt", todos);

        // read todos to console
        readyTodosFromFileToConsole("todoslist.txt");
    }

    public static void saveTodosToFile(String fileName, List<Todo> todos) throws FileNotFoundException {
        PrintWriter printWriter = new PrintWriter(new FileOutputStream(fileName));
        for (Todo todo : todos) {
            printWriter.println(todo.getTitle());
            printWriter.println(todo.getIsComplete());
        }
        printWriter.close();
    }

    public static void readyTodosFromFileToConsole(String fileName) throws FileNotFoundException {
 
    }
}
?