Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Item
- Store 0 1 2 3 4
- 0 25 64 23 45 14
- 1 12 82 19 34 63
- 2 54 22 17 32 35
- Item Cost Per Item
- 0 $12.00
- 1 $17.95
- 2 $95.00
- 3 $86.50
- 4 $78.00
- import java.util.*;
- public class asd
- {
- public static void main(String[] args)
- {
- double items[][]= new double[3][5];
- double cost[]=new double[5];
- loadArray(items, cost);
- System.out.println("Total amount of sales for each store : ");
- computeCost(items, cost);
- printArray(items, cost);
- }
- public static void loadArray(double items[][], double cost[])
- {
- Scanner input = new Scanner(System.in);
- String s1;
- int num, x, y;
- for(x=0; x<items.length;x++)
- {
- for(y=0; y<items[x].length; y++)
- {
- System.out.println("Enter the next item of data:");
- items[x][y]=input.nextDouble();
- }
- }
- //Cost of the items:
- cost[0]=12.00;
- cost[1]=17.95;
- cost[2]=95.00;
- cost[3]=86.50;
- cost[4]=78.00;
- }
- public static void printArray(double items[][], double cost[])
- {
- System.out.println("Number of items Sold During Day: ");
- int row, col;
- for (row =0; row<items.length ; row++)
- {
- for(col=0; col<items[row].length; col++)
- {
- System.out.print( items[row][col]+" ");
- }
- System.out.println();
- }
- System.out.println("Cost Per Item: ");
- int i;
- for (i =0; i < 5; i++)
- {
- System.out.println(cost[i]);
- }
- }
- public static void computeCost (double items[][], double cost[])
- {
- int row, col;
- double productArray[]=new double[3];
- for (row =0; row<items.length ; row++)
- {
- for(col=0; col<items[row].length; col++)
- {
- if(col==0)
- {
- productArray[row]=items[row][col]*cost[0];
- System.out.println(productArray[row]+" TEST1 ");
- }
- else if(col==1)
- {
- productArray[row]=items[row][col]*cost[1];
- System.out.println(productArray[row]+" TEST2 ");
- }
- else if(col==2)
- {
- productArray[row]=items[row][col]*cost[2];
- System.out.println(productArray[row]+" TEST3");
- }
- else if(col==3)
- {
- productArray[row]=items[row][col]*cost[3];
- System.out.println(productArray[row]+" TEST4 ");
- }
- else if(col==4)
- {
- productArray[row]=items[row][col]*cost[4];
- System.out.println(productArray[row]+" TEST5 ");
- }
- }
- }
- }
- }
- 300.0 TEST1
- 1148.8 TEST2
- 2185.0 TEST3
- 3892.5 TEST4
- 1092.0 TEST5
- public static void computeCost (double items[][], double cost[]) {
- for (int row = 0; row < items.length; row++) {
- double rowSum = 0.0;
- for(int col = 0; col < items[row].length; col++) {
- double colProduct = productArray[row] = items[row][col] * cost[col];
- rowSum += colProduct;
- System.out.println("Row: " + row + ", Col: " + col + ": " + colProduct);
- }
- System.out.println("Total row " + row + ": " + rowSum);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement