Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2014
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.51 KB | None | 0 0
  1. Item
  2.  
  3. Store 0 1 2 3 4
  4. 0 25 64 23 45 14
  5. 1 12 82 19 34 63
  6. 2 54 22 17 32 35
  7.  
  8. Item Cost Per Item
  9. 0 $12.00
  10. 1 $17.95
  11. 2 $95.00
  12. 3 $86.50
  13. 4 $78.00
  14.  
  15. import java.util.*;
  16. public class asd
  17. {
  18. public static void main(String[] args)
  19. {
  20. double items[][]= new double[3][5];
  21. double cost[]=new double[5];
  22. loadArray(items, cost);
  23. System.out.println("Total amount of sales for each store : ");
  24. computeCost(items, cost);
  25. printArray(items, cost);
  26. }
  27. public static void loadArray(double items[][], double cost[])
  28. {
  29. Scanner input = new Scanner(System.in);
  30. String s1;
  31. int num, x, y;
  32. for(x=0; x<items.length;x++)
  33. {
  34. for(y=0; y<items[x].length; y++)
  35. {
  36. System.out.println("Enter the next item of data:");
  37. items[x][y]=input.nextDouble();
  38. }
  39. }
  40.  
  41. //Cost of the items:
  42. cost[0]=12.00;
  43. cost[1]=17.95;
  44. cost[2]=95.00;
  45. cost[3]=86.50;
  46. cost[4]=78.00;
  47. }
  48. public static void printArray(double items[][], double cost[])
  49. {
  50. System.out.println("Number of items Sold During Day: ");
  51. int row, col;
  52. for (row =0; row<items.length ; row++)
  53. {
  54. for(col=0; col<items[row].length; col++)
  55. {
  56. System.out.print( items[row][col]+" ");
  57. }
  58. System.out.println();
  59. }
  60. System.out.println("Cost Per Item: ");
  61. int i;
  62. for (i =0; i < 5; i++)
  63. {
  64. System.out.println(cost[i]);
  65. }
  66. }
  67. public static void computeCost (double items[][], double cost[])
  68. {
  69. int row, col;
  70. double productArray[]=new double[3];
  71. for (row =0; row<items.length ; row++)
  72. {
  73. for(col=0; col<items[row].length; col++)
  74. {
  75. if(col==0)
  76. {
  77. productArray[row]=items[row][col]*cost[0];
  78. System.out.println(productArray[row]+" TEST1 ");
  79. }
  80. else if(col==1)
  81. {
  82. productArray[row]=items[row][col]*cost[1];
  83. System.out.println(productArray[row]+" TEST2 ");
  84. }
  85. else if(col==2)
  86. {
  87. productArray[row]=items[row][col]*cost[2];
  88. System.out.println(productArray[row]+" TEST3");
  89. }
  90. else if(col==3)
  91. {
  92. productArray[row]=items[row][col]*cost[3];
  93. System.out.println(productArray[row]+" TEST4 ");
  94. }
  95. else if(col==4)
  96. {
  97. productArray[row]=items[row][col]*cost[4];
  98. System.out.println(productArray[row]+" TEST5 ");
  99. }
  100. }
  101. }
  102. }
  103. }
  104.  
  105. 300.0 TEST1
  106. 1148.8 TEST2
  107. 2185.0 TEST3
  108. 3892.5 TEST4
  109. 1092.0 TEST5
  110.  
  111. public static void computeCost (double items[][], double cost[]) {
  112. for (int row = 0; row < items.length; row++) {
  113. double rowSum = 0.0;
  114. for(int col = 0; col < items[row].length; col++) {
  115. double colProduct = productArray[row] = items[row][col] * cost[col];
  116. rowSum += colProduct;
  117. System.out.println("Row: " + row + ", Col: " + col + ": " + colProduct);
  118. }
  119.  
  120. System.out.println("Total row " + row + ": " + rowSum);
  121. }
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement