Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 23rd, 2012  |  syntax: None  |  size: 3.57 KB  |  hits: 4  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace ShippingRateCalculator
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             int numPackages;
  13.             double packageHeight, packageLength, packageWidth, packageVolume, packagePerimeter, packageWeight,  total = 0, extraCharges = 0;
  14.             string shippingType;
  15.             bool air = false;
  16.  
  17.             //Some of these things I am not sure how to write into methods. I also think some of the methods are really cluttered and could be written better, but I'm not sure how.
  18.             //Do not know how to write a restraint method. Have not written the summary stuff yet, since I think it will change when I talk to you
  19.  
  20.  
  21.             Console.WriteLine("How many packages would you like to ship?");
  22.             numPackages = Convert.ToInt32(Console.ReadLine());
  23.  
  24.             //Package information. Do not know how to do this in a method. Was thinking it would be ok with a for loop, but I can't think of a way to write it.
  25.  
  26.             Console.WriteLine("What is the height of the package?");
  27.             packageHeight = Convert.ToDouble(Console.ReadLine());
  28.             Console.WriteLine("What is the length of the package?");
  29.             packageLength = Convert.ToDouble(Console.ReadLine());
  30.             Console.WriteLine("What is the width of the package?");
  31.             packageWidth = Convert.ToDouble(Console.ReadLine());
  32.             Console.WriteLine("How much does the package weigh?");
  33.             packageWeight = Convert.ToDouble(Console.ReadLine());
  34.            
  35.             //Shipping information
  36.  
  37.             Console.WriteLine("Is this package being sent by air or land?");
  38.             shippingType = Console.ReadLine();
  39.             if (shippingType == "air")
  40.                 {
  41.                       air = true;
  42.                 }
  43.  
  44.             //Dimension methods
  45.  
  46.             packagePerimeter = Perimeter(packageLength, packageWidth);
  47.             packageVolume = Volume(packageHeight, packageWidth, packageLength);
  48.  
  49.             //Surcharge method
  50.             extraCharges = Surcharges(packageWeight, packageVolume, packagePerimeter, air);
  51.  
  52.             total += extraCharges;
  53.  
  54.  
  55.          
  56.         }
  57.  
  58.         public static double Volume(double height, double width, double length)
  59.         {
  60.             double total = 0;
  61.  
  62.             total = height * width * length;
  63.  
  64.             return total;
  65.         }
  66.  
  67.         public static double Perimeter(double length, double width)
  68.         {
  69.             double total = 0;
  70.  
  71.             total = (2 * length) + (2 * width);
  72.  
  73.             return total;
  74.         }
  75.  
  76.         public static double Surcharges(double weight, double volume, double perimeter, bool air)
  77.         {
  78.             double total = 0;
  79.             const double FLAT_RATE = 4.95, SM_WEIGHT = 3.95, MD_WEIGHT = 6.95, LG_WEIGHT = 9.95, LG_VOL = 5.95, LG_PERIMETER = 3.95, AIR_SHIP = 9.95;
  80.  
  81.             total += FLAT_RATE;
  82.  
  83.             if (weight >= 10 && weight < 15)
  84.             {
  85.                 total += SM_WEIGHT;
  86.             }
  87.                 else if (weight >= 15 && weight <= 20 )
  88.                 {
  89.                     total += MD_WEIGHT;
  90.                 }
  91.                     else if (weight >= 20 && weight <= 25 )
  92.                     {
  93.                         total += LG_WEIGHT;
  94.                     }
  95.  
  96.             if (volume > 4800)
  97.             {
  98.                 total += LG_VOL;
  99.             }
  100.  
  101.             if (perimeter > 130)
  102.                 {
  103.                          total += LG_PERIMETER;
  104.                 }
  105.  
  106.             if (air == true)
  107.             {
  108.                 total += AIR_SHIP;
  109.             }
  110.  
  111.             return total;
  112.         }
  113.        
  114.     }
  115. }