Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a program named SalesTaxDemo that declares an array of 10 Sale objects. Prompt the user for data for each object and display the 10

Create a program named SalesTaxDemo that declares an array of 10 Sale objects. Prompt the user for data for each object and display the 10 objects. The program should accept input and display output in the same format as the sample program output below.

Data fields for Sale objects include:

InventoryNumber - An inventory number (as a string)

amount - Amount of the sale (as a double)

tax - Tax owed (as a double)

Include a property with get and set accessors for the first two data fields, but make the tax owed a read-only property.

The tax should be calculated whenever the amount of the sale is set. Assume that the tax rate is 8 percent for the first $100 and 6 percent for any amount greater than $100.

Sample Program Output:

Enter inventory number #1 >> 1 Enter amount of sale >> 200 Enter inventory number #2 >> 2 Enter amount of sale >> 900 Enter inventory number #3 >> 5 Enter amount of sale >> 1200 Enter inventory number #4 >> 18 Enter amount of sale >> 37000 Enter inventory number #5 >> 12 Enter amount of sale >> 1500 Enter inventory number #6 >> 91 Enter amount of sale >> 100024 Enter inventory number #7 >> 88 Enter amount of sale >> 8091 Enter inventory number #8 >> 102 Enter amount of sale >> 400675 Enter inventory number #9 >> 21 Enter amount of sale >> 1900 Enter inventory number #10 >> 28 Enter amount of sale >> 12000 Sale # 1 Amount: 1 Sale $200.00 Tax is $14.00 Sale # 2 Amount: 2 Sale $900.00 Tax is $56.00 Sale # 3 Amount: 5 Sale $1,200.00 Tax is $74.00 Sale # 4 Amount: 18 Sale $37,000.00 Tax is $2,222.00 Sale # 5 Amount: 12 Sale $1,500.00 Tax is $92.00 Sale # 6 Amount: 91 Sale $100,024.00 Tax is $6,003.44 Sale # 7 Amount: 88 Sale $8,091.00 Tax is $487.46 Sale # 8 Amount: 102 Sale $400,675.00 Tax is $24,042.50 Sale # 9 Amount: 21 Sale $1,900.00 Tax is $116.00 Sale # 10 Amount: 28 Sale $12,000.00 Tax is $722.00

In order to prepend the $ to currency values, the program will need to use the CultureInfo.GetCultureInfo method. In order to do this, include the statement using System.Globalization; at the top of your program and format the output statements as follows: WriteLine("This is an example: {0}", value.ToString("C", CultureInfo.GetCultureInfo("en-US")));

What I got :

using System; using static System.Console; using System.Globalization; class SalesTaxDemo { static void Main() { Sale[] mySaleItems = new Sale[10]; for (int x = 0, x < mySaleItems.Length; x++) { Write("Enter inventory number #{0} >> ", x + 1); mySaleItems[x].InventoryNumber(ReadLine()); Write("Enter amount of sale >> "); mySaleItems[x].Amount = double.Parse(ReadLine()); } for (int x = 0, x < mySaleItems.Length; x++) { WriteLine("Sale # {0} Amount: {1} Sale {2}", x + 1, mySaleItems[x].InventoryNumber, mySaleItems[x].Amount.Tax.ToString("C", CultureInfo.GetCultureInfo("en-US")));

WriteLine("Tax is {0}", mySaleItems[x].Tax.ToString("C", CultureInfo.GetCultureInfo("en-US"))); } } } class Sale {

private string inventoryNumber; private double amount; private double tax;

public string InventoryNumber { get; set; } public double Amount get { return amount; } set { amount = value; CalculateTax(); } } public double Tax { get { return tax; } }

private void CalculateTax() { if (amount <= 100) { tax = 0.08 * amount; } else { tax = (0.08 * 100) + (0.06 * (amount - 100)); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Autonomous Database In Enterprise Architecture

Authors: Bal Mukund Sharma, Krishnakumar KM, Rashmi Panda

1st Edition

1801072248, 978-1801072243

More Books

Students also viewed these Databases questions

Question

How do modern Dashboards differ from earlier implementations?

Answered: 1 week ago