main() functions. Write the simplest main() needed to get the job done. The point here is not to get complete programs, but to exercise your skill in creating, declaring, and implementing classes. In this context, main() is merely a tool.
The press() function should flip the button's on/off state, then print the button's label and whether the button is now on or off. Answer the following questions:
isOn ?
void setLabel(string lbl)] ?
main() function that (a) creates a button object labelled "Play" and (b) "presses" it. Append to your homework solutions a printout of the result.
printValue() should print the amount represented by an object of this class in the familiar format. For example, a Money(2, 14) object would be printed as '$2.14' (without the quotes, of course). Note that if you create an object such as, say, Money(3, 257), you have two choices: either convert the 257 cents into the appropriate number of dollars and cents in the constructor, or do the conversion when printing the value. Either one is fine, but try to give a reason why you picked one choice instead of the other.
int secondsFrom(Time t) takes another Time object and should return the number of seconds between that object and the object on which the function is called. For example, if Time before = Time(2, 7, 10) and Time after = Time(5, 17, 32), then after.secondsFrom(before) would return the value 11422. The member function print() should print the object it's called on in the usual form. For example, the object Time(23, 41, 8) would be printed as '23h 41m 8s' (without the quotes, of course). Once again, you have a choice of when to perform the necessary conversions when you're given more than 60 seconds or more than 60 minutes. As before, you can do that conversion at construction time or inside the other member functions. Which option makes more sense?
main() function that creates two Time objects, Time(23, 41, 8) and Time(9, 53, 37), and prints the number of hours, minutes, and seconds between them (that is, the time interval between those two objects). Append to your homework solutions a printout of the results. Hint: find the number of seconds between the two objects, create a new Time object with that many seconds (but no hours and no minutes) and then call print() on that new object.
main() function that creates 5 objects of type URLConnection and prints whether or not they're open. The output should look something like this:
Connection 1 to www.google.com is open. Connection 2 to www.ucr.edu is open. ... Connection 5 to www.cs.ucr.edu/cs12/ was not opened.Make sure to run your
main() and append to your homework solutions a printout of the results. You may choose any URL strings you like, since we're not actually connecting to anything here.
main() function that creates specific coin objects (that is, a number of pennies, nickels, dimes, and quarters) and then prints the total amount of change they represent. Thus, if in your main() you created the objects Dime d1 = Dime(), Dime d2 = Dime(), Quarter q = Quarter(), and Penny p = Penny(), then your main() would print something like "The total amount of change you have is 0 dollars and 46 cents."
© 2003 UC Riverside Department of Computer Science & Engineering. All rights reserved.