Archived
Add files via upload
This commit is contained in:
1 parent
1e19e7f773
commit
943f152ce6
12 files changed
+377
-170
No files matched your search
@@ -1,49 +1,49 @@
|
|||||||
public class ActivityLog {
|
public class ActivityLog {
|
||||||
private int actMins;
|
private int actMins;
|
||||||
private int longest;
|
private int longest;
|
||||||
private int longestHigh;
|
private int longestHigh;
|
||||||
|
|
||||||
|
|
||||||
public void log(int minutes, boolean high) {
|
public void log(int minutes, boolean high) {
|
||||||
if(high) {
|
if(high) {
|
||||||
actMins += 2 * minutes;
|
actMins += 2 * minutes;
|
||||||
if(minutes > longestHigh) {
|
if(minutes > longestHigh) {
|
||||||
longestHigh = minutes;
|
longestHigh = minutes;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
actMins += minutes;
|
actMins += minutes;
|
||||||
}
|
}
|
||||||
|
|
||||||
longest = Math.max(longest, minutes);
|
longest = Math.max(longest, minutes);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int longest(boolean highOnly) {
|
public int longest(boolean highOnly) {
|
||||||
return highOnly ? longestHigh : longest;
|
return highOnly ? longestHigh : longest;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int activeMinutes() {
|
public int activeMinutes() {
|
||||||
return actMins;
|
return actMins;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
ActivityLog a = new ActivityLog();
|
ActivityLog a = new ActivityLog();
|
||||||
System.out.println(a.activeMinutes());
|
System.out.println(a.activeMinutes());
|
||||||
System.out.println(a.longest(false));
|
System.out.println(a.longest(false));
|
||||||
System.out.println(a.longest(true));
|
System.out.println(a.longest(true));
|
||||||
System.out.println();
|
System.out.println();
|
||||||
|
|
||||||
a.log(45, false);
|
a.log(45, false);
|
||||||
a.log(30, true);
|
a.log(30, true);
|
||||||
a.log(30, true);
|
a.log(30, true);
|
||||||
System.out.println(a.activeMinutes());
|
System.out.println(a.activeMinutes());
|
||||||
System.out.println(a.longest(false));
|
System.out.println(a.longest(false));
|
||||||
System.out.println(a.longest(true));
|
System.out.println(a.longest(true));
|
||||||
System.out.println();
|
System.out.println();
|
||||||
|
|
||||||
a.log(50, true);
|
a.log(50, true);
|
||||||
a.log(30, false);
|
a.log(30, false);
|
||||||
System.out.println(a.activeMinutes());
|
System.out.println(a.activeMinutes());
|
||||||
System.out.println(a.longest(false));
|
System.out.println(a.longest(false));
|
||||||
System.out.println(a.longest(true));
|
System.out.println(a.longest(true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
public class Address {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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
@@ -1,22 +1,22 @@
|
|||||||
public class Fundraiser {
|
public class Fundraiser {
|
||||||
private double target;
|
private double target;
|
||||||
private double total;
|
private double total;
|
||||||
private double count = 0;
|
private double count = 0;
|
||||||
|
|
||||||
public Fundraiser(double amount) {
|
public Fundraiser(double amount) {
|
||||||
total = amount;
|
total = amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double averageDonation() {
|
public double averageDonation() {
|
||||||
return (count == 0) ? 0.0 : total / count;
|
return (count == 0) ? 0.0 : total / count;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addDonation(double amount) {
|
public void addDonation(double amount) {
|
||||||
total += amount;
|
total += amount;
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double distanceToTarget() {
|
public double distanceToTarget() {
|
||||||
return (total >= target) ? 0.0 : target - total;
|
return (total >= target) ? 0.0 : target - total;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,49 +1,49 @@
|
|||||||
public class GuessingGame {
|
public class GuessingGame {
|
||||||
private int target;
|
private int target;
|
||||||
private int count;
|
private int count;
|
||||||
private boolean gameWon;
|
private boolean gameWon;
|
||||||
|
|
||||||
public GuessingGame(int max) {
|
public GuessingGame(int max) {
|
||||||
target = (int) (max * Math.random()) + 1;
|
target = (int) (max * Math.random()) + 1;
|
||||||
count = 0;
|
count = 0;
|
||||||
gameWon = false;
|
gameWon = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String guessAnswer(int guess) {
|
public String guessAnswer(int guess) {
|
||||||
if(gameWon) {
|
if(gameWon) {
|
||||||
return "Game already over";
|
return "Game already over";
|
||||||
}
|
}
|
||||||
count++;
|
count++;
|
||||||
|
|
||||||
if(guess > target) {
|
if(guess > target) {
|
||||||
return "Too high";
|
return "Too high";
|
||||||
}
|
}
|
||||||
|
|
||||||
if(guess < target) {
|
if(guess < target) {
|
||||||
return "Too low";
|
return "Too low";
|
||||||
}
|
}
|
||||||
|
|
||||||
gameWon = true;
|
gameWon = true;
|
||||||
|
|
||||||
return "Correct";
|
return "Correct";
|
||||||
}
|
}
|
||||||
|
|
||||||
public int numGuesses() {
|
public int numGuesses() {
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
GuessingGame g = new GuessingGame(24);
|
GuessingGame g = new GuessingGame(24);
|
||||||
System.out.println(g.numGuesses());
|
System.out.println(g.numGuesses());
|
||||||
System.out.println(g.guessAnswer(55));
|
System.out.println(g.guessAnswer(55));
|
||||||
System.out.println(g.numGuesses());
|
System.out.println(g.numGuesses());
|
||||||
System.out.println(g.guessAnswer(12));
|
System.out.println(g.guessAnswer(12));
|
||||||
System.out.println(g.guessAnswer(30));
|
System.out.println(g.guessAnswer(30));
|
||||||
System.out.println(g.numGuesses());
|
System.out.println(g.numGuesses());
|
||||||
System.out.println(g.guessAnswer(24));
|
System.out.println(g.guessAnswer(24));
|
||||||
System.out.println(g.numGuesses());
|
System.out.println(g.numGuesses());
|
||||||
System.out.println(g.guessAnswer(26));
|
System.out.println(g.guessAnswer(26));
|
||||||
System.out.println(g.guessAnswer(24));
|
System.out.println(g.guessAnswer(24));
|
||||||
System.out.println(g.numGuesses());
|
System.out.println(g.numGuesses());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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; }
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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; }
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,2 +1,2 @@
|
|||||||
# project-stem-keys
|
# project-stem-keys
|
||||||
Did da work for ya
|
Did da work for ya
|
||||||
@@ -1,24 +1,24 @@
|
|||||||
public class TriangleNumberTracker {
|
public class TriangleNumberTracker {
|
||||||
private int term = 1;
|
private int term = 1;
|
||||||
private int number = 1;
|
private int number = 1;
|
||||||
|
|
||||||
public TriangleNumberTracker(int startTerm) {
|
public TriangleNumberTracker(int startTerm) {
|
||||||
for (int i = 2; 1 <= startTerm; i++) {
|
for (int i = 2; 1 <= startTerm; i++) {
|
||||||
nextTriangle();
|
nextTriangle();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int currentTriangle() {
|
public int currentTriangle() {
|
||||||
return number;
|
return number;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void nextTriangle() {
|
public void nextTriangle() {
|
||||||
term++;
|
term++;
|
||||||
number += term;
|
number += term;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void prevTriangle() {
|
public void prevTriangle() {
|
||||||
term--;
|
term--;
|
||||||
number -= term;
|
number -= term;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,27 +1,27 @@
|
|||||||
public class wordSandwich {
|
public class wordSandwich {
|
||||||
private String[] wordSandwiches;
|
private String[] wordSandwiches;
|
||||||
|
|
||||||
public wordSandwich(String str1, String str2) {
|
public wordSandwich(String str1, String str2) {
|
||||||
makeAllSandwiches(str1, str2);
|
makeAllSandwiches(str1, str2);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void makeAllSandwiches(String str1, String str2) {
|
private void makeAllSandwiches(String str1, String str2) {
|
||||||
wordSandwiches = new String(str1.length() - 1);
|
wordSandwiches = new String(str1.length() - 1);
|
||||||
for(int i = 0; i < wordSandwiches.length; i++) {
|
for(int i = 0; i < wordSandwiches.length; i++) {
|
||||||
wordSandwiches[i] = makeSandwich(str1, str2, i + 1);
|
wordSandwiches[i] = makeSandwich(str1, str2, i + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String makeSandwich(String str1, String str2, int n) {
|
private String makeSandwich(String str1, String str2, int n) {
|
||||||
return str1.substring(0, n) + str2 + str1.substring(n);
|
return str1.substring(0, n) + str2 + str1.substring(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String[] getFillings(int start, int end) {
|
public String[] getFillings(int start, int end) {
|
||||||
String[] result = new String(wordSandwiches.length);
|
String[] result = new String(wordSandwiches.length);
|
||||||
for(int i = 0; i < wordSandwiches.length; i++) {
|
for(int i = 0; i < wordSandwiches.length; i++) {
|
||||||
result[i] = wordSandwiches[i].substring(start, end);
|
result[i] = wordSandwiches[i].substring(start, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user