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

AT&T; 11:35 100% oo public asu.edu ASU CSE IIU Lab Ry Due date/Time: Monday, Apr

ID: 3814576 • Letter: A

Question

AT&T; 11:35 100% oo public asu.edu ASU CSE IIU Lab Ry Due date/Time: Monday, Apr 10th, 2017 at 5:30pm What this Lab Is About: Learn how to define, intialize and fill a -dimensional array. Learn how to compute the sum of one row or one column ofa 2D array Learn how to compute the sum, average of a 2Darray Coding Guidelines for All LabsAssignments (You wilLhegraded on this) Give identifiers semantic meaning and make them easy to read (examples numStudents. gross Pay, etc) Keep identifiers to a reasonably short length. Use upper case for constants. Use title case (first letter is upper case)for classes. Use lower case with uppercase word separators for all other identifiers (variables, methods, objects). Use tabs or spaces to indent code within blocks (code surrounded by braces). This includes classes, methods, and code associated with ifs, switches and loops. Be consistent with the number of spaces or tabs that you use to indent. Use white space to make your program more readable. Use comments properly before or after the ending brace of classes, methods, and blocks to identify to which block it belongs. 1. Lab Description For this lab, you will create a 3x7two dimensional array to store how many pounds of food three monkeys eats each day in a week. The 2D array is then passed to functions to find total. average and least amount of food consumption, etc. The program then need to display: the average amount of food the three monkeys ate per day the least amount of food eaten all week by any one monkey. each monkey's consumption of food during the week the average of food the 3 monkeys ate on Monday and Saturday. 1.l Step Getting Started Create a class called Lab9. Use the same setup for setting up your class and main method as you did in previous labs and assignments. Be sure to name your file Labs java (again, no empty spaces and special characters are allowed, follow the naming conventions). For documentation purpose, at the beginning of each programming labassignment, you must have a comment block with the following information inside: AUTHOR: your name ASU ID: your 10 digits ASU ID FILENAME: title of the source file SPECIFICATION: description of the program TIME SPENT: how long it took you to complete the lab The general structure of Lab9java should be similar as follows: import java.util. Scanner; import java. text Decimal Format;

Explanation / Answer

/*

Code is Self Explanatory. You can look at the printed statements for explanation.

I have used formating of the numbers using DecimalFormat Class only at three Places. you can apply them to other variables wherever it is needed.

*/

import java.util.Scanner;
import java.text.DecimalFormat;;

public class Lab9 {
  
