Using C#, Visual Studio, Assume that you\'ve started a business that sells sport
ID: 3868490 • Letter: U
Question
Using C#, Visual Studio, Assume that you've started a business that sells sporting goods equipment online. You currently have operations in Arizona and California. As such, you only need to charge tax if the order comes from one of these states. Assume the tax rate is 10% for California and 5% for Arizona. You also need to charge for shipping. You charge a flat rate of $12.99 for orders less than $50 and a rate of $4.99 for orders between $50 and $100. You do not charge shipping for orders $100 and over.
Create a program that allows employees to calculate the tax and shipping charges. The program should do the following:
Note: Your results should be output to decimal places, and they should use the appropriate format specifiers.
Allow the user to enter the total amount of the order (subtotal).
Allow the user to enter the state (CA for California and AZ for Arizona).
Store the information entered by the user into a separate class, and create instance methods to calculate the tax and the shipping amount.
Output the subtotal, tax amount, shipping amount, and grand total (i.e., order amount plus the tax and shipping amount).
Explanation / Answer
using System;
class Order
{
private int amount;
private string state;
public Order(int amount,string state)//constructor
{
this.amount = amount;
this.state = state;
}
public double calculateTax()
{
double tax;
if(state == "California")
tax = 0.1;
else if(state == "Arizona")
tax = 0.05;
else
tax = 0;
return tax;
}
public double shippingCharge()
{
double charge;
if(amount < 50)
charge = 12.99;
else if(amount >= 50 && amount <= 100)
charge = 4.99;
else
charge = 0;
return charge;
}
}
public class Test
{
public static void Main()
{
Console.WriteLine("Enter the order amount : ");
int amount = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter the order state : ");
string state = Console.ReadLine();
Order o1 = new Order(amount,state);
double tax = o1.calculateTax();
double sCharge = o1.shippingCharge();
//formatted output
Console.WriteLine(" Subtotal :$ {0:00}",amount );
Console.WriteLine(" Tax :$ {0:0.00} ",tax);
Console.WriteLine(" Shipping Charges :$ {0:0.00} ", sCharge);
double gTotal = (amount+amount*tax+sCharge);
Console.WriteLine(" Grandtotal :$ {0:0.00}",gTotal);
}
}
Output:
Enter the order amount : 70
Enter the order state : California
Subtotal :$ 70
Tax :$ 0.10
Shipping Charges :$ 4.99
Grandtotal :$ 81.99
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.