Starting from:

$25

CS212- Object-Oriented Programming in Java: Lab 17 Solved

Aim: Extending a Class: Money.

Create a new project in Eclipse called Lab 17, and import the files from Z:\Lab17.

Open all the files.

Observe the class hierarchy

                     The abstract class Money extends to Bill and Coin.

              Coin extends to Quarter.

Read through the MoneyMain application and understand how it works.

Write classes for Penny, Nickel and Dime using class Quarter as a reference.

Add some pennies, nickels and dimes to the dataSource array and modify the main method so that it will add pennies, nickels and dimes to the wallet.

Run the main application to see that it works.

Notice in the method printWallet that the output string for a Bill is complicated and the output string for a Coin is simple. This is because Coin has a toString method. Provide class Bill with a similar toString method and rewrite the output string in printWallet for the Bills.

Write a method for the main application called sumWallet which adds all the money in the wallet and prints the amount to the console.

 

 

More products