Advertisement
vencinachev

OOP2

Jan 12th, 2021
926
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.16 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace SoftUniiii
  8. {
  9.     class Student
  10.     {
  11.         private string name;
  12.  
  13.         public static int count = 0;
  14.  
  15.         public static decimal money = 0;
  16.  
  17.         public static void Info()
  18.         {
  19.             Console.WriteLine($"There are {count} students.");
  20.             Console.WriteLine($"Money: {money}");
  21.         }
  22.  
  23.         public void AddMoney(decimal m)
  24.         {
  25.             money += m;
  26.         }
  27.  
  28.         public void GetMoney(decimal m)
  29.         {
  30.             if (money < m)
  31.             {
  32.                 throw new Exception("Not enough money!");
  33.             }
  34.             money -= m;
  35.         }
  36.         public Student(string name)
  37.         {
  38.             this.Name = name;
  39.             count++;
  40.         }
  41.  
  42.         public void PrintInfo()
  43.         {
  44.             Console.WriteLine($"Hi, I'm {this.Name}.");
  45.             Console.WriteLine($"We are {count} students!");
  46.         }
  47.         public string Name
  48.         {
  49.             get { return this.name;  }
  50.             set { this.name = value; }
  51.         }
  52.     }
  53. }
  54.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement