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

JAVA PROGRAMMING Problem 02: Cost of Manufactured Devices A company manufactures

ID: 3569352 • Letter: J

Question

JAVA PROGRAMMING

Problem 02: Cost of Manufactured Devices A company manufactures four different electronic devices which use five different components. The components cost $10.95, $6.30, $14.74, $11.25, and $5.00 respectively. Store these costs in a one-dimensional array. The number of components used in each device is given in the table below: Device Number Component Number ,1 23 45 10 4 5 6 7 7 0 12 1 3 49508 6 Write a program to: Store the values of the table in a 2D array. Display the table to the user in order to confirm that you entered the data into the table correctly. NOTE: You only have to display the values in the table, not the device or component numbers (a) Calculate the total cost of each device. (b) Calculate the total cost of producing each device if the estimated labor cost for each device is 10 percent of the cost in (a) Display the output to the user.

Explanation / Answer

package org.serenecode; public class Main { public static void main(String[] args) { double[] componentCosts = {10.95, 6.30, 14.74, 11.25, 5.00}; int[][] componentsPerDevice = { { 10, 4, 5, 6, 7 }, { 7, 0, 12, 1, 3 }, { 4, 9, 5, 0, 8 }, { 3, 2, 1, 5, 6 } }; // show componentsPerDevice table for (int[] n : componentsPerDevice) { for (int x : n) { System.out.print(x + " "); } System.out.println(""); } System.out.println(""); double[] costPerDevice = {0, 0, 0, 0, 0}; // calculate costs per device int device = 1; for (int[] n : componentsPerDevice) { int c = 0; double cost = 0; for (int x : n) { cost = componentCosts[c] * x; costPerDevice[c] = costPerDevice[c] + cost; } System.out.println("Cost for device " + device + " is " + costPerDevice[c]); System.out.println("Cost for producing the device " + device + " is " + (costPerDevice[c] * 1.1)); device++; } } }