Write compile and execute a computer program which will defi
Write, compile and execute a computer program which will define and initialize two hard - coded arrays ( subscripted variables ) and then populate a third array with the product of the two earlier declared arrays. The program will simulate the business application of examining a price, quantity and amount analysis using this simple but important equation. PLEASE PRINT OUTPUT!
Amount = Price × Quantity
/********************************************************************
Program Name: ArrayProcessing.java
Programmer\'s Name: Sammy Student
Program Description: Manipulation of three arrays ********************************************************************/
// include any necessary packages / libraries
import java.text.DecimalFormat;
// the class file
public class ArrayProcessing
{
// declare the global variables for the array indices
public static final int index = 10;
public static int count = 0;
// declare the three arrays
public static double[] priceArray =
{ 5.73, 11.77, 13.41, 14.25, 19.64,
8.37, 9.19, 19.44, 18.53, 12.04 };
public static int[] quantityArray =
{ 3, 9, 7, 8, 10, 12, 3, 6, 3, 5 };
public static double[] amountArray =
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
// declare a decimal formatting object
static DecimalFormat df = new DecimalFormat(\"###,###.##\");
-- CODE CONTINUED
// the main() method is defined
public static void main(String[] args)
{
// call the method named process()
process(priceArray, quantityArray);
// call the method named display()
display(priceArray, quantityArray);
}
// define the method named process()
static void process(double[] priceA, int[] quantityA)
{
// global arrays restored
priceArray = priceA;
quantityArray = quantityA;
// looping structure to perform the multiplication
for(count = 0; count < index; count++)
{
// body statement(s) for the looping structure
}
}
// define the method named display()
static void display(double[] prices, int[] quantities)
{
// global arrays restored
priceArray = prices;
quantityArray = quantities;
// output displayed
for(int i = 0; i < index; i++)
{
// body statement(s) for the looping structure
}
}
}//end the class
I need to modify the working program by including, within the display() method a separate for loop that will display the following table, which shows the amount status as either being above or equal to $ 100.00 or being strictly below. Make sure that the program has four arrays and when completed, submit the program source code as well as the program outputs showing the results of running the code.
$ 100.00 . Store the status character in a global array defined as statusArray() with \' A \' for ABOVE and \' B \' for BELOW.
1) B
2) A
3) B
4) A
5) A
6) A
7) B
8) A
9) B
10) B
| /******************************************************************** Program Name: ArrayProcessing.java Programmer\'s Name: Sammy Student Program Description: Manipulation of three arrays ********************************************************************/ // include any necessary packages / libraries import java.text.DecimalFormat; // the class file public class ArrayProcessing { // declare the global variables for the array indices public static final int index = 10; public static int count = 0; // declare the three arrays public static double[] priceArray = { 5.73, 11.77, 13.41, 14.25, 19.64, 8.37, 9.19, 19.44, 18.53, 12.04 }; public static int[] quantityArray = { 3, 9, 7, 8, 10, 12, 3, 6, 3, 5 }; public static double[] amountArray = // declare a decimal formatting object static DecimalFormat df = new DecimalFormat(\"###,###.##\"); -- CODE CONTINUED |
Solution
/********************************************************************
Program Name: ArrayProcessing.java
Programmer\'s Name: Sammy Student
Program Description: Manipulation of three arrays ********************************************************************/
// include any necessary packages / libraries
import java.text.DecimalFormat;
// the class file
public class ArrayProcessing {
// declare the global variables for the array indices
public static final int index = 10;
public static int count = 0;
// declare the three arrays
public static double[] priceArray = { 5.73, 11.77, 13.41, 14.25, 19.64,
8.37, 9.19, 19.44, 18.53, 12.04 };
public static int[] quantityArray = { 3, 9, 7, 8, 10, 12, 3, 6, 3, 5 };
public static double[] amountArray = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
public static char[] statusArray = new char[index];
// declare a decimal formatting object
static DecimalFormat df = new DecimalFormat(\"###,###.##\");
// the main() method is defined
public static void main(String[] args) {
// call the method named process()
process(priceArray, quantityArray);
// call the method named display()
display(priceArray, quantityArray);
}
// define the method named process()
static void process(double[] priceA, int[] quantityA) {
// global arrays restored
priceArray = priceA;
quantityArray = quantityA;
// looping structure to perform the multiplication
for (count = 0; count < index; count++) {
// body statement(s) for the looping structure
amountArray[count] = priceArray[count] * quantityArray[count];
}
}
// define the method named display()
static void display(double[] prices, int[] quantities) {
// global arrays restored
priceArray = prices;
quantityArray = quantities;
// output displayed
for (int i = 0; i < index; i++) {
// body statement(s) for the looping structure
if (amountArray[i] >= 100)
statusArray[i] = \'A\';
else
statusArray[i] = \'B\';
System.out.println((i + 1) + \") \" + statusArray[i]);
}
}
}// end the class
OUTPUT:
1) B
2) A
3) B
4) A
5) A
6) A
7) B
8) A
9) B
10) B




