Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8a45c56

Browse files
committed
Upload files
1 parent 2545c0f commit 8a45c56

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
7+
/**
8+
*
9+
* @author User
10+
*/
11+
import java.util.ArrayList;
12+
13+
public class TodoList {
14+
private ArrayList<String> list;
15+
16+
public TodoList() {
17+
this.list = new ArrayList<>();
18+
}
19+
20+
public void add(String task) {
21+
this.list.add(task);
22+
}
23+
24+
public void print() {
25+
for (int i = 0; i < list.size(); i++) {
26+
System.out.println((i + 1) + ": " + list.get(i));
27+
}
28+
}
29+
30+
public void remove(int number) {
31+
this.list.remove(number - 1);
32+
}
33+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
7+
/**
8+
*
9+
* @author User
10+
*/
11+
import java.util.Scanner;
12+
13+
public class UserInterface {
14+
private TodoList todoList;
15+
private Scanner scanner;
16+
17+
public UserInterface(TodoList list, Scanner scanner) {
18+
this.todoList = list;
19+
this.scanner = scanner;
20+
}
21+
22+
public void start() {
23+
while (true) {
24+
System.out.println("Command: ");
25+
String command = scanner.nextLine();
26+
if (command.equals("stop")) {
27+
break;
28+
} else if (command.equals("list")) {
29+
todoList.print();
30+
} else if (command.equals("add")) {
31+
System.out.println("To add: ");
32+
String toAdd = scanner.nextLine();
33+
todoList.add(toAdd);
34+
} else if (command.equals("remove")) {
35+
System.out.println("Which one is removed? ");
36+
int number = Integer.valueOf(scanner.nextLine());
37+
todoList.remove(number);
38+
}
39+
}
40+
}
41+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /