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

Question: import java.util.Scanner; public class Lab_Q2 { public static void mai

ID: 3547640 • Letter: Q

Question

Question:


import java.util.Scanner;

public class Lab_Q2 {
    
    public static void main(String [] args)
    {
       Scanner input = new Scanner(System.in);
       
        double [][] sales = new double [3][5];
        double [] totalsales = new double [3];
        
        int i=0;
        int j=0;
        double average=0;
        
        for(i=0; i<3; i++)
        {
            System.out.println("Employee "+(i+1));
            
            for(j=0; j<5; j++)
            {
                
                System.out.print("Day "+(j+1)+": $");
                sales[i][j] = input.nextDouble();
                
            }
            System.out.print(" ");
        }
        
        getTotalSales(sales,totalsales);
        
        for(i=0 ;i<3; i++)
        {
            
            System.out.println("Employee "+(i+1)+" total sales :"+totalsales[i]);
            
        }
        
        average=getAverage(sales);
        
        System.out.println("Average sales for this week: $ "+average);
        
    }
    
    public static void getTotalSales(double [][] sales, double [] totalsales)
    {
        int i=0;
        int j=0;
        
        for(i=0; i<3; i++)
        {
            for(j=0; j<5; j++)
            {
                totalsales[i]+=sales[i][j];
      
            }
        }
           
    }
    
    public static int findHighest(double [] totalsales)
    {
        int highest=0;
        
        if(totalsales[0]>totalsales[1])
         
            System.out.println("Highest sales Employee 1");
        
        else if(totalsales[1]>totalsales[0])
            
           System.out.println("Highest sales Employee 2");
            
        else if(totalsales[2]>totalsales[1])
            
           System.out.println("Highest sales Employee 3");
        
        else if(totalsales[1]>totalsales[2])
            
           System.out.println("Highest sales Employee 2");

         else if(totalsales[2]>totalsales[0])
            
           System.out.println("Highest sales Employee 3");      

         else if(totalsales[0]>totalsales[2])
            
           System.out.println("Highest sales Employee 1");
        
        else
         {
             
         }
        
        return highest;
    }
    
    public static double getAverage(double[][] sales)
    {

        double average=0;
        int i=0;
        int j=0;
        
        for(i=0; i<3; i++)
        {
            for(i=1; i<5; i++)
            {
              
                average+=sales[i][j];
                
            }
            
        }
        
        average=average/3;
        
        return average;
        
    }
    
    
}


Please correct my error, explain using comment.

following by this output:


Day 1: $2500.00 Day 2: $3510.50 Day 3: $1650.50 Day 4: $3340.00 Day 5: $1000.00 Employee 2 : Day 1: $3478.50 Day 2: $2136.30 Day 3: $123.45 Day 4: $486.00 Day 5: $1500.00 Employee 3: Day 1: $2830.00 Day 2: $1450.50 Day 3: $3667.00 Day 4: $1456.50 Day 5: $789.90 Weekly Sales Report Total Sales per person: Employee 1: $ 12001.00 Employee 2: $ 7724.25 Employee 3: $ 10193.90 Highest sales: Employee 1 Total collection of sales for this week: $ 29919.15 Average sales for this week: $ 9973.05

Explanation / Answer

/*i have corrected all the error's and shown in comments what was wrong

if any problem,understanding the code,please let me know by commenting on the solution

*/

Solution:

import java.util.Scanner;


public class Lab_Q2 {


public static void main(String [] args)

{

Scanner input = new Scanner(System.in);


double [][] sales = new double [3][5];

double [] totalsales = new double [3];


int i=0;

int j=0;

double average=0;


for(i=0; i<3; i++)

{

System.out.println("Employee "+(i+1));


for(j=0; j<5; j++)

{


System.out.print("Day "+(j+1)+": $");

sales[i][j] = input.nextDouble();


}

System.out.print(" ");

}


getTotalSales(sales,totalsales);


for(i=0 ;i<3; i++)

{


System.out.println("Employee "+(i+1)+" total sales :"+totalsales[i]);


}

findHighest(totalsales); //you misses this statement to print highest sale

System.out.println("Total collection of sales for this week:$"+(totalsales[0]+totalsales[1]+totalsales[2]));//you also //missed this to //print total collection


average=getAverage(sales);


System.out.println("Average sales for this week: $ "+average);


}


public static void getTotalSales(double [][] sales, double [] totalsales)

{

int i=0;

int j=0;


for(i=0; i<3; i++)

{

for(j=0; j<5; j++) //your were using 'i' in this loop as well

{

totalsales[i]+=sales[i][j];


}

}


}


public static int findHighest(double [] totalsales)

{

int highest=0;


if(totalsales[0]>totalsales[1])


System.out.println("Highest sales Employee 1");


else if(totalsales[1]>totalsales[0])


System.out.println("Highest sales Employee 2");


else if(totalsales[2]>totalsales[1])


System.out.println("Highest sales Employee 3");


else if(totalsales[1]>totalsales[2])


System.out.println("Highest sales Employee 2");


else if(totalsales[2]>totalsales[0])


System.out.println("Highest sales Employee 3");


else if(totalsales[0]>totalsales[2])


System.out.println("Highest sales Employee 1");


else

{


}


return highest;

}


public static double getAverage(double[][] sales)

{


double average=0;

int i=0;

int j=0;


for(i=0; i<3; i++)

{

for(j=0; j<5; j++) //you assigned 'j' to intially 1 instead of 0

{


average+=sales[i][j];


}


}


average=average/3;


return average;


}



}


Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote