case 2 almost done

This commit is contained in:
2022-10-23 16:02:52 +03:30
parent 0e90a4b4d6
commit 3a9b48a6f1
7 changed files with 64 additions and 41 deletions

View File

@@ -1,32 +1,11 @@
package com.tabrizu.ds; package com.tabrizu.ds;
import java.util.Scanner; import java.util.Scanner;
public class App { public class App {
ISingleLinkedList<Task> m_unfinished; ISingleLinkedList<Task> m_unfinished;
ISingleLinkedList<Task> m_finished; ISingleLinkedList<Task> m_finished;
public void userInterface(){
Scanner sc = new Scanner(System.in);
while (true){
int menuOption;
menuOption = mainMenu();
if(menuOption == 7){
break;
}
switch (menuOption) {
case 1:
System.out.println("What is the title of the task? ");
String taskTitle = sc.next();
Task task = new Task(taskTitle);
addTask(task, true);
break;
default:
System.out.println("DEFAULT");
break;
}
}
}
public int mainMenu() { public int mainMenu() {
int command; int command;
Scanner scanner = new Scanner(System.in); Scanner scanner = new Scanner(System.in);
@@ -47,10 +26,46 @@ public class App {
return command; return command;
} }
public void userInterface() {
Scanner sc = new Scanner(System.in);
while (true) {
int menuOption;
menuOption = mainMenu();
if (menuOption == 7) {
break;
}
switch (menuOption) {
case 1: {
System.out.println("What is the title of the task? ");
String taskTitle = sc.next();
Task task = new Task(taskTitle);
addTask(task, true);
break;
}
case 2: {
System.out.println("What is the title of the task? ");
String taskTitle = sc.next();
Task task = new Task(taskTitle);
addTask(task, false);
break;
}
default:
System.out.println("DEFAULT");
break;
}
}
}
public App() { public App() {
m_unfinished = ISingleLinkedList.create(); m_unfinished = ISingleLinkedList.create();
m_finished = ISingleLinkedList.create(); m_finished = ISingleLinkedList.create();
} }
public static void main(String[] Args) { public static void main(String[] Args) {
App app = new App(); App app = new App();
app.userInterface(); app.userInterface();
@@ -59,8 +74,7 @@ public class App {
public void addTask(Task task, boolean isNormalTask) { public void addTask(Task task, boolean isNormalTask) {
if (isNormalTask) { if (isNormalTask) {
m_unfinished.addLast(task); m_unfinished.addLast(task);
} } else {
else{
m_unfinished.addFirst(task); m_unfinished.addFirst(task);
} }
} }

View File

@@ -45,7 +45,9 @@ public class SingleLinkedList<T> implements ISingleLinkedList<T> {
m_tail = m_head; m_tail = m_head;
} }
m_size += 1; m_size += 1;
System.out.println("First Node added with value: " + value); System.out.println(
"First Node added with value: " + value
);
} }
@@ -59,7 +61,9 @@ public class SingleLinkedList<T> implements ISingleLinkedList<T> {
m_tail.setNext(newNode); m_tail.setNext(newNode);
m_tail = newNode; m_tail = newNode;
m_size++; m_size++;
System.out.println("Last Node added with value: " + value); System.out.println(
"Last Node added with value: " + value
);
} }

View File

@@ -10,4 +10,9 @@ public class Task {
public String getTitle(){ public String getTitle(){
return m_title; return m_title;
} }
@Override
public String toString() {
return "[Task] " + m_title;
}
} }

Binary file not shown.