(Mondays 2 PM)
(Fridays 2 PM)
Quote Lab3.getStockQuote(String stockName)An API for
Quoteis given below.
Stringthat contains a numeral to the
intnumber for the
String. The following methods are provided in Lab3.java.
trueif conversion can occur without error. Otherwise,
int Lab3.stringToInt(String)returns the integer value of the supplied string. If the string has an error, then 0 is returned.
SegmentDisplaywindow from Lab 2.
Things to consider:
ints or some class of your own design?
MarketValue v1 = new MarketValue(3,4);creates a value that is 3 dollars and 4/8 dollars, or $3.50. The
MarketValuemust print out the value in stock form: 3 4/8.
MarketValue may appear to be similar to
you should view
Quote as an interface for obtaining stock
MarketValue is much more general. In particular,
think about methods you need to do the following.
MarketValuev. What is the
MarketValueof 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
MarketValuethat represents the sum of
MarketValue. You might also have
void increase(MarketValue howmuch)that increments
MarketValueclasses, provide the following.
balance >= 0
Quoteclass 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
Quotefor 0 dollars and 0 eighths.
Quote(String dollars)constructs a
Quotefor 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.
dollarsis the trimmed string containing dollars
eighthsis the trimmed string containing eighths