first commit

This commit is contained in:
DrChic0 committed 2024-03-07 11:19:37 -08:00
commit 1e19e7f773
7 files changed
+173

No files matched your search

+49
View File
@@ -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));
}
}
+22
View File
@@ -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;
}
}
+49
View File
@@ -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());
}
}
View File
Whitespace-only changes.
+2
View File
@@ -0,0 +1,2 @@
# project-stem-keys
Did da work for ya
@@ -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;
}
}
+27
View File
@@ -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;
}
}