   public static void main(String[] args) {
       final int NUM_MONKEYS = 3;
       final int NUM_DAYS = 7;
       DecimalFormat fmt = new DecimalFormat();
       Scanner scan = new Scanner(System.in);
      
       double[][] food = new double[NUM_MONKEYS][NUM_DAYS];
      
       for(int monkey=0;monkey<NUM_MONKEYS;monkey++){
           System.out.print("Enter the pounds of food eaten by monkey " + (monkey+1));
           for(int day=0;day<NUM_DAYS;day++){
               System.out.print(" on day " + (day+1) + ":");
               food[monkey][day] = scan.nextDouble();
           }
       }
      
       double groupTotal = findGroupTotal(food);
       System.out.println("Total pounds of food eaten by all three monkeys on all days of week: " + groupTotal);
       double avgPerDay = (groupTotal/21.00);
       System.out.println("Average pounds of food eaten by all three monkeys on all days of week: " + avgPerDay);
       double leastAmtFood = findLeastAmtFood(food);
       System.out.println("Least pounds of food eaten by any of the three monkeys in any of the days of week: " + leastAmtFood);
      
       double totalOne = 0.0;
       for(int day=0;day<NUM_DAYS;day++){
           totalOne += food[0][day];
       }
       System.out.println("Monkey #1 eat total of " + fmt.format(totalOne) + " pounds of food in this week");
      
       double totalTwo = 0.0;
       for(int day=0;day<NUM_DAYS;day++){
           totalTwo += food[1][day];
       }
       System.out.println("Monkey #2 eat total of " + fmt.format(totalTwo) + " pounds of food in this week");
      
       double totalThree = 0.0;
       for(int day=0;day<NUM_DAYS;day++){
           totalThree += food[2][day];
       }
       System.out.println("Monkey #3 eat total of " + fmt.format(totalThree) + " pounds of food in this week");
      
       double totalSunday = 0.0;
       for(int monkey=0;monkey<NUM_MONKEYS;monkey++){
               totalSunday += food[monkey][0];
       }
       double avgSunday = (totalSunday/3.0);
       System.out.println("Total pounds of food eaten by three monkeys on Sunday:" + totalSunday);
       System.out.println("Average pounds of food eaten by three monkeys on Sunday:" + avgSunday);
      
       double totalMonday = 0.0;
       for(int monkey=0;monkey<NUM_MONKEYS;monkey++){
               totalMonday += food[monkey][0];
       }
       double avgMonday = (totalMonday/3.0);
       System.out.println("Total pounds of food eaten by three monkeys on Monday:" + totalMonday);
       System.out.println("Average pounds of food eaten by three monkeys on Monday:" + avgMonday);
      
       double totalTuesday = 0.0;
       for(int monkey=0;monkey<NUM_MONKEYS;monkey++){
               totalTuesday += food[monkey][0];
       }
       double avgTuesday = (totalTuesday/3.0);
       System.out.println("Total pounds of food eaten by three monkeys on Tuesday:" + totalTuesday);
       System.out.println("Average pounds of food eaten by three monkeys on Tuesday:" + avgTuesday);
      
       double totalWednesday = 0.0;
       for(int monkey=0;monkey<NUM_MONKEYS;monkey++){
               totalWednesday += food[monkey][0];
       }
       double avgWednesday = (totalWednesday/3.0);
       System.out.println("Total pounds of food eaten by three monkeys on Wednesday:" + totalWednesday);
       System.out.println("Average pounds of food eaten by three monkeys on Wednesday:" + avgWednesday);
      
       double totalThursday = 0.0;
       for(int monkey=0;monkey<NUM_MONKEYS;monkey++){
               totalThursday += food[monkey][0];
       }
       double avgThursday = (totalThursday/3.0);
       System.out.println("Total pounds of food eaten by three monkeys on Thursday:" + totalThursday);
       System.out.println("Average pounds of food eaten by three monkeys on Thursday:" + avgThursday);
      
       double totalFriday = 0.0;
       for(int monkey=0;monkey<NUM_MONKEYS;monkey++){
               totalFriday += food[monkey][0];
       }
       double avgFriday = (totalFriday/3.0);
       System.out.println("Total pounds of food eaten by three monkeys on Friday:" + totalFriday);
       System.out.println("Average pounds of food eaten by three monkeys on Friday:" + avgFriday);
      
       double totalSaturday = 0.0;
       for(int monkey=0;monkey<NUM_MONKEYS;monkey++){
               totalSaturday += food[monkey][0];
       }
       double avgSaturday = (totalSaturday/3.0);
       System.out.println("Total pounds of food eaten by three monkeys on Saturday:" + totalSaturday);
       System.out.println("Average pounds of food eaten by three monkeys on Saturday:" + avgSaturday);
      
   }
  
   public static double findGroupTotal(double[][] a2DArray){
       double total = 0.0;
      
       for(int monkey=0;monkey<3;monkey++){
           for(int day=0;day<7;day++){
               total += a2DArray[monkey][day];
           }
       }
       return total;
   }
  
   public static double findLeastAmtFood(double[][] a2DArray){
       double leastAmt = a2DArray[0][0];
      
       for(int monkey=0;monkey<3;monkey++){
           for(int day=0;day<7;day++){
               if(a2DArray[monkey][day] < leastAmt){
                   leastAmt = a2DArray[monkey][day];
               }                  
           }
       }
       return leastAmt;
   }

}