emsiardy

appclass_1

Mar 31st, 2015
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.04 KB | None | 0 0
  1. using System;
  2.  
  3.  
  4. namespace PurchasesApp
  5. {
  6.     class PurchasesClass
  7.     {
  8.         //data fields
  9.         private decimal theCost;
  10.         private int thePurchased;
  11.        
  12.         //properties
  13.         public decimal Cost
  14.         {
  15.             get { return theCost; }
  16.             set { theCost = value; }
  17.         }
  18.  
  19.         public int Purchased
  20.         {
  21.             get { return thePurchased; }
  22.             set { thePurchased = value; }
  23.         }
  24.        
  25.  
  26.  
  27.         //constructors
  28.         PurchasesClass()
  29.         {
  30.  
  31.         }
  32.         //constructor with 2 args
  33.         PurchasesClass(decimal cost, int purchased)
  34.         {
  35.             theCost = cost;
  36.             thePurchased = purchased;
  37.         }
  38.  
  39.         //methods
  40.  
  41.         //method to calculate shipping
  42.         public decimal GetShipping()
  43.         {
  44.             decimal myCost = 0.00M;
  45.  
  46.             if(thePurchased < 3)
  47.             { myCost = 3.50M; }
  48.             else
  49.                 if(thePurchased >= 3 && thePurchased <= 6)
  50.                 { myCost = 5.00M; }
  51.                 else
  52.                     if(thePurchased >= 5 && thePurchased <= 12)
  53.                     { myCost = 7.00M; }
  54.                     else
  55.                         if(thePurchased >= 11 && thePurchased <= 15)
  56.                         { myCost = 9.00M; }
  57.                         else
  58.                             if(thePurchased > 15)
  59.                             { myCost = 10.00M; }
  60.             return myCost;
  61.         }
  62.         //calculate tax
  63.         public decimal GetTax()
  64.         {
  65.             decimal taxAmount = 0.0775M;
  66.             decimal taxed;
  67.  
  68.             taxed = theCost * taxAmount;
  69.  
  70.             return taxed;
  71.         }
  72.  
  73.         //calculate total
  74.         public decimal GetTotal()
  75.         {
  76.             decimal total;
  77.  
  78.             total = GetTax() + GetShipping();
  79.  
  80.             return total;
  81.         }
  82.  
  83.         //Send data in string
  84.         public override string ToString()
  85.         {
  86.             return "Total: " + GetTotal().ToString("n2");
  87.         }
  88.     }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment