Your mission: Write a program using Visual Studio 2010 in C# that gets the amoun
ID: 3628317 • Letter: Y
Question
Your mission: Write a program using Visual Studio 2010 in C# that gets the amount of a purchase from the user and then calculates the shipping charge, based on the following table:$0.00 - $250.00: $5.00
$250.01 - $500.00: $8.00
$500.01 - $1,000.00: $10.00
$1,000.01 - $5,000.00: $15.00
over $5,000.00: $20.00
Sample output from program:
Enter a purchase amount to find out your shipping charges.
Please enter the amount of your purchase: 234.65
The shipping charge on a purchase of $234.65 is $5.00.
Press any key to continue . . .
Tips
Best practice: Put yourself in the place of the program. What questions would you ask a customer in order to get the best input? How would you determine the correct shipping charges if you had to make the decisions yourself? Write out the questions you would ask yourself on paper as pseudocode and/or in Visual Studio as C# comments, and then implement them one by one, testing as you go. Remember to not write too much at one time. Always add and test functionality incrementally!
You can use the pseudocode below as a guide:
Prompt the user for the sale amount
Is sale amount greater than $5,000.00?
If so, shipping is $20.00
If not, is sale amount greater than $1,000.00?
If so, shipping is $15.00
If not, is sale amount greater than $500.00?
If so, shipping is $10.00
If not, is sale amount greater than $250.00?
If so, shipping is $8.00
If not, is sale amount greater than $0.00
shipping is $5.00
If not
shipping is $0.00
If shipping is $0.00
Display "Error incorrect input"
If not
Display sale amount and shipping charge
Explanation / Answer
hope this helps Program.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Shipping { class Program { static void Main(string[] args) { bool isExit = false; // boolean variable for loop block double returned = 0.00; // variable that holds returned shipping cost while (isExit == false) // while isExit is equal to false do, { Console.Write("Please enter the amount to find out your shipping charges. "); Console.Write("Please enter the amount of your purchase: "); string input = Console.ReadLine(); // get string input you could use a buffered reader if so inclined double convert = Convert.ToDouble(input); // convert the string to a double if (convert < 0) // if the user input is less than zero then, { isExit = true; // time to exit is now true printExit(); // lets exit } else // else do, { returned = ShippingHelper.calculateShipping(convert); // call to calculate shipping method Console.WriteLine("Your shipping cost is: ${0}.00", returned); // print the output } } } /// /// Exit method for clarity /// public static void printExit() { Console.WriteLine("Exiting the program"); // just a print statement } } } ///////////// ShippingHelper.cs class /////////////////////// using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Shipping { class ShippingHelper { /// /// Takes double as input and returns the shipping cost /// /// Purchase Amount /// Shipping Cost public static double calculateShipping(double inputValue) { double returnValue = 0.00; if(inputValue >= 0 && inputValue < 250.00) { returnValue = 5.00; } else if (inputValue >= 250.01 && inputValue = 500.01 && inputValue = 5000) { returnValue = 20.00; } return returnValue; } } } Alternatively you could just copy/paste the calculate shipping method to Program.cs classRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.