Created
October 15, 2022 09:51
-
-
Save ProfAndreaPollini/cf96c1e5d4bd1f23328c725dc3755b59 to your computer and use it in GitHub Desktop.
Todolist in Java - Compito a casa
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package org.ap.todolist; | |
| import java.util.Scanner; | |
| public class Application { | |
| private final TodoList todoList; | |
| public Application() { | |
| todoList = new TodoList(); | |
| } | |
| public static void main(String[] args) { | |
| var app = new Application(); | |
| app.run(); | |
| } | |
| private void run() { | |
| var selezione = 0; | |
| do { | |
| System.out.println("Todolist v. 0.1"); | |
| System.out.println("1 - elenco cose da fare"); | |
| System.out.println("2 - inserimento nuova cosa da fare"); | |
| System.out.println("3 - elimina una cosa da fare"); | |
| System.out.println("0 - Esci"); | |
| var sc = new Scanner(System.in); | |
| selezione = sc.nextInt(); | |
| switch (selezione) { | |
| case 1: | |
| elencoCoseDaFare(); | |
| break; | |
| case 2: | |
| inserimentoNuovaCosaDaFare(); | |
| break; | |
| case 3: | |
| eliminaCosaDaFare(); | |
| break; | |
| } | |
| } while (selezione != 0); | |
| } | |
| private void eliminaCosaDaFare() { | |
| } | |
| private void inserimentoNuovaCosaDaFare() { | |
| System.out.println("Aggiungi nuovo Todo"); | |
| var sc = new Scanner(System.in); | |
| var todoContent = sc.next(); | |
| var t = new Todo(todoContent); // creazione nuovo todo | |
| todoList.addTodo(t); | |
| } | |
| private void elencoCoseDaFare() { | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package org.ap.todolist; | |
| public class Todo { | |
| private final String title; | |
| public Todo(String title) { | |
| this.title = title; | |
| } | |
| public String getTitle() { | |
| return title; | |
| } | |
| @Override | |
| public String toString() { | |
| return String.format("Todo: %s",title); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package org.ap.todolist; | |
| import java.util.Vector; | |
| public class TodoList { | |
| private final Vector<Todo> todos; | |
| public TodoList() { | |
| todos = new Vector<>(); | |
| } | |
| public void addTodo(Todo todo) { | |
| todos.add(todo); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @startuml | |
| 'https://plantuml.com/class-diagram | |
| TodoList "1" *-- "N" Todo | |
| Application "1" *-- "1" TodoList | |
| class Todo { | |
| - title: String | |
| } | |
| class TodoList { | |
| - todos : Vector<Todo> | |
| + getTodos() : Vector<Todo> | |
| + getTodo(id: int) : Todo | |
| + addTodo(todo: Todo) : void | |
| + removeTodo(id: int) : void | |
| } | |
| class Application { | |
| - todoList: TodoList | |
| } | |
| @enduml |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment