Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a Java program that calculates sales price of each item. The sales price i

ID: 3825099 • 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.

5. The method calculates sales price of each item using above formula and display it on the screen.

Explanation / Answer

SalesPrice.java

import java.util.Scanner;


public class SalesPrice {

   public static void main(String args[])
   {
       Scanner scan = new Scanner(System.in);
       System.out.println("Enter the number of items: ");
       int n = scan.nextInt();
       double sales[] = new double[n];
       for(int i=0; i<n; i++){
           System.out.println("Enter the item "+(i+1)+": ");
           sales[i] = scan.nextDouble();
       }
       final double TAX = 5;
       calculateTax(sales, TAX);
   }
   public static void calculateTax(double originalSales[], double tax) {
       for(int i=0; i<originalSales.length; i++){
           double salesPrice = originalSales[i]+(originalSales[i]*tax)/100;
           System.out.println("Original Price: "+originalSales[i]+" Calculated Sales Price: "+salesPrice);
       }
   }

}

Output:

Enter the number of items:
3
Enter the item 1:
100
Enter the item 2:
202
Enter the item 3:
303
Original Price: 100.0 Calculated Sales Price: 105.0
Original Price: 202.0 Calculated Sales Price: 212.1
Original Price: 303.0 Calculated Sales Price: 318.15

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote