From 1e19e7f773fce7d62e8247ff4fcb18350318ce28 Mon Sep 17 00:00:00 2001 From: DrChic0 Date: Thu, 7 Mar 2024 11:19:37 -0800 Subject: [PATCH] first commit --- ActivityLog/ActivityLog.java | 49 +++++++++++++++++++ Fundraiser/Fundraiser.java | 22 +++++++++ Guessing Game/GuessingGame.java | 49 +++++++++++++++++++ New Text Document.txt | 0 README.md | 2 + .../TriangleNumberTracker.java | 24 +++++++++ Word Sandwich/wordSandwich.java | 27 ++++++++++ 7 files changed, 173 insertions(+) create mode 100644 ActivityLog/ActivityLog.java create mode 100644 Fundraiser/Fundraiser.java create mode 100644 Guessing Game/GuessingGame.java create mode 100644 New Text Document.txt create mode 100644 README.md create mode 100644 Triangle Number Tracker/TriangleNumberTracker.java create mode 100644 Word Sandwich/wordSandwich.java diff --git a/ActivityLog/ActivityLog.java b/ActivityLog/ActivityLog.java new file mode 100644 index 0000000..b2fc243 --- /dev/null +++ b/ActivityLog/ActivityLog.java @@ -0,0 +1,49 @@ +public class ActivityLog { + private int actMins; + private int longest; + private int longestHigh; + + + public void log(int minutes, boolean high) { + if(high) { + actMins += 2 * minutes; + if(minutes > longestHigh) { + longestHigh = minutes; + } + } else { + actMins += minutes; + } + + longest = Math.max(longest, minutes); + } + + public int longest(boolean highOnly) { + return highOnly ? longestHigh : longest; + } + + public int activeMinutes() { + return actMins; + } + + public static void main(String[] args) { + ActivityLog a = new ActivityLog(); + System.out.println(a.activeMinutes()); + System.out.println(a.longest(false)); + System.out.println(a.longest(true)); + System.out.println(); + + a.log(45, false); + a.log(30, true); + a.log(30, true); + System.out.println(a.activeMinutes()); + System.out.println(a.longest(false)); + System.out.println(a.longest(true)); + System.out.println(); + + a.log(50, true); + a.log(30, false); + System.out.println(a.activeMinutes()); + System.out.println(a.longest(false)); + System.out.println(a.longest(true)); + } +} \ No newline at end of file diff --git a/Fundraiser/Fundraiser.java b/Fundraiser/Fundraiser.java new file mode 100644 index 0000000..70fbf6c --- /dev/null +++ b/Fundraiser/Fundraiser.java @@ -0,0 +1,22 @@ +public class Fundraiser { + private double target; + private double total; + private double count = 0; + + public Fundraiser(double amount) { + total = amount; + } + + public double averageDonation() { + return (count == 0) ? 0.0 : total / count; + } + + public void addDonation(double amount) { + total += amount; + count++; + } + + public double distanceToTarget() { + return (total >= target) ? 0.0 : target - total; + } +} diff --git a/Guessing Game/GuessingGame.java b/Guessing Game/GuessingGame.java new file mode 100644 index 0000000..65c6f0d --- /dev/null +++ b/Guessing Game/GuessingGame.java @@ -0,0 +1,49 @@ +public class GuessingGame { + private int target; + private int count; + private boolean gameWon; + + public GuessingGame(int max) { + target = (int) (max * Math.random()) + 1; + count = 0; + gameWon = false; + } + + public String guessAnswer(int guess) { + if(gameWon) { + return "Game already over"; + } + count++; + + if(guess > target) { + return "Too high"; + } + + if(guess < target) { + return "Too low"; + } + + gameWon = true; + + return "Correct"; + } + + public int numGuesses() { + return count; + } + + public static void main(String[] args) { + GuessingGame g = new GuessingGame(24); + System.out.println(g.numGuesses()); + System.out.println(g.guessAnswer(55)); + System.out.println(g.numGuesses()); + System.out.println(g.guessAnswer(12)); + System.out.println(g.guessAnswer(30)); + System.out.println(g.numGuesses()); + System.out.println(g.guessAnswer(24)); + System.out.println(g.numGuesses()); + System.out.println(g.guessAnswer(26)); + System.out.println(g.guessAnswer(24)); + System.out.println(g.numGuesses()); + } +} \ No newline at end of file diff --git a/New Text Document.txt b/New Text Document.txt new file mode 100644 index 0000000..e69de29 diff --git a/README.md b/README.md new file mode 100644 index 0000000..581fb2a --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# project-stem-keys +Did da work for ya diff --git a/Triangle Number Tracker/TriangleNumberTracker.java b/Triangle Number Tracker/TriangleNumberTracker.java new file mode 100644 index 0000000..55beaef --- /dev/null +++ b/Triangle Number Tracker/TriangleNumberTracker.java @@ -0,0 +1,24 @@ +public class TriangleNumberTracker { + private int term = 1; + private int number = 1; + + public TriangleNumberTracker(int startTerm) { + for (int i = 2; 1 <= startTerm; i++) { + nextTriangle(); + } + } + + public int currentTriangle() { + return number; + } + + public void nextTriangle() { + term++; + number += term; + } + + public void prevTriangle() { + term--; + number -= term; + } +} diff --git a/Word Sandwich/wordSandwich.java b/Word Sandwich/wordSandwich.java new file mode 100644 index 0000000..f0a1323 --- /dev/null +++ b/Word Sandwich/wordSandwich.java @@ -0,0 +1,27 @@ +public class wordSandwich { + private String[] wordSandwiches; + + public wordSandwich(String str1, String str2) { + makeAllSandwiches(str1, str2); + } + + private void makeAllSandwiches(String str1, String str2) { + wordSandwiches = new String(str1.length() - 1); + for(int i = 0; i < wordSandwiches.length; i++) { + wordSandwiches[i] = makeSandwich(str1, str2, i + 1); + } + } + + private String makeSandwich(String str1, String str2, int n) { + return str1.substring(0, n) + str2 + str1.substring(n); + } + + public String[] getFillings(int start, int end) { + String[] result = new String(wordSandwiches.length); + for(int i = 0; i < wordSandwiches.length; i++) { + result[i] = wordSandwiches[i].substring(start, end); + } + + return result; + } +} \ No newline at end of file