/*************BANK ACCOUNT******************/ public int closeAccount() { int num = numberOfFives; setNumberOfFives(0); return 5*num; } public void transferBalance(BankAccount other, int numOfBills) { int billsInOther = other.getNumberOfFives(); if(billsInOther < numOfBills) //not enough bills to withdraw correct number { other.setNumberOfFives(0); //empty account and transfer that number setNumberOfFives(getNumberOfFives() + billsInOther); } else { other.setNumberOfFives(billsInOther - numOfBills); setNumberOfFives(getNumberOfFives() + numOfBills); } } public BankAccount(int startingNumberOfFives) { numberOfFives = startingNumberOfFives; //initialize the one field. } /* * Code Segment Question: * * 6 * 2 * 0 * 8 * 40 * 6 * 6 * * * */ /*************DOMINO******************/ public boolean canConnectTo(Domino other) { int other1 = other.getNum1(); int other2 = other.getNum2(); //compare all numbers to each other if(other1 == num1) return true; if(other1 == num2) return true; if(other2 == num1) return true; if(other2 == num2) return true; return false; } /*************CLOCK******************/ public void startDaylightSavings() { int h = getHour(); if (h == 23) { setHour(0); } else { setHour(h + 1); } } public boolean isWithin(Clock other, double h) { //represent times as doubles, example: 3:45 -> 3.75 double otherTime = (double)(other.getHour()); otherTime += (double)(other.getMinute())/(60.0); double ourTime = (double)(this.getHour()) + (double)(this.getMinute())/(60.0); //find the difference between this and other clock double diff = otherTime - ourTime; if (diff < 0) { diff = diff*(-1); //take absolute value of diff (can also call Math.abs()) } //if difference is within given limit h, return true if (diff <= h) return true; //if not, we must check if it is wrapped around //subtract from 24 to get the wrap-around difference diff = 24.0-diff; //if within limit, return true if(diff <= h) return true; //if not, return false return false; } public void swapTimes(Clock other) { int h = other.getHour(); int m = other.getMinute(); other.setHour(this.getHour()); other.setMinute(this.getMinute()); this.setHour(h); this.setMinute(m); } /*************BUS******************/ public int fillBus() { int x = getCapacity() - numPassengers; numPassengers += x; return x; } public double fractionFull() { double f = (double)(numPassengers)/(double)(getCapacity()); return f; } public boolean addPassengersFrom(Bus anotherBus) { int num = (int)(anotherBus.getCapacity()*anotherBus.fractionFull()); //num contains the number of passengers on the other bus if(num > (getCapacity() - numPassengers)) { return false; //cannot fit the passengers } while(anotherBus.fractionFull() != 0.0) { anotherBus.removeOnePassenger(); //remove passengers from other bus } numPassengers += num;//add passengers to this bus return true; } /*************ARRAY EXAMINER******************/ public String getValue() { numReturned++; return array[numReturned-1]; } public int getNumLeft() { return array.length - numReturned; } public String[] getAllValuesAlreadyReturned() { String[] returnedValues = new String[numReturned]; for(int i = 0; i 0) { System.out.println(e.getValue()); } }