From a5d8de27123c9fe245ed8b4ba2d55782fe7519c4 Mon Sep 17 00:00:00 2001 From: Desangles Date: Wed, 16 Jan 2019 20:08:58 -0600 Subject: [PATCH 1/7] Adding Calc project --- Calculator/.classpath | 6 ++++++ Calculator/.project | 17 +++++++++++++++++ Calculator/.settings/org.eclipse.jdt.core.prefs | 11 +++++++++++ 3 files changed, 34 insertions(+) create mode 100644 Calculator/.classpath create mode 100644 Calculator/.project create mode 100644 Calculator/.settings/org.eclipse.jdt.core.prefs 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/.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 From 762f7baf2606d87492e6f81caf496a4a1cb9d7a7 Mon Sep 17 00:00:00 2001 From: Desangles Date: Fri, 18 Jan 2019 15:23:06 -0600 Subject: [PATCH 2/7] calculator project --- Calculator/bin/Calculator.class | Bin 0 -> 1380 bytes Calculator/src/Calculator.java | 39 ++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 Calculator/bin/Calculator.class create mode 100644 Calculator/src/Calculator.java diff --git a/Calculator/bin/Calculator.class b/Calculator/bin/Calculator.class new file mode 100644 index 0000000000000000000000000000000000000000..bb9615399f53d79633e761577dd3271f80806df0 GIT binary patch literal 1380 zcmZux-Ez}L7(JWVmg1=7k3b3zD3nk;ZE&Grehi@`<;SfHX_Lte)9FlQX_G7?ORlt{ z%?%g409Ra;w}6Xerp)vK`cR#owUam{zR`ZW=i9UAJNvEv`S-8C0bIk67KQ|hD_-bl zp{L`-LQY`(x%a}WhF-K)ecF01eJxP9qavl31cu9%4T0QB9LOSuG2$SPg1}f)Me<43 zZpmcbYlTu^vKjkcxZx$r%=Z^_dRwIePP2bvoosDSMFOYFKR5d)ujxcZTlLC@g$aR) zE|6&zR@Zzliexf^DNI{9`9Ha9JE@j!2d8jaV91b8_b63dZA6_+lT~`{dJ*IJ)JQ)g zFjF3wQrR#klpM_B9LtU~y3i+ErMLq!8?M0l)lhn=bY-Mv;_7YbZmJ~JZq)VUwp+vn zT(t0+z*M&s3Od5!U>=tQtd5}#jqH6<-Ag#M!pJT=s9=G)k^Dn9BC6t*G;Dk+;2zVE zNyTN^STE2*z4sPMLfUV9(Z) zUCL;HEE{ahIg{Q=;vn<&VD&b>5x8K|e#>I5cvFM(jLXXoR!m>#{g5WGMZIK;jXO1< zLz$#ZYZ2`gf3!?6V;bwfm&@k*FbC4`2?Iln_yqa2IID6L9P28hyH+^B?i#Fc1Pg1{0d~(|)*;4&@AoTOqH0suC@Yvk z5i_jDWi9iVzyeq9^B?e#tH0nZT71JhL|^g^zQINO$t>f Date: Fri, 25 Jan 2019 16:09:30 -0600 Subject: [PATCH 3/7] Version 1 of RPS --- RockPaperScissors/.classpath | 6 + RockPaperScissors/.gitignore | 1 + RockPaperScissors/.project | 17 +++ .../.settings/org.eclipse.jdt.core.prefs | 11 ++ RockPaperScissors/src/RockPaperScissors.java | 127 ++++++++++++++++++ 5 files changed, 162 insertions(+) create mode 100644 RockPaperScissors/.classpath create mode 100644 RockPaperScissors/.gitignore create mode 100644 RockPaperScissors/.project create mode 100644 RockPaperScissors/.settings/org.eclipse.jdt.core.prefs create mode 100644 RockPaperScissors/src/RockPaperScissors.java diff --git a/RockPaperScissors/.classpath b/RockPaperScissors/.classpath new file mode 100644 index 0000000..51a8bba --- /dev/null +++ b/RockPaperScissors/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/RockPaperScissors/.gitignore b/RockPaperScissors/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/RockPaperScissors/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/RockPaperScissors/.project b/RockPaperScissors/.project new file mode 100644 index 0000000..f5d918c --- /dev/null +++ b/RockPaperScissors/.project @@ -0,0 +1,17 @@ + + + RockPaperScissors + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/RockPaperScissors/.settings/org.eclipse.jdt.core.prefs b/RockPaperScissors/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..3a21537 --- /dev/null +++ b/RockPaperScissors/.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/RockPaperScissors/src/RockPaperScissors.java b/RockPaperScissors/src/RockPaperScissors.java new file mode 100644 index 0000000..0b09763 --- /dev/null +++ b/RockPaperScissors/src/RockPaperScissors.java @@ -0,0 +1,127 @@ +import java.util.Random; +import java.util.Scanner; + +public class RockPaperScissors { + public static void main(String[] args) { + + // These are the moves the user makes + String playerMove; + + // These are the moves the computer makes + String computerMove = ""; + // Randomly generated number mapped to the computer's move + int computerInt; + + Scanner scan = new Scanner(System.in); + Random generator = new Random(); + + // These are the valid strings the user can input + String Rock; + String Paper; + String Scissors; + + // Invite user to play + System.out.println("Hey! Let's play Rock Paper Scissors."); + System.out.println("Please enter your move as R for Rock, P for Paper, and S for Scissors."); + System.out.println("Good Luck!"); + + System.out.println(); + + // Generate computer's move (0,1,2) + computerInt = generator.nextInt(3) + 1; + + // Translate computer's randomly generated move to string + + if (computerInt == 1) + computerMove = "Rock"; + else if (computerInt == 2) + computerMove = "Paper"; + else if (computerInt == 3) + computerMove = "Scissors"; + + // Get player's move from input + System.out.println("Make your move: "); + playerMove = scan.next(); + + // Translate player's move to input to "Rock" string + if (playerMove == "r" || playerMove == "R") { + playerMove = "Rock"; + } + + // Translate player's move to input to "Paper" string + else if (playerMove == "p" || playerMove == "P") { + playerMove = "Paper"; + } + + // Translate player's move to input to "Scissors" string + else if (playerMove == "s" || playerMove == "S") { + playerMove = "Scissors"; + } + + // Message that every other input is invalid + boolean invalidMove = false; + if (!playerMove.equals("R") && !playerMove.equals("P") && !playerMove.equals("S")) { + System.out.println("Invalid move. Try again."); + invalidMove = true; + } + + while (invalidMove) { + System.out.println("Please enter your move as R for Rock, P for Paper, and S for Scissors."); + System.out.println("Make your move: "); + playerMove = scan.next(); + if (playerMove.equals("R") || playerMove.equals("P") || playerMove.equals("S")) { + invalidMove = false; + } + } + + // Translate player's move to input to "Rock" string AGAIN + if (playerMove == "r" || playerMove == "R") { + playerMove = "Rock"; + } + + // Translate player's move to input to "Paper" string AGAIN + else if (playerMove == "p" || playerMove == "P") { + playerMove = "Paper"; + } + + // Translate player's move to input to "Scissors" string AGAIN + else if (playerMove == "s" || playerMove == "S") { + playerMove = "Scissors"; + } + + + // Show computer's move + System.out.println("Computer's move is: " + computerMove); + + // Figure out the winner using nested conditional statements. + // Player move and Computer move are the same + if (playerMove.equals(computerMove)) { + System.out.println("It's a tie!"); + } + + // Player move is rock + else if (playerMove.equals("R")) { + if (computerMove.equals("Scissors")) + System.out.println("Rock crushes scissors. You win!"); + else if (computerMove.equals("Paper")) + System.out.println("Paper covers rock. You lose."); + } + + // Player move is paper + else if (playerMove.equals("P")) { + if (computerMove.equals("Scissors")) + System.out.println("Scissors cut paper. You lose."); + else if (computerMove.equals("Rock")) + System.out.println("Paper covers rock. You win!"); + } + + // Player move is scissors + else if (playerMove.equals("S")) { + if (computerMove.equals("Paper")) + System.out.println("Scissors cut paper. You win!"); + else if (computerMove.equals("Rock")) + System.out.println("Rock breaks scissors. You lose."); + } + scan.close(); + } +} From 61a437c9551f7327af417290cc4ca97c63fe4a13 Mon Sep 17 00:00:00 2001 From: Desangles Date: Sat, 26 Jan 2019 12:36:56 -0600 Subject: [PATCH 4/7] Pig Latin --- PigLatin/.classpath | 6 ++ PigLatin/.gitignore | 1 + PigLatin/.project | 17 ++++++ PigLatin/.settings/org.eclipse.jdt.core.prefs | 11 ++++ PigLatin/src/PigLatin.java | 57 +++++++++++++++++++ 5 files changed, 92 insertions(+) create mode 100644 PigLatin/.classpath create mode 100644 PigLatin/.gitignore create mode 100644 PigLatin/.project create mode 100644 PigLatin/.settings/org.eclipse.jdt.core.prefs create mode 100644 PigLatin/src/PigLatin.java diff --git a/PigLatin/.classpath b/PigLatin/.classpath new file mode 100644 index 0000000..51a8bba --- /dev/null +++ b/PigLatin/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/PigLatin/.gitignore b/PigLatin/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/PigLatin/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/PigLatin/.project b/PigLatin/.project new file mode 100644 index 0000000..1221824 --- /dev/null +++ b/PigLatin/.project @@ -0,0 +1,17 @@ + + + PigLatin + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/PigLatin/.settings/org.eclipse.jdt.core.prefs b/PigLatin/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..3a21537 --- /dev/null +++ b/PigLatin/.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/PigLatin/src/PigLatin.java b/PigLatin/src/PigLatin.java new file mode 100644 index 0000000..f31ec84 --- /dev/null +++ b/PigLatin/src/PigLatin.java @@ -0,0 +1,57 @@ +import java.util.Scanner; + +public class PigLatin { + + public static void main(String[] args) { + + Scanner scan = new Scanner(System.in); + + // Ask user for a word + System.out.println("Enter a word to translate it into Pig Latin."); + + // This variable holds the word the user inputs and converts it to a string + String userWord = scan.next(); + + // Let's ensure legibility by converting the user's input into lower case + userWord = userWord.toLowerCase(); + + // This is the variable that holds the user's word translated into Pig Latin + String translatedWord = ""; + + // Let's assume there are no vowels in userWord and set the value of int to 0 + int flag = 0; + + // Let's iterate through the string to find the first vowel as defined by x. + for (int i = 0; i < userWord.length(); i++) { + char x = userWord.charAt(i); + if (x == 'a' || x == 'e' || x == 'i' || x == 'o' || x == 'u') { + /* + * Make the translation by creating a substring of all the letters up to the + * first vowel moving these to the end of the original string, and appending + * 'ay' after that. + */ + translatedWord = userWord.substring(i) + userWord.substring(0, i) + "ay"; + + // Change flag to 1 to indicate userWord has been translated and break the loop. + flag = 1; + break; + + } + } + + /* + * if there are no vowels in userWord, flag remains 0 and the word isn't + * translated. To translate a vowel-less userWord, append 'ay' to the end. + */ + if (flag == 0) { + translatedWord = userWord + "ay"; + } + + // Show the user's word translated into Pig Latin + System.out.println("That word translated into Pig Latin is: " + translatedWord); + + scan.close(); + + } + +} From 374727eb174a936677c9d4b446a1720cd0d54802 Mon Sep 17 00:00:00 2001 From: Desangles Date: Fri, 8 Feb 2019 16:55:15 -0600 Subject: [PATCH 5/7] Assessment my ass! This was totally a test. --- TimesheetApp/.classpath | 6 + TimesheetApp/.gitignore | 1 + TimesheetApp/.project | 17 +++ .../.settings/org.eclipse.jdt.core.prefs | 11 ++ TimesheetApp/src/ConsoleUtils.java | 114 +++++++++++++++ TimesheetApp/src/Controller.java | 133 ++++++++++++++++++ TimesheetApp/src/Main.java | 132 +++++++++++++++++ TimesheetApp/src/Timesheet.java | 6 + TimesheetApp/src/TimesheetEntry.java | 58 ++++++++ 9 files changed, 478 insertions(+) create mode 100644 TimesheetApp/.classpath create mode 100644 TimesheetApp/.gitignore create mode 100644 TimesheetApp/.project create mode 100644 TimesheetApp/.settings/org.eclipse.jdt.core.prefs create mode 100644 TimesheetApp/src/ConsoleUtils.java create mode 100644 TimesheetApp/src/Controller.java create mode 100644 TimesheetApp/src/Main.java create mode 100644 TimesheetApp/src/Timesheet.java create mode 100644 TimesheetApp/src/TimesheetEntry.java 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..81e7fc3 --- /dev/null +++ b/TimesheetApp/src/ConsoleUtils.java @@ -0,0 +1,114 @@ +/*This is where we manage everything related to console printing. +No need to initialize a Scanner. Just make calls to the appropriate ConsoleUtils method to print to the console.*/ + +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 < longestProject; i++) { + projectUnderline += "-"; + } + + String taskHeader = String.format("%" + longestTask + "s", "Task"); + String taskUnderline = ""; + for (int i = 0; i < longestTask; i++) { + taskUnderline += "-"; + } + + System.out.println(" ID | " + projectHeader + " | " + taskHeader + " | Start | End "); + System.out.println("----+-" + projectUnderline + "-+-" + taskUnderline + "-+----------------+----------------"); + + for (TimesheetEntry entry : entries) { + String project = String.format("%-" + longestProject + "s", entry.getProjectName()); + String task = String.format("%-" + longestTask + "s", entry.getTask()); + String startTime = entry.getStartTime().format(timeFormatter); + String endTime = ""; + if (entry.getEndTime() != null) { + endTime = entry.getEndTime().format(timeFormatter); + } + String line = String.format(" %2s | %s | %s | %s | %s ", entry.getId(), project, task, startTime, endTime); + System.out.println(line); + } + + if (entries.size() == 1) { + System.out.println("[1 entry]"); + } else { + System.out.println("[" + entries.size() + " entries]"); + } + + System.out.println(); + } +} \ No newline at end of file diff --git a/TimesheetApp/src/Controller.java b/TimesheetApp/src/Controller.java new file mode 100644 index 0000000..5a0dba6 --- /dev/null +++ b/TimesheetApp/src/Controller.java @@ -0,0 +1,133 @@ +//This file interprets user inputs and makes the appropriate changes to the timesheet based on user actions + +import java.util.List; + +public class Controller { + + /* Member variables */ + + Timesheet timesheet; + ConsoleUtils consoleUtils; + + /* Constructor */ + + public Controller() { + this.timesheet = new Timesheet(); + this.consoleUtils = new ConsoleUtils(); + } + + /* Methods */ + + /* + * Runs the program + */ + public void start() { + + consoleUtils.printHelp(); // Print the action menu + + boolean quit = false; + while (!quit) { + + // Prompt the user for input, collect input, parse into parts + String input = consoleUtils.promptString("> "); + String[] actionParts = input.split(" "); + String action = actionParts[0].trim(); // Primary action + + // Figure out what to do depending on the user's primary action + 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")) { + + // Your code here + + } else if (action.equals("help")) { + + // Your code here + + } else if (action.length() == 0) { + + // do nothing. + + } else { + + // Your code here + + } + } + + } + + /* + * The user requested that a given TimesheetEntry be stopped (marked as + * complete) This method conveys that request to the Timesheet + */ + public void processStopAction(String[] actionParts) { + + if (actionParts.length > 2) { + consoleUtils.error("Too many inputs to stop command"); + return; + } + + int id = Integer.parseInt(actionParts[1]); + + // Your code here + } + + /* + * The user requested that a given TimesheetEntry be deleted This method conveys + * that request to the Timesheet + */ + public void processDeleteAction(String[] actionParts) { + + if (actionParts.length > 2) { + consoleUtils.error("Too many inputs to delete command"); + return; + } + + int id = Integer.parseInt(actionParts[1]); + + // Your code here + } + + /* + * The user wants to view a list of timesheet entries This method conveys that + * request to the Timesheet, along with any special options (active-only, filter + * by project name) + */ + public void processListAction(String[] actionParts) { + + if (actionParts.length > 3) { + consoleUtils.error("Too many inputs to list command"); + return; + } + + // Your code here + } + + /* + * The user wants to add a new entry to the Timesheet This method conveys that + * request to the Timesheet, along with the specified project name and task + * description + */ + public void processAddAction() { + + String project = consoleUtils.promptString("Project Name (one word only):"); + String description = consoleUtils.promptString("Task:"); + + // Your code here + } +} \ No newline at end of file diff --git a/TimesheetApp/src/Main.java b/TimesheetApp/src/Main.java new file mode 100644 index 0000000..bd05245 --- /dev/null +++ b/TimesheetApp/src/Main.java @@ -0,0 +1,132 @@ + +import java.util.List; + +public class Controller { + + /* Member variables */ + + Timesheet timesheet; + ConsoleUtils consoleUtils; + + /* Constructor */ + + public Controller(){ + this.timesheet = new Timesheet(); + this.consoleUtils = new ConsoleUtils(); + } + + /* Methods */ + + /* + * Runs the program + */ + public void start() { + + consoleUtils.printHelp(); // Print the action menu + + boolean quit = false; + while(!quit) { + + // Prompt the user for input, collect input, parse into parts + String input = consoleUtils.promptString("> "); + String[] actionParts = input.split(" "); + String action = actionParts[0].trim(); // Primary action + + // Figure out what to do depending on the user's primary action + 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")) { + + // Your code here + + } else if (action.equals("help")) { + + // Your code here + + } else if(action.length() ==0 ){ + + // do nothing. + + } else { + + // Your code here + + } + } + + } + + /* + * The user requested that a given TimesheetEntry be stopped (marked as complete) + * This method conveys that request to the Timesheet + */ + public void processStopAction(String[] actionParts){ + + if(actionParts.length > 2){ + consoleUtils.error("Too many inputs to stop command"); + return; + } + + int id = Integer.parseInt(actionParts[1]); + + // Your code here + } + + /* + * The user requested that a given TimesheetEntry be deleted + * This method conveys that request to the Timesheet + */ + public void processDeleteAction(String[] actionParts){ + + if(actionParts.length > 2){ + consoleUtils.error("Too many inputs to delete command"); + return; + } + + int id = Integer.parseInt(actionParts[1]); + + // Your code here + } + + /* + * The user wants to view a list of timesheet entries + * This method conveys that request to the Timesheet, + * along with any special options (active-only, filter by project name) + */ + public void processListAction(String[] actionParts){ + + if(actionParts.length > 3){ + consoleUtils.error("Too many inputs to list command"); + return; + } + + // Your code here + } + + /* + * The user wants to add a new entry to the Timesheet + * This method conveys that request to the Timesheet, along with + * the specified project name and task description + */ + public void processAddAction(){ + + String project = consoleUtils.promptString("Project Name (one word only):"); + String description = consoleUtils.promptString("Task:"); + + // Your code here + } +} \ No newline at end of file diff --git a/TimesheetApp/src/Timesheet.java b/TimesheetApp/src/Timesheet.java new file mode 100644 index 0000000..418d156 --- /dev/null +++ b/TimesheetApp/src/Timesheet.java @@ -0,0 +1,6 @@ + +public class Timesheet { + + + +} diff --git a/TimesheetApp/src/TimesheetEntry.java b/TimesheetApp/src/TimesheetEntry.java new file mode 100644 index 0000000..06bc458 --- /dev/null +++ b/TimesheetApp/src/TimesheetEntry.java @@ -0,0 +1,58 @@ + +import java.time.LocalDateTime; + +public class TimesheetEntry { + + // Static variable that belongs with the TimesheetEntry class + private static int NEXTID = 1; + + // Timesheet member variables + private String projectName; + private String task; + private int id; + private LocalDateTime startTime; + private LocalDateTime endTime; + + // Here's my constructor. It initializes the variables projectName, task, + // startTime, and ID. NEXTID is incremented + public TimesheetEntry(String myProject, String myTask) { + projectName = myProject; + task = myTask; + startTime = LocalDateTime.now(); + id = NEXTID; + NEXTID++; // increment + + } + + // Here are my Methods. + // This group of methods implements Getters for all five variables + + public String getProjectName() { + return projectName; + } + + public String getTask() { + return task; + } + + public int getId() { + return id; + } + + public LocalDateTime getStartTime() { + return startTime; + } + + public LocalDateTime getEndTime() { + return endTime; + } + + // Here's my UpdateEndtime method. It sets endTime to LocalTime now if it hasn't already been set + public void updateEndTime() { + if (endTime == null) { + endTime = LocalDateTime.now(); + } + + } + +} From fea9165251a74d2e5073ffbd7dac2bad08fdf695 Mon Sep 17 00:00:00 2001 From: Desangles Date: Fri, 8 Feb 2019 19:21:37 -0600 Subject: [PATCH 6/7] Here's my TicTacToe project --- TicTacToe/.classpath | 6 + TicTacToe/.gitignore | 1 + TicTacToe/.project | 17 +++ .../.settings/org.eclipse.jdt.core.prefs | 11 ++ TicTacToe/src/TicTacToe.java | 142 ++++++++++++++++++ 5 files changed, 177 insertions(+) create mode 100644 TicTacToe/.classpath create mode 100644 TicTacToe/.gitignore create mode 100644 TicTacToe/.project create mode 100644 TicTacToe/.settings/org.eclipse.jdt.core.prefs create mode 100644 TicTacToe/src/TicTacToe.java diff --git a/TicTacToe/.classpath b/TicTacToe/.classpath new file mode 100644 index 0000000..51a8bba --- /dev/null +++ b/TicTacToe/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/TicTacToe/.gitignore b/TicTacToe/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/TicTacToe/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/TicTacToe/.project b/TicTacToe/.project new file mode 100644 index 0000000..d6bf9b5 --- /dev/null +++ b/TicTacToe/.project @@ -0,0 +1,17 @@ + + + TicTacToe + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/TicTacToe/.settings/org.eclipse.jdt.core.prefs b/TicTacToe/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..3a21537 --- /dev/null +++ b/TicTacToe/.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/TicTacToe/src/TicTacToe.java b/TicTacToe/src/TicTacToe.java new file mode 100644 index 0000000..cbb97aa --- /dev/null +++ b/TicTacToe/src/TicTacToe.java @@ -0,0 +1,142 @@ + +// Import this Java program to read data (input from the user) using the Scanner class +import java.util.Scanner; + +public class TicTacToe { + + // Public static variables of varying types that belong to the TicTacToe class + public static char[][] board; + public static Scanner reader = new Scanner(System.in); + public static int movesPlayed = 0; + + + // Let's modify the 'main' method so that it initializes a couple of objects + public static void main(String[] args) { + board = new char[3][3]; + char player = 'X'; + + System.out.println("Let's play tic-tac-toe!"); + System.out.println("You be Xs and I'll be Os"); + + printBoard(); + + //Create a new integer array called 'move' that holds 2 items + int[] move = new int[2]; + + ticTacToe(player, move); + } + + public static void printBoard() { + System.out.println("\n 0 1 2"); + System.out.println("0 " + board[0][0] + " | " + board[0][1] + " | " + board[0][2]); + System.out.println(" ---------"); + System.out.println("1 " + board[1][0] + " | " + board[1][1] + " | " + board[1][2]); + System.out.println(" ---------"); + System.out.println("2 " + board[2][0] + " | " + board[2][1] + " | " + board[2][2] + "\n"); + } + + public static void ticTacToe(char player, int[] move) { + // Ask user for move + receiveInput(player, move); + + // Check for legal move + if (isMoveLegal(move)) { + board[move[0]][move[1]] = player; + printBoard(); + + // Check for win or tie + if (checkForWin(player)) { + winner(player); + } else if (movesPlayed == 8) { + tie(); + } else { + movesPlayed++; + player = player == 'X' ? 'O' : 'X'; + + System.out.println("It's " + player + "'s turn."); + ticTacToe(player, move); + } + + } else { + System.out.println(board[move[0]][move[1]] + " is already in that position. Choose another:"); + ticTacToe(player, move); + } + } + + public static void receiveInput(char player, int[] move) { + // Ask for move + System.out.println("Player " + player + "'s move. \n Enter a row (0 - 2):"); + + // Take input from user + int row = reader.nextInt(); + System.out.println("Enter a column (0 - 2):"); + int column = reader.nextInt(); + + // Store user's move in array + move[0] = row; + move[1] = column; + } + + public static boolean isMoveLegal(int[] move) { + int row = move[0]; + int col = move[1]; + if (board[row][col] == 'X' || board[row][col] == 'O') { + return false; + } else { + return true; + } + } + + public static boolean checkForWin(char player) { + if (verticalWin(player)) { + return true; + } else if (horizontalWin(player)) { + return true; + } else if (diagonalWin(player)) { + return true; + } else { + return false; + } + } + + public static boolean verticalWin(char player) { + for (int i = 0; i < board.length; i++) { + if (board[0][i] == player && board[1][i] == player && board[2][i] == player) { + return true; + } + } + + return false; + } + + public static boolean horizontalWin(char player) { + for (int i = 0; i < board.length; i++) { + if (board[i][0] == player && board[i][1] == player && board[i][2] == player) { + return true; + } + } + + return false; + } + + public static boolean diagonalWin(char player) { + if (board[0][0] == player && board[1][1] == player && board[2][2] == player) { + return true; + } else if (board[0][2] == player && board[1][1] == player && board[2][0] == player) { + return true; + } else { + return false; + } + } + + public static void tie() { + System.out.println("Tie!"); + reader.close(); + } + + public static void winner(char player) { + System.out.println(player + " wins!"); + reader.close(); + } + +} \ No newline at end of file From 55fdb1f4716cafc911a49081b7386ea7309e6ec4 Mon Sep 17 00:00:00 2001 From: Desangles Date: Wed, 20 Feb 2019 22:14:31 -0600 Subject: [PATCH 7/7] Statistics & Gradebook --- .gitignore | 2 + FunWithStrings/.classpath | 6 + FunWithStrings/.gitignore | 1 + FunWithStrings/.project | 17 +++ .../.settings/org.eclipse.jdt.core.prefs | 11 ++ FunWithStrings/src/FunWithStrings.java | 9 ++ GradeBook/.classpath | 6 + GradeBook/.gitignore | 1 + GradeBook/.project | 17 +++ .../.settings/org.eclipse.jdt.core.prefs | 11 ++ GradeBook/src/GradeBook.java | 79 +++++++++++ RockPaperScissors/src/RockPaperScissors.java | 6 +- RockPaperScissorsExceptions/.classpath | 6 + RockPaperScissorsExceptions/.gitignore | 1 + RockPaperScissorsExceptions/.project | 17 +++ .../.settings/org.eclipse.jdt.core.prefs | 11 ++ .../src/RockPaperScissorsExceptions.java | 128 ++++++++++++++++++ Statistics/.classpath | 6 + Statistics/.gitignore | 1 + Statistics/.project | 17 +++ .../.settings/org.eclipse.jdt.core.prefs | 11 ++ Statistics/src/Statistics.java | 90 ++++++++++++ TimesheetApp/src/TimesheetEntry.java | 3 +- 23 files changed, 452 insertions(+), 5 deletions(-) create mode 100644 .gitignore create mode 100644 FunWithStrings/.classpath create mode 100644 FunWithStrings/.gitignore create mode 100644 FunWithStrings/.project create mode 100644 FunWithStrings/.settings/org.eclipse.jdt.core.prefs create mode 100644 FunWithStrings/src/FunWithStrings.java create mode 100644 GradeBook/.classpath create mode 100644 GradeBook/.gitignore create mode 100644 GradeBook/.project create mode 100644 GradeBook/.settings/org.eclipse.jdt.core.prefs create mode 100644 GradeBook/src/GradeBook.java create mode 100644 RockPaperScissorsExceptions/.classpath create mode 100644 RockPaperScissorsExceptions/.gitignore create mode 100644 RockPaperScissorsExceptions/.project create mode 100644 RockPaperScissorsExceptions/.settings/org.eclipse.jdt.core.prefs create mode 100644 RockPaperScissorsExceptions/src/RockPaperScissorsExceptions.java create mode 100644 Statistics/.classpath create mode 100644 Statistics/.gitignore create mode 100644 Statistics/.project create mode 100644 Statistics/.settings/org.eclipse.jdt.core.prefs create mode 100644 Statistics/src/Statistics.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f36c267 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/.metadata/ +/.recommenders/ diff --git a/FunWithStrings/.classpath b/FunWithStrings/.classpath new file mode 100644 index 0000000..51a8bba --- /dev/null +++ b/FunWithStrings/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/FunWithStrings/.gitignore b/FunWithStrings/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/FunWithStrings/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/FunWithStrings/.project b/FunWithStrings/.project new file mode 100644 index 0000000..5a54bad --- /dev/null +++ b/FunWithStrings/.project @@ -0,0 +1,17 @@ + + + FunWithStrings + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/FunWithStrings/.settings/org.eclipse.jdt.core.prefs b/FunWithStrings/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..3a21537 --- /dev/null +++ b/FunWithStrings/.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/FunWithStrings/src/FunWithStrings.java b/FunWithStrings/src/FunWithStrings.java new file mode 100644 index 0000000..fb62240 --- /dev/null +++ b/FunWithStrings/src/FunWithStrings.java @@ -0,0 +1,9 @@ + +public class FunWithStrings { + + public static void main(String[] args) { + // TODO Auto-generated method stub + + } + +} diff --git a/GradeBook/.classpath b/GradeBook/.classpath new file mode 100644 index 0000000..51a8bba --- /dev/null +++ b/GradeBook/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/GradeBook/.gitignore b/GradeBook/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/GradeBook/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/GradeBook/.project b/GradeBook/.project new file mode 100644 index 0000000..53d01ac --- /dev/null +++ b/GradeBook/.project @@ -0,0 +1,17 @@ + + + GradeBook + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/GradeBook/.settings/org.eclipse.jdt.core.prefs b/GradeBook/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..3a21537 --- /dev/null +++ b/GradeBook/.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/GradeBook/src/GradeBook.java b/GradeBook/src/GradeBook.java new file mode 100644 index 0000000..88dcf1c --- /dev/null +++ b/GradeBook/src/GradeBook.java @@ -0,0 +1,79 @@ +import java.util.Scanner; +import java.util.ArrayList; +import java.util.HashMap; + + public class GradeBook { + + //Create static String for the grades + static HashMap gradeBook = new HashMap(); + static HashMap gradePointAverage = new HashMap(); + + // Obligatory main method + public static void main(String[] args) { + + // Initialize the fields + inputGrades(); + makeStringArray(); + printGrades(); + } + + //Store the name + grades for each student + public static void inputGrades() { + Scanner reader = new Scanner(System.in); + System.out.println("How many students will be added to the grade book?"); + Integer numberOfStudents = reader.nextInt(); + reader.nextLine(); + for (int i=0; i + + + + + diff --git a/RockPaperScissorsExceptions/.gitignore b/RockPaperScissorsExceptions/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/RockPaperScissorsExceptions/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/RockPaperScissorsExceptions/.project b/RockPaperScissorsExceptions/.project new file mode 100644 index 0000000..cdb252b --- /dev/null +++ b/RockPaperScissorsExceptions/.project @@ -0,0 +1,17 @@ + + + RockPaperScissorsExceptions + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/RockPaperScissorsExceptions/.settings/org.eclipse.jdt.core.prefs b/RockPaperScissorsExceptions/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..3a21537 --- /dev/null +++ b/RockPaperScissorsExceptions/.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/RockPaperScissorsExceptions/src/RockPaperScissorsExceptions.java b/RockPaperScissorsExceptions/src/RockPaperScissorsExceptions.java new file mode 100644 index 0000000..b369b56 --- /dev/null +++ b/RockPaperScissorsExceptions/src/RockPaperScissorsExceptions.java @@ -0,0 +1,128 @@ +import java.util.Random; +import java.util.Scanner; + +public class RockPaperScissorsExceptions { + public static void main(String[] args) { + + // Start game + System.out.println("Hey! Let's play Rock Paper Scissors."); + System.out.println("Please enter your move as R for Rock, P for Paper, and S for Scissors."); + System.out.println("Good Luck!"); + + System.out.println(); + + // These are the moves the user makes + String playerMove; + + // These are the moves the computer makes + String computerMove = ""; + // Randomly generated number mapped to the computer's move + int computerInt; + + Scanner scan = new Scanner(System.in); + Random generator = new Random(); + + // These are the valid strings the user can input +// String Rock; +// String Paper; +// String Scissors; + + + // Generate computer's move (0,1,2) + computerInt = generator.nextInt(3) + 1; + + // Translate computer's randomly generated move to string + + if (computerInt == 1) + computerMove = "Rock"; + else if (computerInt == 2) + computerMove = "Paper"; + else if (computerInt == 3) + computerMove = "Scissors"; + + // Get player's move from input + System.out.println("Make your move: "); + playerMove = scan.next(); + + // Translate player's move to input to "Rock" string + if (playerMove == "r" || playerMove == "R") { + playerMove = "Rock"; + } + + // Translate player's move to input to "Paper" string + else if (playerMove == "p" || playerMove == "P") { + playerMove = "Paper"; + } + + // Translate player's move to input to "Scissors" string + else if (playerMove == "s" || playerMove == "S") { + playerMove = "Scissors"; + } + + // Message that every other input is invalid + boolean invalidMove = false; + if (!playerMove.equals("R") && !playerMove.equals("P") && !playerMove.equals("S")) { + System.out.println("Invalid move. Try again."); + invalidMove = true; + } + + while (invalidMove) { + System.out.println("Please enter your move as R for Rock, P for Paper, and S for Scissors."); + System.out.println("Make your move: "); + playerMove = scan.next(); + if (playerMove.equals("R") || playerMove.equals("P") || playerMove.equals("S")) { + invalidMove = false; + } + } + + // Translate player's move to input to "Rock" string AGAIN + if (playerMove == "r" || playerMove == "R") { + playerMove = "Rock"; + } + + // Translate player's move to input to "Paper" string AGAIN + else if (playerMove == "p" || playerMove == "P") { + playerMove = "Paper"; + } + + // Translate player's move to input to "Scissors" string AGAIN + else if (playerMove == "s" || playerMove == "S") { + playerMove = "Scissors"; + } + + + // Show computer's move + System.out.println("Computer's move is: " + computerMove); + + // Figure out the winner using nested conditional statements. + // Player move and Computer move are the same + if (playerMove.equals(computerMove)) { + System.out.println("It's a tie!"); + } + + // Player move is rock + else if (playerMove.equals("R")) { + if (computerMove.equals("Scissors")) + System.out.println("Rock crushes scissors. You win!"); + else if (computerMove.equals("Paper")) + System.out.println("Paper covers rock. You lose."); + } + + // Player move is paper + else if (playerMove.equals("P")) { + if (computerMove.equals("Scissors")) + System.out.println("Scissors cut paper. You lose."); + else if (computerMove.equals("Rock")) + System.out.println("Paper covers rock. You win!"); + } + + // Player move is scissors + else if (playerMove.equals("S")) { + if (computerMove.equals("Paper")) + System.out.println("Scissors cut paper. You win!"); + else if (computerMove.equals("Rock")) + System.out.println("Rock breaks scissors. You lose."); + } + scan.close(); + } +} diff --git a/Statistics/.classpath b/Statistics/.classpath new file mode 100644 index 0000000..51a8bba --- /dev/null +++ b/Statistics/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/Statistics/.gitignore b/Statistics/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/Statistics/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/Statistics/.project b/Statistics/.project new file mode 100644 index 0000000..e98850d --- /dev/null +++ b/Statistics/.project @@ -0,0 +1,17 @@ + + + Statistics + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/Statistics/.settings/org.eclipse.jdt.core.prefs b/Statistics/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..3a21537 --- /dev/null +++ b/Statistics/.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/Statistics/src/Statistics.java b/Statistics/src/Statistics.java new file mode 100644 index 0000000..e096264 --- /dev/null +++ b/Statistics/src/Statistics.java @@ -0,0 +1,90 @@ +import java.util.*; + +public class Statistics { + + public static void main(String[] args) { + + // Used to read input from the user + Scanner reader = new Scanner(System.in); + + // Used to print out text to the user + System.out.println("Please enter a list of numbers."); + + // nextLine() reads the whole String including blank spaces + String submittedNumbers = reader.nextLine(); + + // close the reader + reader.close(); + + // convert the string to an string array and split it w/commas + String[] stringArray = submittedNumbers.split(","); + + // print out the users input + System.out.println(stringArray); + + // Print out the count of the number of values the user input + System.out.println("You entered " + stringArray.length + " numbers."); + + // Print out the minimum value in the array + System.out.println("Minimum is " + returnMin(stringArray)); + + // Print out the maximum value in the array + System.out.println("Maximum is " + returnMax(stringArray)); + + // Print out the average value of the array + System.out.println("Average is " + returnAverage(stringArray)); + + // Print out the sum of the values in the array + System.out.println("Sum is " + returnSum(stringArray)); + } + + // Parse the string array, convert each value to int, and loop through to return the minimum value + public static int returnMin(String[] array) { + int minimum = 0; + + for (int i = 0; i < array.length; i++) { + int currentNum = Integer.parseInt(array[i]); + if (i == 0 || currentNum < minimum) { + minimum = currentNum; + } + } + + return minimum; + } + + // Parse the string array, convert each value to int, and loop through to return the max value + public static int returnMax(String[] array) { + int maximum = 0; + + for (int i = 0; i < array.length; i++) { + int currentNum = Integer.parseInt(array[i]); + if (i == 0 || currentNum > maximum) { + maximum = currentNum; + } + } + + return maximum; + } + + // Parse the string array, convert each value to float, and loop through to return the avg value + public static float returnAverage(String[] array) { + float total = 0; + + for (int i = 0; i < array.length; i++) { + total += Integer.parseInt(array[i]); + } + + return total / array.length; + } + + // Parse the string array, convert each value to int, and loop through to return the sum total + public static int returnSum(String[] array) { + int total = 0; + for (int i = 0; i < array.length; i++) { + total += Integer.parseInt(array[i]); + } + + return total; + } + +} \ No newline at end of file diff --git a/TimesheetApp/src/TimesheetEntry.java b/TimesheetApp/src/TimesheetEntry.java index 06bc458..0eb393a 100644 --- a/TimesheetApp/src/TimesheetEntry.java +++ b/TimesheetApp/src/TimesheetEntry.java @@ -13,8 +13,7 @@ public class TimesheetEntry { private LocalDateTime startTime; private LocalDateTime endTime; - // Here's my constructor. It initializes the variables projectName, task, - // startTime, and ID. NEXTID is incremented + // My constructor initializes the variables projectName, task, startTime, and ID public TimesheetEntry(String myProject, String myTask) { projectName = myProject; task = myTask;