I am posting this because I always feel like I Could do something better with my code. I feel like I'm too elementary, do you have any suggestions about what I can do better? (This is my first time posting, so I hope this is a suitable question and wont get flagged.)
Main Method Side
Main Method Side
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace InternetMerchandise { class Program { static void Main(string[] args) { // Declaring Variables and Methods double totalPurchases; totalPurchases = GetTotalPurchases(); ShippingCost MyCost = new ShippingCost(totalPurchases); // Results for showing shipping charges MyCost.SetCharges(totalPurchases); Console.ReadLine(); Console.WriteLine("The Shipping Charges is: {0:C}", MyCost.ShippingCharges); Console.ReadLine(); } // method to obtain Total Purchases public static double GetTotalPurchases() { double totalPurchases; Console.WriteLine(" Enter the Price of goods purchased\n "); totalPurchases = double.Parse(Console.ReadLine()); return totalPurchases; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace InternetMerchandise { class ShippingCost { private double shippingCharges; private double totalPurchases; // Default Constructor public ShippingCost() { } // Constructor with One argument public ShippingCost(double price) { totalPurchases = price; } // Getters and Setters public double TotalPurchases { set { totalPurchases = value; } get { return totalPurchases; } } public double ShippingCharges { set { shippingCharges = value; } get { return shippingCharges; } } // Determine how much customer is to be charged per purchase price public void SetCharges(double totalPurchases) { if ((totalPurchases > 0) && (totalPurchases <= 250)) shippingCharges = 5; else if ((totalPurchases > 250) && (totalPurchases <= 500)) shippingCharges = 8; else if ((totalPurchases > 500) && (totalPurchases <= 1000)) shippingCharges = 10; else if ((totalPurchases>1000) && (totalPurchases <= 5000)) shippingCharges = 15; else if ((totalPurchases > 5000)) shippingCharges = 20; } } }