ch4 - Chapter Four Defining Your Own Classes Topics...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
Chapter Four Defining Your Own Classes
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Topics Instantiable classes Components of a class constructors accessors mutators Visibility modifiers Class diagrams revisited
Background image of page 2
Defining Instantiable Classes Learning how to define instantiable classes is the first step toward mastering the skills necessary in building large programs. A class is instantiable if we can create instances of the class. The DecimalFormat , GregorianCalendar , and String classes are all instantiable classes, while the Math class is not.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Currency converter We need two methods for conversion: fromDollar and toDollar. CurrencyConverter yenConverter; double amountInYen, amountInDollar; yenConverter = new CurrencyConverter( ); ... amountInYen = yenConverter.fromDollar(200); // from dollar to yen amountInDollar = yenConverter.toDollar(15000); //from yen to dollar
Background image of page 4
Currency converter Since the exchange rate fluctuates, we need a method to set the exchange rate. CurrencyConverter yenConverter; yenConverter = new CurrencyConverter( ); yenConverter.setExchangeRate(130.77);
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CurrencyConverter Want to convert both to and from dollars To convert, need to know exchange rate exchange rates fluctuate Class diagram for a CurrencyConverter object.
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 08/18/2011 for the course COMPUTER S CSC113 taught by Professor Shah during the Spring '09 term at King Saud University.

Page1 / 20

ch4 - Chapter Four Defining Your Own Classes Topics...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online