|
home—info—exams—lectures—labs—hws
Recipe—Laws—lies—syntax—java.lang docs—java.util docs
We will review make sure we understand:
Practice:
A VideoGame has a title,
a web page,
and a suggested price.
Write a class with appropriate fields and constructor.
Write a getter for the price.
In lab, we have followed The Design Recipe for modeling Dates.
Brainstorm: what further info a Date might have?
Let's look at a different language than Java -- fire up a spreadsheet (like Excel). Spreadsheet programming is also programming (although it's not object-oriented).
how to catch?: Perhaps the *constructor* could catch this problem: It takes the inputs 2007,2,29 and it constructs an internal date object (int). But before returning it can ask getMonth() and getDay(); if these give different answers than 2 and 29 then it can ask the user “2007.Feb.29 is not a valid day; did you want to use 2007.Mar.01?”
The Zero'th Law of Programming: The structure of your data and of your program should reflect how you (as a human) conceive of the problem at hand.(To be fair, Excel does do a good job of separating the abstract data type (Date) from its representation (int). Though if it did a perfect job, we'd have no way of figuring out their internal representation.1) This topic is discussed more in ITEC220 (CS2). We'll also say that it separates the model (the date) from the view (the many ways of formatting the Date).)
Task (optional): play around with Excels Time constructor2 and see if you can figure out Excel's representation of time-of-day.
In fact, Excel just has one way to represent moments in time, which is what it uses for both dates and for time-of-day -- clever clever! Perhaps their representation is not so bad after all -- it is reflecting how physicists view time, and thus arguably is not actually a lapse of the zero'th law.
What if we decided that a VideoGame also contains a release-date?
1In fact, are we really certain that Excel represents dates as an int? ↩
2Well, spreadsheet programming -- that is, what we type in as a user to computer our answers -- isn't object-oriented, and hence date(int,int,int) isn't actually a “contructor”, but it is the function which creates the internalized representation -- close enough. ↩
home—info—exams—lectures—labs—hws
Recipe—Laws—lies—syntax—java.lang docs—java.util docs
©2008, Ian Barland, Radford University Last modified 2008.Jan.24 (Thu) |
Please mail any suggestions (incl. typos, broken links) to ibarlandradford.edu |