{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lecture-23b - Object Oriented Programming Java Defining...

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

View Full Document Right Arrow Icon
Object Oriented Programming Java - 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 Document Right Arrow Icon
Object Oriented Programming Java - Defining Own Classes R.B. Lenin Winter - 2006 DA-IICT 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 2
Object Oriented Programming Java - Defining Own Classes R.B. Lenin Winter - 2006 DA-IICT 3 Defining Instantiable Classes Currency converter example : We need two methods for conversion: fromDollar and toDollar CurrencyConverter yenConverter; double amountInYen, amountInDollar; yenConverter = new CurrencyConverter( ); ... //from dollar to yen amountInYen = yenConverter.fromDollar(200); //from yen to dollar amountInDollar = yenConverter.toDollar(15000);
Background image of page 3

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

View Full Document Right Arrow Icon
Object Oriented Programming Java - Defining Own Classes R.B. Lenin Winter - 2006 DA-IICT 4 Defining Instantiable Classes 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 4
Object Oriented Programming Java - Defining Own Classes R.B. Lenin Winter - 2006 DA-IICT 5 Defining Instantiable Classes Class diagram for a CurrencyConverter object
Background image of page 5

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

View Full Document Right Arrow Icon
Object Oriented Programming Java - Defining Own Classes R.B. Lenin Winter - 2006 DA-IICT 6 Defining Instantiable Classes A program template for a class definition
Background image of page 6
Object Oriented Programming Java - Defining Own Classes R.B. Lenin Winter - 2006 DA-IICT 7 Defining Instantiable Classes Once the CurrencyConverter class is defined, we can use its multiple instances
Background image of page 7

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

View Full Document Right Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}