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

Prices Write a Java program that specifies three one-dimensional arrays named pr

ID: 3715927 • Letter: P

Question

Prices Write a Java program that specifies three one-dimensional arrays named price, amount, and total. Each array should be capable of holding 10 elements. Using a loop, input values for the price and amount arrays. The entries in the total array should be the product of the corresponding values in the price and amount arrays. After all the data have been entered, display the following output:

Price per Item     Number Purchased Total

================= ============== =================

Under each column heading display the appropriate value. Format the values in the price and amount column with two decimal points. Make sure to line up the decimal points in your columns.

Explanation / Answer

PurchasedTest.java

import java.text.DecimalFormat;

import java.util.Scanner;

public class PurchasedTest {

public static void main(String[] args) {

Scanner scan = new Scanner(System.in);

double price[] = new double[10];

int amount[]= new int[10];

double total[]= new double[10];

for(int i=0;i<10;i++) {

System.out.println("Enter the price: ");

price[i]=scan.nextDouble();

System.out.println("Enter the number of purchases: ");

amount[i]=scan.nextInt();

}

for(int i=0;i<10;i++) {

total[i] = price[i]*amount[i];

}

DecimalFormat df = new DecimalFormat("0.00");

System.out.println("Price per Item Number Purchased Total");

System.out.println("==================================================");

for(int i=0;i<10;i++) {

System.out.println(df.format(price[i])+" "+amount[i]+" "+df.format(total[i]));

}

}

}

Output:

Enter the price:

1

Enter the number of purchases:

2

Enter the price:

3

Enter the number of purchases:

4

Enter the price:

5

Enter the number of purchases:

6

Enter the price:

7

Enter the number of purchases:

8

Enter the price:

9

Enter the number of purchases:

11

Enter the price:

222

Enter the number of purchases:

33

Enter the price:

44

Enter the number of purchases:

55

Enter the price:

66

Enter the number of purchases:

77

Enter the price:

88

Enter the number of purchases:

99

Enter the price:

11

Enter the number of purchases:

2

Price per Item Number Purchased Total

==================================================

1.00 2 2.00

3.00 4 12.00

5.00 6 30.00

7.00 8 56.00

9.00 11 99.00

222.00 33 7326.00

44.00 55 2420.00

66.00 77 5082.00

88.00 99 8712.00

11.00 2 22.00

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