Advertisement
Guest User

Account (C# Shell App Paste)

a guest
Jul 19th, 2019
324
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.75 KB | None | 0 0
  1. //Disclaimer: The creator of 'C# Shell (C# Offline Compiler)' is in no way responsible for the code posted by any user.
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace CsharpDemo2
  9. {
  10.     class Account
  11.     {
  12.         // Instance variables
  13.         private int acno;
  14.         private string ahname;
  15.         private double balance;
  16.         //private static int minbal = 5000;
  17.  
  18.         // Constructor
  19.         public Account(int ano, string name, double bal = 0)
  20.         {
  21.             acno = ano;
  22.             ahname = name;
  23.             balance = bal;
  24.         }
  25.  
  26.         // Methods
  27.         public void Deposit(double amount)
  28.         {
  29.             Console.WriteLine("\n\nInitialising Deposit....");
  30.             if (amount > 0){
  31.                 balance += amount;
  32.                 Console.WriteLine("Balance updated \nAvilable Balance:"+balance);
  33.             }
  34.             else
  35.                 Console.WriteLine("Invalid amount!");
  36.         }
  37.  
  38.         public void Withdraw(double amount)
  39.         {
  40.             Console.WriteLine("\n\n Initialising Withdraw....");
  41.             if (amount <= balance){
  42.                 balance -= amount;
  43.                 Console.WriteLine("Amount Withdrawn:"+amount+"\nAvilable Balance in Account:"+balance);
  44.             }
  45.             else
  46.                 Console.WriteLine("Insufficient Balance!");
  47.         }
  48.  
  49.  
  50.         public void Print()
  51.         {
  52.             Console.WriteLine(acno);
  53.             Console.WriteLine(ahname);
  54.             Console.WriteLine(balance);
  55.         }
  56.     }
  57.     class Testacc
  58.     {
  59.         public static void Main()
  60.         {
  61.             Account a = new Account(101,"abcd");
  62.             a.Print();
  63.             a.Deposit(42356.51);
  64.             a.Withdraw(40000);
  65.             a.Withdraw(2306);
  66.             a.Deposit(0.49);
  67.             a.Withdraw(2);
  68.         }
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement