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 Ouput:
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")));
This is my code, can you review it?
// I have removed "using static System.Console" because I am using .Net 4.5 compiler
// So if you found error while running you can include it in your program
using System;
public class SalesTaxDemo
{
public static void Main()
{
int time = 10; // number of objects
Sale[] sale = new Sale[10]; // creating objects
for(int i=0; i<10; i++) sale[i] = new Sale(); //initializing objects
for(int i=0; i
Console.Write("Enter inventory number #{0} >> ",(i+1));
sale[i].SetInventoryNumber(Console.ReadLine()); // input InventoryNumber
Console.Write("Enter amount of sale >> ");
sale[i].SetAmount(Convert.ToDouble(Console.ReadLine())); // input amount
}
for(int i=0; i
Console.WriteLine("Sale # {0} Amount: {1} Sale ${2} Tax is ${3}",(i+1),sale[i].GetInventoryNumber(), String.Format("{0:n}", sale[i].GetAmount()), String.Format("{0:n}", sale[i].GetTax()));
}
}
}
class Sale{ // class definition of Sale
private string InventoryNumber;
private double amount;
private double tax;
public string GetInventoryNumber(){ return InventoryNumber;} // getter method for InventoryNumber
public double GetAmount(){ return amount;} // getter method for amount
public void SetInventoryNumber(string n){InventoryNumber=n;} // setter method for InventoryNumber
public void SetAmount(double a){amount=a; CalculateTax();} // setter method for amount : CalculateTax is called inside function
public double GetTax(){return tax;} // getter method for tax
private void CalculateTax(){ // tax calculation
if(amount>100.0){
tax = 0.08*100 + 0.06*(amount-100.0);
} else{
tax = 0.08*amount;
}
}
}