Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace CashRegister
- {
- class Program
- {
- static void Main(string[] args)
- {
- // declare a new CashRegister object
- CashRegister myRegister = new CashRegister ();
- // add several dollar amounts
- myRegister.add (20.00);
- myRegister.add (15.50);
- myRegister.add (3.75);
- // display the current cash balance
- Console.WriteLine("The register has: $" + myRegister.????());
- Console.ReadKey();
- }
- }
- // CashRegister object definition
- class CashRegister
- {
- // declare a property (class variable)
- double cash = 0.0;
- // define an add() method that takes one double "amount" parameter
- public void add(double amount)
- {
- Console.WriteLine("Adding $" + amount);
- cash += amount;
- }
- // define a report() method that returns one double value
- public double report()
- {
- return cash;
- }
- }
- }
Add Comment
Please, Sign In to add comment