From f734f7d09e27509c82ab324ba807ca3d4d8205dc Mon Sep 17 00:00:00 2001 From: mahala Date: Thu, 9 Apr 2026 18:03:09 -0400 Subject: [PATCH 1/3] added my name --- .travis.yml | 4 - .../com/github/zipcodewilmington/Console.jave | 0 .../github/zipcodewilmington/WordGuess.java | 1 + .../zipcodewilmington/sample/Person.java | 245 +++++++++++++++++- .../sample/Edited Person Library 1 | 46 ++++ .../sample/Projects.code-workspace | 10 + 6 files changed, 301 insertions(+), 5 deletions(-) create mode 100644 java/src/main/java/com/github/zipcodewilmington/Console.jave create mode 100644 java/src/test/java/com/github/zipcodewilmington/sample/Edited Person Library 1 create mode 100644 java/src/test/java/com/github/zipcodewilmington/sample/Projects.code-workspace diff --git a/.travis.yml b/.travis.yml index 962bba1..e69de29 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +0,0 @@ -language: java -jdk: openjdk8 -after_success: - - mvn coveralls:report \ No newline at end of file diff --git a/java/src/main/java/com/github/zipcodewilmington/Console.jave b/java/src/main/java/com/github/zipcodewilmington/Console.jave new file mode 100644 index 0000000..e69de29 diff --git a/java/src/main/java/com/github/zipcodewilmington/WordGuess.java b/java/src/main/java/com/github/zipcodewilmington/WordGuess.java index 6f5485f..a0c708e 100644 --- a/java/src/main/java/com/github/zipcodewilmington/WordGuess.java +++ b/java/src/main/java/com/github/zipcodewilmington/WordGuess.java @@ -6,3 +6,4 @@ * @date 5/27/21 11:02 AM */ public class WordGuess {} +//Mahala// \ No newline at end of file diff --git a/java/src/main/java/com/github/zipcodewilmington/sample/Person.java b/java/src/main/java/com/github/zipcodewilmington/sample/Person.java index 48d7e4b..3d428c9 100644 --- a/java/src/main/java/com/github/zipcodewilmington/sample/Person.java +++ b/java/src/main/java/com/github/zipcodewilmington/sample/Person.java @@ -1,4 +1,247 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + package com.github.zipcodewilmington.sample; public class Person { -} \ No newline at end of file +} + + +public class Address[] + //Instance vairables + private String street; + private String city; + private String state; + private String zipCode; + + //Defalut Setting +public Address() { + this.street = ""; + this.city = ""; + this.state = ""; + this.zipCode = ""; + } + + //Parameterized Constructor + public Address(String street, String city, String state, String zipCode) { + this.street = street; + this.city = city; + this.state = state; + this.zipCode = zipCode; + } + + //Getter + public String getStreet() { + return street; + } + public String getCity() { + return city; + } + public String getState() { + return state; + } + public String getZipcode() { + return zipCode; + } + //Override for cleaner view + public String toString() { + return street + ", " + city + ", " + state + " " + zipCode; + } +} + diff --git a/java/src/test/java/com/github/zipcodewilmington/sample/Edited Person Library 1 b/java/src/test/java/com/github/zipcodewilmington/sample/Edited Person Library 1 new file mode 100644 index 0000000..93bb055 --- /dev/null +++ b/java/src/test/java/com/github/zipcodewilmington/sample/Edited Person Library 1 @@ -0,0 +1,46 @@ +package com.zipcodewilmington.centrallibrary; + +public class Person {} + +public class Address { + //Instance vairables + private String street; + private String city; + private String state; + private String zipCode; + + //Defalut Setting +public Address() { + this.street = ""; + this.city = ""; + this.state = ""; + this.zipCode = ""; + } + + //Parameterized Constructor + public Address(String street, String city, String state, String zipCode) { + this.street = street; + this.city = city; + this.state = state; + this.zipCode = zipCode; + } + + //Getter + public String gitStreet() { + return street; + } + public String gitCity() { + return city; + } + public String gitState() { + return state; + } + public String gitZipcode() { + return zipCode; + } + //Override for cleaner view + public String AddressString() { + return street + ", " + city + ", " + state + ", " + zipCode; + } +} + diff --git a/java/src/test/java/com/github/zipcodewilmington/sample/Projects.code-workspace b/java/src/test/java/com/github/zipcodewilmington/sample/Projects.code-workspace new file mode 100644 index 0000000..5b9efb2 --- /dev/null +++ b/java/src/test/java/com/github/zipcodewilmington/sample/Projects.code-workspace @@ -0,0 +1,10 @@ +{ + "folders": [ + { + "path": "../../../../../../../../.." + }, + { + "path": "../../../../../../../../../bluebook1" + } + ] +} \ No newline at end of file From 3db497742659dce0bcd6f9939ad8ea3bc937f95d Mon Sep 17 00:00:00 2001 From: mahala Date: Thu, 9 Apr 2026 20:04:44 -0400 Subject: [PATCH 2/3] Version 2.0 --- java/pom.xml | 34 +-- .../com/github/zipcodewilmington/Console.java | 1 + .../com/github/zipcodewilmington/Console.jave | 0 .../github/zipcodewilmington/WordGuess.java | 137 ++++++++- .../zipcodewilmington/sample/Person.java | 266 +++--------------- 5 files changed, 174 insertions(+), 264 deletions(-) create mode 100644 java/src/main/java/com/github/zipcodewilmington/Console.java delete mode 100644 java/src/main/java/com/github/zipcodewilmington/Console.jave diff --git a/java/pom.xml b/java/pom.xml index 963bccc..4a888b7 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -11,47 +11,33 @@ 11 11 + 5.7.0 + 2.12.3 + org.apache.maven.plugins maven-compiler-plugin - 3.8.0 + 3.8.1 11 + - - org.apache.maven.plugins - maven-compiler-plugin - 3.8.1 - - - junit - junit - 4.12 - test - + junit junit 4.12 test - - junit - junit - 4.12 - test - - - - + org.junit.jupiter junit-jupiter-params @@ -59,7 +45,7 @@ test - + org.junit.vintage junit-vintage-engine @@ -67,14 +53,12 @@ test - + com.fasterxml.jackson.core jackson-databind ${jackson.version} - - diff --git a/java/src/main/java/com/github/zipcodewilmington/Console.java b/java/src/main/java/com/github/zipcodewilmington/Console.java new file mode 100644 index 0000000..c61149f --- /dev/null +++ b/java/src/main/java/com/github/zipcodewilmington/Console.java @@ -0,0 +1 @@ +package main.java.com.github.zipcodewilmington; diff --git a/java/src/main/java/com/github/zipcodewilmington/Console.jave b/java/src/main/java/com/github/zipcodewilmington/Console.jave deleted file mode 100644 index e69de29..0000000 diff --git a/java/src/main/java/com/github/zipcodewilmington/WordGuess.java b/java/src/main/java/com/github/zipcodewilmington/WordGuess.java index a0c708e..bbb1a4b 100644 --- a/java/src/main/java/com/github/zipcodewilmington/WordGuess.java +++ b/java/src/main/java/com/github/zipcodewilmington/WordGuess.java @@ -1,9 +1,132 @@ package com.github.zipcodewilmington; -/** - * @author xt0fer - * @version 1.0.0 - * @date 5/27/21 11:02 AM - */ -public class WordGuess {} -//Mahala// \ No newline at end of file +// @author mahala +// @version 2.0.0 + +import java.util.Random; +import java.util.Scanner; + +public class WordGuess { + + // instance variables + private String[] words = {"cat", "dog", "bog", "cut", "hat", "run", "fun", "sun", "big", "dig"}; + private char[] secretWord; + private char[] guesses; + private int triesLeft; + private boolean wordGuessed; + + private Scanner scanner = new Scanner(System.in); + private Random random = new Random(); + + public WordGuess() {} + + public static void main(String[] args) { + WordGuess game = new WordGuess(); + game.runGame(); + } + + public void runGame() { + announceGame(); + boolean playAgain = true; + while (playAgain) { + initializeGameState(); + wordGuessed = false; + + while (triesLeft > 0 && !wordGuessed) { + printCurrentState(); + char guess = getNextGuess(); + + if (guess == '-') { + System.out.println("Quitting game."); + return; + } + + process(guess); + + if (isWordGuessed()) { + wordGuessed = true; + playerWon(); + } else { + triesLeft--; + if (triesLeft == 0) { + playerLost(); + } + } + } + + playAgain = askToPlayAgain(); + } + gameOver(); + } + + public void announceGame() { + System.out.println("Let's Play Wordguess version 2.0"); + } + + public void gameOver() { + System.out.println("Game Over."); + } + + public void initializeGameState() { + String word = words[random.nextInt(words.length)]; + secretWord = word.toCharArray(); + guesses = new char[secretWord.length]; + for (int i = 0; i < guesses.length; i++) { + guesses[i] = '_'; + } + triesLeft = secretWord.length; + } + + public char getNextGuess() { + System.out.println("Enter a single character: "); + String input = scanner.nextLine().trim(); + if (input.isEmpty()) return ' '; + return input.charAt(0); + } + + public boolean isWordGuessed() { + for (char c : guesses) { + if (c == '_') return false; + } + return true; + } + + public boolean askToPlayAgain() { + System.out.println("Would you like to play again? (yes/no) "); + String answer = scanner.nextLine().trim().toLowerCase(); + return answer.equals("yes"); + } + + public void printCurrentState() { + System.out.println("Current Guesses: "); + printArray(guesses); + System.out.println("You have " + triesLeft + " tries left."); + } + + public void printArray(char[] a) { + for (char c : a) { + System.out.print(c + " "); + } + System.out.println(); + } + + public void process(char guess) { + for (int i = 0; i < secretWord.length; i++) { + if (secretWord[i] == guess) { + guesses[i] = guess; + } + } + } + + public void playerWon() { + System.out.println("**** ****"); + printArray(guesses); + System.out.println("Congratulations, You Won!"); + } + + public void playerLost() { + System.out.println(":-( :-( :-("); + printArray(guesses); + System.out.println("You Lost! You ran out of guesses."); + } +} diff --git a/java/src/main/java/com/github/zipcodewilmington/sample/Person.java b/java/src/main/java/com/github/zipcodewilmington/sample/Person.java index 3d428c9..0a8975c 100644 --- a/java/src/main/java/com/github/zipcodewilmington/sample/Person.java +++ b/java/src/main/java/com/github/zipcodewilmington/sample/Person.java @@ -1,247 +1,49 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - package com.github.zipcodewilmington.sample; -public class Person { -} +public class Person implements PersonInterface { + private String firstName; + private String lastName; + private Integer age; -public class Address[] - //Instance vairables - private String street; - private String city; - private String state; - private String zipCode; + public Person() { + this.firstName = ""; + this.lastName = ""; + this.age = 0; + } - //Defalut Setting -public Address() { - this.street = ""; - this.city = ""; - this.state = ""; - this.zipCode = ""; + @Override + public String getFirstName() { + return firstName; } - //Parameterized Constructor - public Address(String street, String city, String state, String zipCode) { - this.street = street; - this.city = city; - this.state = state; - this.zipCode = zipCode; + @Override + public void setFirstName(String firstName) { + this.firstName = firstName; } - //Getter - public String getStreet() { - return street; + @Override + public String getLastName() { + return lastName; } - public String getCity() { - return city; + + @Override + public void setLastName(String lastName) { + this.lastName = lastName; } - public String getState() { - return state; + + @Override + public Integer getAge() { + return age; } - public String getZipcode() { - return zipCode; + + @Override + public void setAge(Integer age) { + this.age = age; } - //Override for cleaner view + + @Override public String toString() { - return street + ", " + city + ", " + state + " " + zipCode; + return firstName + " " + lastName + ", age " + age; } -} - +} From 258980934ce7f191afdf6711932b5ca4c8bcb5dd Mon Sep 17 00:00:00 2001 From: mahala Date: Thu, 9 Apr 2026 20:30:55 -0400 Subject: [PATCH 3/3] Hangman over with word --- java/.vscode/settings.json | 4 + .../github/zipcodewilmington/WordGuess.java | 56 ++++++++-- java/src/main/resources/words.txt | 102 ++++++++++++++++++ 3 files changed, 156 insertions(+), 6 deletions(-) create mode 100644 java/.vscode/settings.json create mode 100644 java/src/main/resources/words.txt diff --git a/java/.vscode/settings.json b/java/.vscode/settings.json new file mode 100644 index 0000000..47f172f --- /dev/null +++ b/java/.vscode/settings.json @@ -0,0 +1,4 @@ +{ + "java.project.sourcePaths": ["src/main/java"], + "java.project.outputPath": "target/classes" +} diff --git a/java/src/main/java/com/github/zipcodewilmington/WordGuess.java b/java/src/main/java/com/github/zipcodewilmington/WordGuess.java index bbb1a4b..67da60f 100644 --- a/java/src/main/java/com/github/zipcodewilmington/WordGuess.java +++ b/java/src/main/java/com/github/zipcodewilmington/WordGuess.java @@ -3,13 +3,20 @@ // @author mahala // @version 2.0.0 +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.List; import java.util.Random; import java.util.Scanner; public class WordGuess { + private static final int MAX_TRIES = 6; + // instance variables - private String[] words = {"cat", "dog", "bog", "cut", "hat", "run", "fun", "sun", "big", "dig"}; + private String[] words = loadWords(); private char[] secretWord; private char[] guesses; private int triesLeft; @@ -18,6 +25,23 @@ public class WordGuess { private Scanner scanner = new Scanner(System.in); private Random random = new Random(); + private String[] loadWords() { + try { + InputStream is = getClass().getClassLoader().getResourceAsStream("words.txt"); + if (is == null) throw new RuntimeException("words.txt not found"); + BufferedReader reader = new BufferedReader(new InputStreamReader(is)); + List list = new ArrayList<>(); + String line; + while ((line = reader.readLine()) != null) { + line = line.trim(); + if (!line.isEmpty()) list.add(line); + } + return list.toArray(new String[0]); + } catch (Exception e) { + return new String[]{"cat", "dog", "bog", "cut", "hat", "run", "fun", "sun", "big", "dig"}; + } + } + public WordGuess() {} public static void main(String[] args) { @@ -48,12 +72,13 @@ public void runGame() { playerWon(); } else { triesLeft--; - if (triesLeft == 0) { - playerLost(); - } } } + if (!wordGuessed) { + playerLost(); + } + playAgain = askToPlayAgain(); } gameOver(); @@ -74,7 +99,7 @@ public void initializeGameState() { for (int i = 0; i < guesses.length; i++) { guesses[i] = '_'; } - triesLeft = secretWord.length; + triesLeft = MAX_TRIES; } public char getNextGuess() { @@ -98,11 +123,29 @@ public boolean askToPlayAgain() { } public void printCurrentState() { + drawHangman(MAX_TRIES - triesLeft); System.out.println("Current Guesses: "); printArray(guesses); System.out.println("You have " + triesLeft + " tries left."); } + public void drawHangman(int wrong) { + String head = wrong >= 1 ? "O" : " "; + String body = wrong >= 2 ? "|" : " "; + String lArm = wrong >= 3 ? "/" : " "; + String rArm = wrong >= 4 ? "\\" : " "; + String lLeg = wrong >= 5 ? "/" : " "; + String rLeg = wrong >= 6 ? "\\" : " "; + + System.out.println(" _____"); + System.out.println(" | |"); + System.out.println(" | " + head); + System.out.println(" | " + lArm + body + rArm); + System.out.println(" | " + lLeg + " " + rLeg); + System.out.println(" |"); + System.out.println("_|_"); + } + public void printArray(char[] a) { for (char c : a) { System.out.print(c + " "); @@ -125,8 +168,9 @@ public void playerWon() { } public void playerLost() { + drawHangman(MAX_TRIES); System.out.println(":-( :-( :-("); - printArray(guesses); System.out.println("You Lost! You ran out of guesses."); + System.out.println("The Word is: " + new String(secretWord)); } } diff --git a/java/src/main/resources/words.txt b/java/src/main/resources/words.txt new file mode 100644 index 0000000..59687f1 --- /dev/null +++ b/java/src/main/resources/words.txt @@ -0,0 +1,102 @@ +apple +brave +chair +dance +eagle +flame +grape +house +igloo +juice +knife +lemon +mango +night +ocean +piano +queen +river +storm +tiger +umbrella +violet +water +xenon +yacht +zebra +angry +blaze +chess +dizzy +elite +frost +giant +honey +ivory +joker +karma +latch +march +noble +olive +plumb +quirk +ridge +snowy +talon +under +vivid +waltz +xeric +yield +zonal +bread +cloud +drive +earth +fauna +globe +haven +ideal +jewel +kneel +lunar +magic +nerve +ozone +pearl +quest +realm +snake +trail +unity +vapor +witch +xylem +yearn +zones +bluff +crisp +dwarf +elder +flair +grasp +haste +infer +joust +knack +lofty +maple +nudge +orbit +prism +quart +raven +shiny +thyme +ulcer +valor +whirl +xerox +young +zesty