Advertisement
Guest User

Class Keyboard

a guest
Apr 9th, 2024
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.83 KB | Source Code | 0 0
  1.  
  2. using System;
  3.  
  4. namespace class1
  5. {
  6.  
  7.     public class Keyboard
  8.     {
  9.         public string Brand { get; set; }
  10.        
  11.         private int keyCount;
  12.         public int KeyCount
  13.         {
  14.             get
  15.             {
  16.                 return keyCount;
  17.             }
  18.             set
  19.             {
  20.                 if (value < 80 || value > 130)
  21.                 {
  22.                     throw new ArgumentException("Invalid keys number");
  23.                 }
  24.                
  25.                 keyCount = value;
  26.             }
  27.         }
  28.        
  29.         public string KbdType { get; set; }
  30.        
  31.         public double Price { get; set; }
  32.        
  33.        
  34.         public Keyboard(string brand, string kbdType, int keyCount, double price)
  35.         {
  36.             this.Brand = brand;
  37.             this.KbdType = kbdType;
  38.             this.KeyCount = keyCount;
  39.             this.Price = price;
  40.            
  41.         }
  42.        
  43.         public override string ToString()
  44.         {
  45.             return string.Format("KBD {0}, {1}, {2} keys, Price: {3:f2}]",
  46.                                  Brand, KbdType, KeyCount, Price);
  47.         }
  48.  
  49.        
  50.     }
  51. }
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement