Write a java program that calculates sales price of each item. The sales price i
ID: 3824635 • Letter: W
Question
Write a java program that calculates sales price of each item. The sales price is calculated as follows:
sales price = original price + (original price x tax)
The tax rate is 5%. The program must design a single dimensional array to save all original price. Then, in Main() method, entire array and tax rate are passed to the static method. The method calculate sale price of each item. Your program must meet following requirements:
1. The program should declare one dimensional array to store original price of each item.
2. The size of an array should be determined by number of items. - it means that this is determined by user.
3. Prompt the user to input original price of each item and save it to the array.
4. The entire array and tax rate pass to the static method you defined.
should look like the picture.
ca C: WINDOWSAsystem32cmd.exe How many Items do you have? 5 Enter the original price of item 1 $1.99 Enter the original price of item 2 $2.99 $5.50 Enter the original price of item 3 Enter the original price of item 4 $3.55 Enter the original price of item 5 $12.99 Sale Price of item 1 including tax $2.09 ale Price of item 2 including tax $3.14 ale Price of item 3 including tax: $5.78 ale Price of item 4 including tax $3.73 Sale Price of item 5 including tax $11.54 Press any key to continueExplanation / Answer
import java.util.Scanner;
public class findSalePrice {
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
System.out.print("How many items do you have?");
int n = scan.nextInt();
double tmp;
double[] arr = new double[n];
for(int i=0;i<n;i++)
{
System.out.print("Enter original price of the item "+(i+1)+": $");
arr[i] = scan.nextDouble();
}
for(int i=0;i<n;i++)
{
tmp = arr[i]*1.05;
System.out.println("Sales price of the item "+(i+1)+" including tax: $"+String.format( "%.2f", tmp ) );
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.