Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[The-Dudeski] iP #566

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,10 @@ src/main/resources/docs/
*.iml
bin/

# Java Files
*.class

/text-ui-test/ACTUAL.TXT
text-ui-test/EXPECTED-UNIX.TXT

kirby.txt
10 changes: 0 additions & 10 deletions src/main/java/Duke.java

This file was deleted.

32 changes: 32 additions & 0 deletions src/main/java/kirby/Kirby.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package kirby;

import kirby.tasks.TaskList;

import java.util.Scanner;


public class Kirby {

private Storage storage;
private TaskList taskList;
private Ui ui;

public static void main(String[] args) {

String message =
"____________________________________________________________\nHiiiiii \uD83D\uDE00! I'm kirby.Kirby Yayyyyy \uD83C\uDF8C!\nWhat can I do for you?\n____________________________________________________________\n";

Scanner sc = new Scanner(System.in);

TaskList inputs;

inputs = Storage.returnSave();

System.out.println(message);

Ui.receiveInput(sc, inputs);

Storage.save(inputs);

}
}
51 changes: 51 additions & 0 deletions src/main/java/kirby/Storage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package kirby;

import kirby.tasks.TaskList;

import java.io.*;
import java.util.ArrayList;

public class Storage {

public static TaskList returnSave() {
String home = System.getProperty("user.dir");
java.nio.file.Path path = java.nio.file.Paths.get(home, "data", "kirby.txt");
File saveFile = path.toFile();

TaskList inputs = new TaskList(new ArrayList<>());

try {
saveFile.createNewFile();
FileInputStream fileInputStream = new FileInputStream(saveFile);
ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream);
inputs = (TaskList) objectInputStream.readObject();
objectInputStream.close();
} catch (IOException e) {
System.out.println("Error: Input seems to not work");
} catch (SecurityException e) {
System.out.println("Error: Don't have permissions to create Save File");
} catch (ClassNotFoundException e) {
System.out.println("Error: Save File is corrupted");
}

return inputs;

}


public static void save(TaskList inputs){
try {
String home = System.getProperty("user.dir");
java.nio.file.Path path = java.nio.file.Paths.get(home, "data", "kirby.txt");
File saveFile = path.toFile();

FileOutputStream fileOutputStream = new FileOutputStream(saveFile);
ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream);
objectOutputStream.writeObject(inputs);
objectOutputStream.flush();
objectOutputStream.close();
} catch(IOException e){
System.out.println("Error: Could not write to save file");
}
}
}
109 changes: 109 additions & 0 deletions src/main/java/kirby/Ui.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package kirby;

import kirby.exceptions.InvalidCommandException;
import kirby.exceptions.MissingArgumentException;
import kirby.tasks.TaskList;

import java.util.Scanner;

public class Ui {

public static void receiveInput(Scanner sc, TaskList inputs){

String var = sc.nextLine();

while(!var.equals("bye")){

//list command
if(var.equals("list")){

inputs.list();

var = sc.nextLine();
continue;
}

try {
//mark command
if (var.split(" ")[0].equals("mark")) {

inputs.mark(var);

var = sc.nextLine();
continue;
}

//unmark command
if (var.split(" ")[0].equals("unmark")) {

inputs.unmark(var);

var = sc.nextLine();
continue;
}

//todo command
if (var.split(" ")[0].equals("todo")){

inputs.todo(var);

var = sc.nextLine();
continue;
}

//delete command
if (var.split(" ")[0].equals("delete")){

inputs.delete(var);

var = sc.nextLine();
continue;
}

//deadline command
if (var.split(" ")[0].equals("deadline")){

inputs.delete(var);

var = sc.nextLine();
continue;
}

//event command
if (var.split(" ")[0].equals("event")){

inputs.event(var);

var = sc.nextLine();
continue;
}

throw new InvalidCommandException("Invalid Command");

} catch(IndexOutOfBoundsException e){
System.out.println("Sorry that item doesn't exist");
// e.printStackTrace();
var = sc.nextLine();
continue;
} catch(NumberFormatException e){
System.out.println("You have to indicate the number on the list");
var = sc.nextLine();
continue;
} catch(MissingArgumentException e){
System.out.println("It seems that you are missing some details. I'm not really sure what I'm supposed to do");
var = sc.nextLine();
continue;

} catch(InvalidCommandException e){
System.out.println("Please enter a valid command");
var = sc.nextLine();
continue;
}
}

//bye command
System.out.println("Noooo \uD83E\uDD7A You are leaving already \uD83D\uDE16? Hope to see you again soon!\n____________________________________________________________");

}

}
9 changes: 9 additions & 0 deletions src/main/java/kirby/exceptions/InvalidCommandException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package kirby.exceptions;

public class InvalidCommandException extends Exception {

public InvalidCommandException(String errorMessage) {
super(errorMessage);
}

}
10 changes: 10 additions & 0 deletions src/main/java/kirby/exceptions/MissingArgumentException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package kirby.exceptions;

public class MissingArgumentException extends Exception {

public MissingArgumentException(String errorMessage) {
super(errorMessage);
}


}
28 changes: 28 additions & 0 deletions src/main/java/kirby/tasks/DeadlinedTask.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package kirby.tasks;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class DeadlinedTask extends Task {

private LocalDateTime deadline;

public DeadlinedTask(String name, LocalDateTime deadline) {
super(name);
this.deadline = deadline;
}

@Override
public String toString() {

String taskString = "[D] ";

String temp = "[ ] ";

if(this.isDone()){
temp = "[X] ";
}

return taskString + temp + this.getName() + "(by: " + this.deadline.format(DateTimeFormatter.ofPattern("d MMMM yyyy h:mm a")) + ")";
}
}
30 changes: 30 additions & 0 deletions src/main/java/kirby/tasks/EventTask.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package kirby.tasks;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class EventTask extends Task {

private LocalDateTime start, end;

public EventTask(String name, LocalDateTime start, LocalDateTime end) {
super(name);
this.start = start;
this.end = end;
}

@Override
public String toString() {

String taskString = "[E] ";

String temp = "[ ] ";

if(this.isDone()){
temp = "[X] ";
}

return taskString + temp + this.getName() + "(from: " + this.start.format(DateTimeFormatter.ofPattern("d MMMM yyyy h:mm a")) + " to: " + this.end.format(DateTimeFormatter.ofPattern("d MMMM yyyy h:mm a")) + ")";
}

}
44 changes: 44 additions & 0 deletions src/main/java/kirby/tasks/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package kirby.tasks;

import java.io.Serializable;

public class Task implements Serializable {

private String name;
private boolean done;

@Override
public String toString() {

String taskString = "[ ] ";

String temp = "[ ] ";

if(this.done){
temp = "[X] ";
}

return taskString + temp + this.name;
}

public void setName(String name) {
this.name = name;
}

public void setDone(boolean done) {
this.done = done;
}

public String getName() {
return name;
}

public boolean isDone() {
return done;
}

public Task(String name) {
this.name = name;
this.done = false;
}
}
Loading