Advertisement
Guest User

Untitled

a guest
Mar 4th, 2023
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.87 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4.  
  5. namespace ShoppingSpree
  6. {
  7.     public class Product
  8.     {
  9.         private string name;
  10.         private double cost;
  11.  
  12.         public Product(string name, double cost)
  13.         {
  14.             this.Name = name;
  15.             this.Cost = cost;
  16.         }
  17.         public string Name
  18.         {
  19.             get
  20.             {
  21.                 return name;
  22.             }
  23.             set
  24.             {
  25.                 name = value;
  26.             }
  27.         }
  28.         public double Cost
  29.         {
  30.             get
  31.             {
  32.                 return cost;
  33.             }
  34.             set
  35.             {
  36.                 if (value < 0)
  37.                 {
  38.                     throw new Exception("Money cannot be negative");
  39.                 }
  40.                 this.cost = value;
  41.             }
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement