Advertisement
emsiardy

23456

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