Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Deakin University

Object Oriented Development


OnTrack Submission

The Account Class

Submitted By:
Tran Dac Duy Ho Tutor:
s223033111 Khan Norfolk
2024/03/27 19:21

March 27, 2024

Produced by Doubtfire
File 1 of 2 TestAccount.cs

1 using System;
2

3 class Account
4 {
5 private decimal _balance;
6 private string _name;
7

8 public Account(string name, decimal balance)


9 {
10 _name = name;
11 _balance = balance;
12 }
13

14 public void Deposit(decimal amount)


15 {
16 _balance += amount;
17 Console.WriteLine($"You have deposited : {amount:C}. The current balnce is:
,→ {_balance:C)}");
18 }
19

20 public void Withdraw(decimal amount)


21 {
22 if (_balance >= amount)
23 {
24 _balance -= amount;
25 Console.WriteLine($"You have withdrawned : {amount:C}. The current
,→ balnce is: {_balance:C}");
26 }
27 else
28 {
29 Console.WriteLine("Insufficient funds.");
30 }
31 }
32

33 public void Print()


34 {
35 Console.WriteLine($"Account Name: {_name}");
36 Console.WriteLine($"Balance: {_balance:C}");
37 }
38

39 public string Name


40 {
41 get { return _name; }
42 }
43 }

Page 1 of 2
File 2 of 2 Account.cs

1 using System;
2

3 class AccountTest
4 {
5 static void Main(string[] args)
6 {
7 Account account = new Account("Dave Ho", 2000.00m);
8

10 account.Deposit(500.00m);
11 account.Withdraw(200.00m);
12

13

14 account.Print();
15 }
16 }

Page 2 of 2

You might also like