| Lab | Assigned | Design Due (Mondays 2 PM) |
Lab Due (Fridays 2 PM) |
|||
|---|---|---|---|---|---|---|
| 29 | Jan | 1 | Feb | 5 | Feb | |
Quote Lab3.getStockQuote(String stockName)An API for
Quote is given below.
String that
contains a numeral to the int number for the String.
The following methods are provided in Lab3.java.
boolean Lab3.stringToIntOK(String)returns
true if conversion can occur without error. Otherwise,
false is returned.
int Lab3.stringToInt(String)returns the integer value of the supplied string. If the string has an error, then 0 is returned.
SegmentDisplay window
from Lab 2.
Portfolio
Things to consider:
ints or
some class of your own design?
MarketValue
MarketValue v1 = new MarketValue(3,4);creates a value that is 3 dollars and 4/8 dollars, or $3.50. The
toString method for MarketValue must
print out the value in stock form: 3 4/8.
Although MarketValue may appear to be similar to Quote,
you should view Quote as an interface for obtaining stock
quotes, while MarketValue is much more general. In particular,
think about methods you need to do the following.
MarketValue v. What is the MarketValue
of the n shares? Where does the method live that computes this?
What is its type signature? Does it mutate to return the right value or
does it create a new object to represent the value?
MarketValue plus(MarketValue addend)that returns a new
MarketValue that represents the
sum of this and the addend's MarketValue.
You might also have
void increase(MarketValue howmuch)that increments
this MarketValue by
howmuch.
Portfolio
and MarketValue classes, provide the following.
balance >= 0
Quote API
Quote class is as follows.
Quote(String dollars, String eighths)
constructs an immutable pair of Strings. Blanks are
trimmed from the strings. If dollars or eighths is
not positive, or not a number, then the associated
instance variable is set to "0".
Quote( )
constructs a Quote for 0 dollars and 0 eighths.
Quote(String dollars)
constructs a Quote for the specified dollars and
0 eighths.
String getDollars() returns the dollars.
String getEighths() returns the eighths.
String toString( )
returns a string with the dollars and eighths.
dollars is the trimmed string containing dollars
eighths is the trimmed string containing eighths