10-07-2013 HW e

posted Oct 7, 2013, 8:19 AM by Samuel Konstantinovich   [ updated Oct 7, 2013, 9:37 AM ]
Goal String stuff + Practice with

Here are some methods that are built into the class java.lang.String 
• int length() 

• String substring(int from, int to) 
 // returns the substring beginning at from 
 // and ending at to-1 

•String substring(int from) 
// returns substring(from, length()) 

•int indexOf(String str) 
// returns the index of the first occurrence of str; 
 // returns -1 if not found 

•int compareTo(String other) 
// returns a value < 0 if this is less than other 
 // returns a value = 0 if this is equal to other 
 // returns a value > 0 if this is greater than other 

You can find complete documentation on any class on the oracle website. Here are the strings:   http://docs.oracle.com/javase/7/docs/api/java/lang/String.html


Other stuff:
You have a working bank account, lets add a coin!
-What can coins do?
-What properties do they have?


Programming goal: to modify BankAccount to use a new class Coin in the deposit/withdraw methods
New methods for BankAccount:
deposit ( Coin ) ->  Adds the amount of the coin to the balance
withdraw ( Coin ) -> Removes the amount of the coin to the balance.

Homework/LAB:  (upload to the computers at school) 
1. Complete the coin class
Coin
    isHeads
    value
    flip()
    getValue()
    isHeads()  -> returns the value of isHeads
    + at least one constructor.

2. Add the deposit (Coin), and withdraw(Coin) methods to the BankAccount class.


Comments