Add files via upload

This commit is contained in:
Aesthetiful authored and GitHub committed 2024-03-11 12:33:03 -07:00
1 parent 1e19e7f773
commit 943f152ce6
12 files changed
+377 -170

No files matched your search

+48 -48
View File
@@ -1,49 +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));
}
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));
}
}
+3
View File
@@ -0,0 +1,3 @@
public class Address {
}
+30
View File
@@ -0,0 +1,30 @@
import java.util.*;
public class AddressBook {
private List<Address> addresses;
public AddressBook() {
addresses = new ArrayList<Address>();
}
public List<String> onStreet(String st) {
ArrayList<String> result = new ArrayList<String>();
for(Address a : addresses) {
if(a.getStreet())
}
}
public int newBusiness(String nm, String st, int no) {
for(int i = 0; i < addresses.size(); i++) {
Address a = addresses.get(i);
if(a.getStreet().equals(st) && a.getNumber() == no) {
addresses.set(i, new Address(nm, st, no));
return i;
}
}
addresses.add(new Address(nm, st, no));
return addresses.size() - 1;
}
}
+22 -22
View File
@@ -1,22 +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;
}
}
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;
}
}
+48 -48
View File
@@ -1,49 +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());
}
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());
}
}
+43
View File
@@ -0,0 +1,43 @@
import java.util.ArrayList;
public class OccupancyInfo
{
private ArrayList<Room> rooms;
// no two Room objects in rooms have the same room number
/** Attempts to check-in a new guest into a given room number. If a room exists in
* the database with the room number requested, and the room is unoccupied, a guest
* with the name given is checked-in to that room: the room is marked as occupied,
* and the guestName variable in the Room object is set to the name given.
* @param name the name of the guest attempting to check-in
* @param number the room number into which the guest is to be checked-in
* @return -1 if no room with the requested number exists;
* 0 if the room requested is occupied;
* 1 if the check-in is successful
*/
public int checkIn(String name, int number)
{
/* Implement your answer to part (a) here */
for(Room room : rooms) {
if(room.getNumber() == number) {
return room.checkInNewGuest(name) ? 1 : 0;
}
}
return -1;
}
/* Methods for subsequent parts of this question are not shown */
/* CLASS MEMBERS FOR TESTING */
/* DO NOT MODIFY ANY OF THE CONSTRUCTORS OR METHODS BELOW*/
public OccupancyInfo(ArrayList<Room> r)
{ rooms = r; }
public ArrayList<Room> getRooms()
{ return rooms; }
}
+48
View File
@@ -0,0 +1,48 @@
/* COMPLETE WORKING CLASS PROVIDED */
/* DO NOT MODIFY THE IMPLEMENTATION OF THIS CLASS*/
public class Room
{
private int roomNumber;
private boolean occupied;
private String bookingName;
/** Attempts to check a new guest into the room. If the room is not occupied (the
* variable occupied is false), changes bookingName to name and sets
* occupied to true.
* Otherwise does not change the values of the member variables.
* @param name the name of the guest checking in as a String
* @return true if the check-in was successful and bookingName was changed
* false otherwise
*/
public boolean checkInNewGuest(String name)
{
if(occupied) return false;
bookingName = name;
occupied = true;
return true;
}
/** @return the room number
*/
public int getNumber()
{ return roomNumber; }
/** @return true if the room is occupied; false otherwise.
*/
public boolean isOccupied()
{ return occupied; }
public Room (int rn, boolean o, String bn){
roomNumber = rn;
occupied = o;
bookingName = bn;
}
public String toString(){
return roomNumber+"; "+occupied+"; "+bookingName;
}
}
+35
View File
@@ -0,0 +1,35 @@
import java.util.ArrayList;
public class OccupancyInfo
{
private ArrayList<Room> rooms;
// no two Room objects in rooms have the same room number
/** Returns an ArrayList containing the number of every room which is not occupied
* in the order in which these appear in the ArrayList rooms.
*/
public ArrayList<Integer> availableRoomNumbers()
{
/* Implement your answer to part (b) here */
ArrayList<Integer> result = new ArrayList<Integer>();
for(Room room : rooms) {
if(!room.isOccupied()) {
result.add(room.getNumber());
}
}
return result;
}
/* Methods for previous parts of this question are not shown */
/* CLASS MEMBERS FOR TESTING */
/* DO NOT MODIFY ANY OF THE CONSTRUCTORS OR METHODS BELOW*/
public OccupancyInfo(ArrayList<Room> r)
{ rooms = r; }
public ArrayList<Room> getRooms()
{ return rooms; }
}
+48
View File
@@ -0,0 +1,48 @@
/* COMPLETE WORKING CLASS PROVIDED */
/* DO NOT MODIFY THE IMPLEMENTATION OF THIS CLASS*/
public class Room
{
private int roomNumber;
private boolean occupied;
private String bookingName;
/** Attempts to check a new guest into the room. If the room is not occupied (the
* variable occupied is false), changes bookingName to name and sets
* occupied to true.
* Otherwise does not change the values of the member variables.
* @param name the name of the guest checking in as a String
* @return true if the check-in was successful and bookingName was changed
* false otherwise
*/
public boolean checkInNewGuest(String name)
{
if(occupied) return false;
bookingName = name;
occupied = true;
return true;
}
/** @return the room number
*/
public int getNumber()
{ return roomNumber; }
/** @return true if the room is occupied; false otherwise.
*/
public boolean isOccupied()
{ return occupied; }
public Room (int rn, boolean o, String bn){
roomNumber = rn;
occupied = o;
bookingName = bn;
}
public String toString(){
return roomNumber+"; "+occupied+"; "+bookingName;
}
}
+2 -2
View File
@@ -1,2 +1,2 @@
# project-stem-keys
Did da work for ya
# project-stem-keys
Did da work for ya
@@ -1,24 +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;
}
}
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;
}
}
+26 -26
View File
@@ -1,27 +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;
}
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;
}
}