Lecture 7: Example: CreditCard class; UML class diagrams
Textbook section
1.7
An example program: CreditCard
Build your programs one step at a time!
Demonstrates many of the things we’ve learned so far:
- modifiers (
private,public,static) - instance variables
- constructors
- methods
- the
thiskeyword
The main method also demonstrates:
- an array
- a
whileloop - a
forloop - a
for eachloop - making calls to “normal” (nonstatic) methods
- making calls to static methods
UML diagrams
A UML diagram gives the name, attributes, and methods of a class, along with their visibility.
The first 3 minutes, 45 seconds of this video give a nice overview. (The rest of the video goes into inheritance, which we will cover next week.)
Files used in class
Additional exercises
- R-1.11 from book: Modify the
CreditCardclass to include a method that updates the credit limit. - R-1.12 from book: Modify the
CreditCardclass so that it ignores any request to process a negative payment amount.