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/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 diff --git a/Calculator/bin/Calculator.class b/Calculator/bin/Calculator.class new file mode 100644 index 0000000..bb96153 Binary files /dev/null and b/Calculator/bin/Calculator.class differ diff --git a/Calculator/src/Calculator.java b/Calculator/src/Calculator.java new file mode 100644 index 0000000..56b25cc --- /dev/null +++ b/Calculator/src/Calculator.java @@ -0,0 +1,39 @@ +import java.util.Scanner; + +public class Calculator { + public static void main(String[] args) { + + Scanner input = new Scanner(System.in); + + // Get first number + System.out.println("Please enter the first number: "); + int num1 = input.nextInt(); + + // Get second number + System.out.println("Please enter the second number: "); + int num2 = input.nextInt(); + + // Add the numbers together + int add = num1 + num2; + // Print out sum + System.out.println("The sum of those numbers is: " +add); + + // Subtract the second number from the first + int subtract = num1 - num2; + // Print out subtraction + System.out.println("The difference between those numbers is: " +subtract); + + // Multiply the numbers + int multiply = num1 * num2; + // Print out multiplication + System.out.println("The product of those numbers is: " +multiply); + + // Divide the numbers + int divide = num1 / num2; + // Print out quotient + System.out.println("The quotient of those numbers is: " +divide); + + input.close(); + } + +} 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/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(); + + } + +} 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..20e3bc4 --- /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(); + } +} diff --git a/RockPaperScissorsExceptions/.classpath b/RockPaperScissorsExceptions/.classpath new file mode 100644 index 0000000..51a8bba --- /dev/null +++ b/RockPaperScissorsExceptions/.classpath @@ -0,0 +1,6 @@ + + + + + + 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/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 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..0eb393a --- /dev/null +++ b/TimesheetApp/src/TimesheetEntry.java @@ -0,0 +1,57 @@ + +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; + + // My constructor initializes the variables projectName, task, startTime, and ID + 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(); + } + + } + +}