diff --git a/Calculator/.classpath b/Calculator/.classpath
new file mode 100644
index 0000000..51a8bba
--- /dev/null
+++ b/Calculator/.classpath
@@ -0,0 +1,6 @@
+
+
+
+
+
+
diff --git a/Calculator/.gitignore b/Calculator/.gitignore
new file mode 100644
index 0000000..ae3c172
--- /dev/null
+++ b/Calculator/.gitignore
@@ -0,0 +1 @@
+/bin/
diff --git a/Calculator/.project b/Calculator/.project
new file mode 100644
index 0000000..afb56be
--- /dev/null
+++ b/Calculator/.project
@@ -0,0 +1,17 @@
+
+
+ Calculator
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/Calculator/.settings/org.eclipse.jdt.core.prefs b/Calculator/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..3a21537
--- /dev/null
+++ b/Calculator/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,11 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.8
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.8
diff --git a/Calculator/src/AnotherCalculator.java b/Calculator/src/AnotherCalculator.java
new file mode 100644
index 0000000..431be6f
--- /dev/null
+++ b/Calculator/src/AnotherCalculator.java
@@ -0,0 +1,9 @@
+
+public class AnotherCalculator {
+
+ public static void main(String[] args) {
+ // TODO Auto-generated method stub
+
+ }
+
+}
diff --git a/Calculator/src/Calculator.java b/Calculator/src/Calculator.java
new file mode 100644
index 0000000..0710146
--- /dev/null
+++ b/Calculator/src/Calculator.java
@@ -0,0 +1,9 @@
+
+public class Calculator {
+
+ public static void main(String[] args) {
+ // TODO Auto-generated method stub
+
+ }
+
+}
diff --git a/RosterExample/.classpath b/RosterExample/.classpath
new file mode 100644
index 0000000..51a8bba
--- /dev/null
+++ b/RosterExample/.classpath
@@ -0,0 +1,6 @@
+
+
+
+
+
+
diff --git a/RosterExample/.gitignore b/RosterExample/.gitignore
new file mode 100644
index 0000000..ae3c172
--- /dev/null
+++ b/RosterExample/.gitignore
@@ -0,0 +1 @@
+/bin/
diff --git a/RosterExample/.project b/RosterExample/.project
new file mode 100644
index 0000000..453ec81
--- /dev/null
+++ b/RosterExample/.project
@@ -0,0 +1,17 @@
+
+
+ RosterExample
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/RosterExample/.settings/org.eclipse.jdt.core.prefs b/RosterExample/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..3a21537
--- /dev/null
+++ b/RosterExample/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,11 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.8
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.8
diff --git a/RosterExample/src/Employee.java b/RosterExample/src/Employee.java
new file mode 100644
index 0000000..b108f9c
--- /dev/null
+++ b/RosterExample/src/Employee.java
@@ -0,0 +1,53 @@
+
+public class Employee {
+
+ // Variables
+
+ private static int NEXTID = 100; // Static variable that goes with the class
+
+ private String name;
+ private String jobTitle;
+ private int id;
+
+ /*
+ * TODO:
+ * Fields to add:
+ * boolean isActive - true if the employee is active (i.e. not retired or on leave), false otherwise
+ * LocalDateTime startDate - the date this employee began employment
+ */
+
+ // Constructor
+
+ public Employee(String empName, String empJobTitle) {
+ name = empName;
+ jobTitle = empJobTitle;
+ id = NEXTID;
+ NEXTID++; // increment
+ }
+
+ // Methods
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getJobTitle() {
+ return jobTitle;
+ }
+
+ public void setJobTitle(String title) {
+ this.jobTitle = title;
+ }
+}
diff --git a/RosterExample/src/Main.java b/RosterExample/src/Main.java
new file mode 100644
index 0000000..ebe6a26
--- /dev/null
+++ b/RosterExample/src/Main.java
@@ -0,0 +1,78 @@
+import java.util.List;
+import java.util.Scanner;
+
+public class Main {
+
+ public static void main(String[] args) {
+ Roster myRoster = new Roster();
+ Scanner reader = new Scanner(System.in);
+
+ /*
+ * User command options:
+ * add - create a new employee and add them to the roster
+ * list - print all the employees in the roster
+ * list [id] - given an employee id, print their info
+ * quit - exit the program
+ *
+ * TODO:
+ * delete [id] - given an employee id, remove that employee from the roster
+ * list [-a] - print all active employees
+ */
+ boolean quit = false;
+
+ while(!quit) {
+ System.out.println("Command options: add, list [id], quit");
+ String input = reader.nextLine(); // Read user's input
+ String[] inputParts = input.split(" "); // Split user input into multiple strings
+ String firstCommand = inputParts[0]; // First command typed by user
+ if (firstCommand.equals("add")) {
+ // Prompt user for employee info
+ System.out.println("Please enter employee name");
+ String name = reader.nextLine();
+ System.out.println("Please enter employee title");
+ String title = reader.nextLine();
+
+ Employee emp = new Employee(name, title);
+ myRoster.addEmployee(emp);
+ } else if (firstCommand.equals("list")) {
+ if (inputParts.length == 2) { // User has input "list [i]"
+ int empId = Integer.parseInt(inputParts[1]);
+ printEmployee(myRoster, empId);
+ } else if (inputParts.length == 1) { // User has input "list"
+ printEmployeeList(myRoster);
+ }
+ } else if (firstCommand.equals("quit")) {
+ quit = true;
+ } else {
+ System.out.println("Invalid input, please try again");
+ }
+ }
+ reader.close();
+ }
+
+ // Print the entire employee list
+ private static void printEmployeeList(Roster myRoster) {
+ List employeeList = myRoster.getEmployeeList();
+ for (int i = 0; i < employeeList.size(); i++) {
+ Employee currEmp = employeeList.get(i);
+ System.out.println("Id: " + currEmp.getId()
+ + ", Name: " + currEmp.getName()
+ + ", Title: " + currEmp.getJobTitle());
+ }
+ }
+
+ // Given the employee id, find them in the list and print their info
+ private static void printEmployee(Roster myRoster, int id) {
+ List employeeList = myRoster.getEmployeeList();
+ for (int i = 0; i < employeeList.size(); i++) {
+ Employee currEmp = employeeList.get(i);
+ int currId = currEmp.getId();
+ if (currId == id) {
+ System.out.println("Id: " + currEmp.getId()
+ + ", Name: " + currEmp.getName()
+ + ", Title: " + currEmp.getJobTitle());
+ }
+ }
+ }
+
+}
diff --git a/RosterExample/src/Roster.java b/RosterExample/src/Roster.java
new file mode 100644
index 0000000..b4e29c5
--- /dev/null
+++ b/RosterExample/src/Roster.java
@@ -0,0 +1,22 @@
+import java.util.ArrayList;
+import java.util.List;
+
+public class Roster {
+ private List employeeList;
+
+ public Roster() {
+ employeeList = new ArrayList<>();
+ }
+
+ public List getEmployeeList() {
+ return employeeList;
+ }
+
+ public void setEmployeeList(List employees) {
+ employeeList = employees;
+ }
+
+ public void addEmployee(Employee toAdd) {
+ employeeList.add(toAdd);
+ }
+}
diff --git a/SQLiteSample/src/Sample.java b/SQLiteSample/src/Sample.java
new file mode 100644
index 0000000..dd6d864
--- /dev/null
+++ b/SQLiteSample/src/Sample.java
@@ -0,0 +1,93 @@
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+public class Sample
+{
+ public static void main(String[] args)
+ {
+ Connection connection = null;
+ try
+ {
+ // create a database connection
+ connection = DriverManager.getConnection("jdbc:sqlite:sample.db");
+ Statement statement = connection.createStatement();
+ statement.setQueryTimeout(30); // set timeout to 30 sec.
+
+ statement.executeUpdate("drop table if exists person");
+ statement.executeUpdate("create table person (id integer, name string)");
+ statement.executeUpdate("insert into person values(1, 'leo')");
+ statement.executeUpdate("insert into person values(2, 'yui')");
+
+ ResultSet rs = statement.executeQuery("select * from person");
+ while(rs.next())
+ {
+ // read the result set
+ System.out.println("name = " + rs.getString("name"));
+ System.out.println("id = " + rs.getInt("id"));
+ }
+ }
+ catch(SQLException e)
+ {
+ // if the error message is "out of memory",
+ // it probably means no database file is found
+ System.err.println(e.getMessage());
+ }
+ finally
+ {
+ try
+ {
+ if(connection != null)
+ connection.close();
+ }
+ catch(SQLException e)
+ {
+ // connection close failed.
+ System.err.println(e.getMessage());
+ }
+ }
+ getUser("leo");
+ }
+
+ public static void getUser(String name) {
+ String sql = "SELECT id, name FROM person where name = ?";
+
+ Connection connection = null;
+ try
+ {
+ connection = DriverManager.getConnection("jdbc:sqlite:sample.db");
+ PreparedStatement pstmt = connection.prepareStatement(sql);
+ pstmt.setString(1, name);
+ pstmt.setQueryTimeout(30); // set timeout to 30 sec.
+
+ ResultSet rs = pstmt.executeQuery();
+
+ while(rs.next()) {
+ System.out.println(rs.getInt("id") + "\t" +
+ rs.getString("name"));
+ }
+ }
+ catch(SQLException e)
+ {
+ // if the error message is "out of memory",
+ // it probably means no database file is found
+ System.err.println(e.getMessage());
+ }
+ finally
+ {
+ try
+ {
+ if(connection != null)
+ connection.close();
+ }
+ catch(SQLException e)
+ {
+ // connection close failed.
+ System.err.println(e.getMessage());
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/SQLiteSample/src/SqliteExample.java b/SQLiteSample/src/SqliteExample.java
new file mode 100644
index 0000000..93129fe
--- /dev/null
+++ b/SQLiteSample/src/SqliteExample.java
@@ -0,0 +1,197 @@
+import java.sql.Connection;
+import java.sql.Statement;
+import java.util.Scanner;
+import java.sql.ResultSet;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+
+/**
+ *
+ * @author sqlitetutorial.net
+ */
+public class SqliteExample {
+ /**
+ * Connect to a sample database
+ */
+ public static void connect() {
+ Connection conn = null;
+ Scanner scanner = new Scanner(System.in);
+ try {
+
+ // create the database connection, note the name of the file is test.db
+ String url = "jdbc:sqlite:test.db";
+ conn = DriverManager.getConnection(url);
+ // the connection we created above, will be used for all of the calls to the database
+
+ // step 1 create the table in the database if it does not already exists
+ // since we want to use the connection we already created, we will pass it in to the method,
+ createEmployeeTable(conn);
+
+ // now we will insert a record in the database
+ // again we pass the connection to the method
+ // we want to add 2 employees so we call the method 2 times
+ addNewEmployee(conn, scanner);
+ addNewEmployee(conn, scanner);
+
+ // print the employees so we can see the ones that we added
+ printEmployees(conn);
+
+ // short pause
+ Thread.sleep(1000);
+
+ // update a specific employee
+ updateEmployee(conn, scanner);
+
+ // print all the employees so we see the employee we updated
+ printEmployees(conn);
+
+ // short pause
+ Thread.sleep(1000);
+
+ // delete an employee
+ deleteEmployee(conn, scanner);
+
+ // print all the employees so we can see the employee we deleted
+ printEmployees(conn);
+
+ //short pause
+ Thread.sleep(1000);
+
+ // we delete the table so the next time we can start with a fresh table
+ deleteTable(conn);
+
+
+ } catch (Exception e) {
+ System.out.println(e.getMessage());
+ } finally {
+ scanner.close();
+ try {
+ if (conn != null) {
+ conn.close();
+ }
+ } catch (SQLException ex) {
+ System.out.println(ex.getMessage());
+ }
+ }
+ }
+
+ /**
+ * @param args the command line arguments
+ */
+ public static void main(String[] args) {
+ connect();
+ }
+
+ public static void createEmployeeTable(Connection conn) throws SQLException {
+ System.out.println("Creating the table if it does not already exist");
+
+ Statement stmt = conn.createStatement();
+ stmt.execute("CREATE TABLE IF NOT EXISTS employees (id integer, name varchar(255)); ");
+ stmt.close();
+ System.out.println("finished creating the table");
+ System.out.println();
+ }
+
+ public static void deleteTable(Connection conn) throws SQLException {
+ System.out.println("Deleting the table ");
+
+ Statement stmt = conn.createStatement();
+ stmt.execute("DROP TABLE employees; ");
+ stmt.close();
+ System.out.println("done deleting the table");
+ System.out.println();
+ }
+
+
+ public static void updateEmployee(Connection conn, Scanner scanner) throws SQLException {
+ System.out.println("Editing an employee record ");
+
+ // ask the user for an id and a name
+ System.out.print("Enter the id to update: ");
+ String idInput = scanner.nextLine();
+ System.out.print("Enter the new name: ");
+ String nameInput = scanner.nextLine();
+
+ // parse the id entered into an int
+ int id = Integer.parseInt(idInput);
+
+ // use the users input to update the database using a prepared statement
+ PreparedStatement stmt = conn.prepareStatement("update employees set name = ? where id = ?;");
+ stmt.setString(1, nameInput); // notice this is 1 and not 0, because counting starts at 1 for SQL
+ stmt.setInt(2, id);
+ stmt.executeUpdate();
+ stmt.close();
+ System.out.println("done updating the employee record");
+ System.out.println();
+
+ }
+
+ public static void addNewEmployee(Connection conn, Scanner scanner) throws SQLException {
+ System.out.println("Adding a new employee record ");
+
+ // ask the user for information to add to the table
+ System.out.print("Enter the id: ");
+ String idInput = scanner.nextLine();
+ System.out.print("Enter the name: ");
+ String nameInput = scanner.nextLine();
+
+ // we parse the users string input to an int for the id
+ int id = Integer.parseInt(idInput);
+
+ // we use a preparted statment
+ PreparedStatement stmt = conn.prepareStatement("insert into employees values (?,?);");
+ stmt.setInt(1, id); // again notice that in Sql counting starts at 1 not 0
+ stmt.setString(2, nameInput);
+ stmt.executeUpdate();
+ stmt.close();
+ System.out.println("done adding a new employee record ");
+ System.out.println();
+
+ }
+
+ public static void deleteEmployee(Connection conn, Scanner scanner) throws SQLException {
+ System.out.println("Deleting an employee record ");
+
+ // ask for the id to delete
+ System.out.print("Enter the id to delete: ");
+ String idInput = scanner.nextLine();
+ // we parse the user's input to an int for th id
+ int id = Integer.parseInt(idInput);
+
+ // we use the user's input as a parameter in our where caluse.
+ PreparedStatement stmt = conn.prepareStatement("delete from employees where id = ? ");
+ stmt.setInt(1, id); // notice that in sql counting starts at 1 not 0
+ stmt.executeUpdate();
+ stmt.close();
+ System.out.println("done deletng the employee record ");
+ System.out.println();
+
+ }
+
+
+
+ public static void printEmployees(Connection conn)
+ throws SQLException {
+ System.out.println("Printing all the employee records");
+
+ // since we are not using any user input, we do not need to use a prepared statement
+ Statement stmt = conn.createStatement();
+ ResultSet rs = stmt.executeQuery("select id, name from employees");
+ // loop through all the results that come back in the result set
+ while(rs.next()){
+ // get the id column for the row we are processing
+ int id = rs.getInt("id"); // rs.getInt(1);
+ // get the name column for the row we are processing
+ String name = rs.getString("name"); // rs.getString();
+
+ // print the id and name we got to the console
+ System.out.println(id+ " "+name);
+ }
+ rs.close();
+ stmt.close();
+ System.out.println("done printing the employee records ");
+ System.out.println();
+
+ }
+}
diff --git a/TimesheetApp/.classpath b/TimesheetApp/.classpath
new file mode 100644
index 0000000..51a8bba
--- /dev/null
+++ b/TimesheetApp/.classpath
@@ -0,0 +1,6 @@
+
+
+
+
+
+
diff --git a/TimesheetApp/.gitignore b/TimesheetApp/.gitignore
new file mode 100644
index 0000000..ae3c172
--- /dev/null
+++ b/TimesheetApp/.gitignore
@@ -0,0 +1 @@
+/bin/
diff --git a/TimesheetApp/.project b/TimesheetApp/.project
new file mode 100644
index 0000000..c5b5e8c
--- /dev/null
+++ b/TimesheetApp/.project
@@ -0,0 +1,17 @@
+
+
+ TimesheetApp
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/TimesheetApp/.settings/org.eclipse.jdt.core.prefs b/TimesheetApp/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..3a21537
--- /dev/null
+++ b/TimesheetApp/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,11 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.8
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.8
diff --git a/TimesheetApp/src/ConsoleUtils.java b/TimesheetApp/src/ConsoleUtils.java
new file mode 100644
index 0000000..5553163
--- /dev/null
+++ b/TimesheetApp/src/ConsoleUtils.java
@@ -0,0 +1,112 @@
+import java.time.format.DateTimeFormatter;
+import java.util.List;
+import java.util.Scanner;
+
+public class ConsoleUtils {
+
+ /* Member variables */
+
+ private Scanner scanner;
+ private DateTimeFormatter timeFormatter;
+
+ /* Constructor */
+
+ public ConsoleUtils(){
+ scanner = new Scanner(System.in);
+ timeFormatter = DateTimeFormatter.ofPattern("MM/dd/yy HH:mm");
+ }
+
+ /* Methods */
+
+ /*
+ * Prints the menu of actions to the console
+ */
+ public void printHelp(){
+ System.out.println("Valid commands: ");
+ System.out.println(" list [PROJECT] [-a] list entries; project and/or active flag are optional");
+ System.out.println(" add add an entry, and set the start time");
+ System.out.println(" stop ID update the entry's end time");
+ System.out.println(" delete ID delete entry with the ID");
+ System.out.println(" help print help");
+ System.out.println(" quit quit the app");
+ System.out.println();
+
+ }
+
+ /*
+ * Prints an informational message to the console
+ */
+ public void info(String msg){
+ System.out.println("["+msg+"]");
+ System.out.println();
+ }
+
+ /*
+ * Prints an error message to the console
+ */
+ public void error(String msg){
+ System.out.println("[ERROR: "+msg+"]");
+ System.out.println();
+ }
+
+ /*
+ * Prompts the user to enter input
+ * Returns the text entered by the user
+ */
+ public String promptString(String label){
+ System.out.print(label+" ");
+ return scanner.nextLine();
+ }
+
+ /*
+ * Prints a list of TimesheetEntry objects in a pretty table
+ */
+ public void printList(List entries){
+ int longestProject = 7;
+ int longestTask = 4;
+
+ for(TimesheetEntry entry : entries){
+ if(entry.getProjectName().length() > longestProject){
+ longestProject = entry.getProjectName().length();
+ }
+ if(entry.getTask().length() > longestTask) {
+ longestTask = entry.getTask().length();
+ }
+ }
+
+ String projectHeader = String.format("%"+longestProject+"s", "Project");
+ String projectUnderline = "";
+ for(int i=0;i ");
+ String[] actionParts = input.split(" ");
+
+ String action = actionParts[0].trim();
+
+
+ if (action.equals("add")) {
+
+ processAddAction();
+
+ } else if (action.equals("delete")) {
+
+ processDeleteAction(actionParts);
+
+ } else if (action.equals("stop")) {
+
+ processStopAction(actionParts);
+
+ } else if (action.equals("list")) {
+
+ processListAction(actionParts);
+
+ } else if (action.equals("quit")) {
+
+ quit = true;
+
+ } else if (action.equals("help")) {
+
+ consoleUtils.printHelp();
+
+ } else if(action.length() ==0 ){
+ // do nothing.
+ } else {
+
+ consoleUtils.error("Invalid action");
+ }
+ }
+
+ }
+
+
+ public void processStopAction(String[] actionParts){
+
+ if(actionParts.length > 2){
+ consoleUtils.error("Too many inputs to stop command");
+ return;
+ }
+
+ if(actionParts.length <= 1){
+ consoleUtils.error("Stop command requires a valid integer id");
+ return;
+ }
+ int id = 0;
+ try{
+ id = Integer.parseInt(actionParts[1]);
+ } catch (Exception e){
+ consoleUtils.error("Stop command requires a valid integer id");
+ return;
+ }
+
+ TimesheetEntry entry = timesheet.get(id);
+ if(entry == null){
+ consoleUtils.error("Could not find entry with id "+id);
+ return;
+ }
+
+ try{
+ timesheet.stop(entry);
+ consoleUtils.info("Entry stopped");
+ } catch (Exception e){
+ consoleUtils.error("Stop command failed, was entry already stopped?");
+ }
+
+ }
+
+ public void processDeleteAction(String[] actionParts){
+
+ if(actionParts.length > 2){
+ consoleUtils.error("Too many inputs to delete command");
+ return;
+ }
+
+ if(actionParts.length <= 1){
+ consoleUtils.error("Delete command requires a valid integer id");
+ return;
+ }
+ int id = 0;
+ try{
+ id = Integer.parseInt(actionParts[1]);
+ } catch (Exception e){
+ consoleUtils.error("Delete command requires a valid integer id");
+ return;
+ }
+
+ TimesheetEntry entry = timesheet.get(id);
+ if(entry == null){
+ consoleUtils.error("Could not find entry with id "+id);
+ return;
+ }
+
+ timesheet.delete(entry);
+ consoleUtils.info("Entry deleted");
+
+
+
+ }
+
+ public void processListAction(String[] actionParts){
+ if(actionParts.length > 3){
+ consoleUtils.error("Too many inputs to list command");
+ return;
+ }
+ boolean activeOnly = false;
+ String project = null;
+ for(String part: actionParts){
+ if(part.equals("-a")){
+ activeOnly = true;
+ } else if(part.equals("list")){
+ continue;
+ } else {
+ project = part;
+ }
+ }
+
+ List entries = timesheet.list(project, activeOnly);
+ consoleUtils.printList(entries);
+
+ }
+
+
+
+
+ public void processAddAction(){
+ String project = consoleUtils.promptString("Project (one word only):");
+ String description = consoleUtils.promptString("Task:");
+
+ if(project == null || project.length() == 0){
+ consoleUtils.error("A project is required");
+ } else {
+ timesheet.add(project, description);
+ consoleUtils.info("Entry added");
+ }
+
+ }
+}
diff --git a/TimesheetApp/src/Main.java b/TimesheetApp/src/Main.java
new file mode 100644
index 0000000..b3a6758
--- /dev/null
+++ b/TimesheetApp/src/Main.java
@@ -0,0 +1,8 @@
+public class Main {
+
+ public static void main(String[] args) {
+ Controller controller = new Controller();
+ controller.start();
+ }
+
+}
diff --git a/TimesheetApp/src/Timesheet.java b/TimesheetApp/src/Timesheet.java
new file mode 100644
index 0000000..54d1444
--- /dev/null
+++ b/TimesheetApp/src/Timesheet.java
@@ -0,0 +1,53 @@
+import java.util.ArrayList;
+import java.util.List;
+
+public class Timesheet {
+
+ private List database;
+
+ public Timesheet(){
+ this.database = new ArrayList<>();
+ }
+ public TimesheetEntry get(int id){
+ for(TimesheetEntry entry: database){
+ if(id == entry.getId()){
+ return entry;
+ }
+ }
+ return null;
+ }
+
+ public TimesheetEntry add(String project, String description){
+ TimesheetEntry newEntry = new TimesheetEntry(project, description);
+ database.add(newEntry);
+ return newEntry;
+ }
+
+ public void delete(TimesheetEntry entry){
+ database.remove(entry);
+ }
+
+ public TimesheetEntry stop(TimesheetEntry entry){
+ entry.updateEndTime();
+ return entry;
+ }
+
+ public List list(String project, boolean activeOnly){
+ List results = new ArrayList<>();
+ for(TimesheetEntry entry:database){
+ if(project != null && !project.equals(entry.getProjectName())){
+ continue;
+ }
+
+ if(activeOnly && entry.getEndTime() != null){
+ continue;
+ }
+
+ results.add(entry);
+
+ }
+ return results;
+ }
+
+
+}
diff --git a/TimesheetApp/src/TimesheetEntry.java b/TimesheetApp/src/TimesheetEntry.java
new file mode 100644
index 0000000..c6b837c
--- /dev/null
+++ b/TimesheetApp/src/TimesheetEntry.java
@@ -0,0 +1,49 @@
+import java.time.LocalDateTime;
+
+public class TimesheetEntry {
+
+ private String task;
+ private String projectName;
+ private int id;
+ private LocalDateTime startTime;
+ private LocalDateTime endTime;
+
+ private static int NEXTID = 1;
+
+
+ public TimesheetEntry(String projectName, String task){
+ this.projectName = projectName;
+ this.task = task;
+ this.startTime = LocalDateTime.now();
+ this.id = NEXTID;
+ NEXTID ++;
+ }
+
+ public void updateEndTime(){
+ if(endTime != null){
+ throw new IllegalStateException("End time already set");
+ }
+
+ endTime = LocalDateTime.now();
+ }
+
+ public String getTask() {
+ return task;
+ }
+
+ public String getProjectName() {
+ return projectName;
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public LocalDateTime getStartTime() {
+ return startTime;
+ }
+
+ public LocalDateTime getEndTime() {
+ return endTime;
+ }
+}