I need a little help with an assignment. I have a table that I turned into an ar
ID: 3622023 • Letter: I
Question
I need a little help with an assignment. I have a table that I turned into an array. I need help writing a code for java that takes a table that I turned into a 2-d array and now need help trying to find the max total students per day (max of all day sums) & max students per tutor (max of all tutor sums) using max1dArray() as a method.
int [][] tutorData = {
{25,3,0},
{14,5,12},
{33,22,10},
{0,20,5}}
tutor
Mon
Tue
Wed
Amy
25
3
0
John
14
5
12
Nick
33
22
10
Maria
0
20
5
tutor
Mon
Tue
Wed
Amy
25
3
0
John
14
5
12
Nick
33
22
10
Maria
0
20
5
Explanation / Answer
please rate - thanks
import java.io.*;
import java.util.*;
public class tutors
{public static int numOfTutors;
public static void main(String[] args)
{int i,j,total=0,max,min,totalStudents=0;
numOfTutors=4;
int [][] tutorData = {
{25,3,0},
{14,5,12},
{33,22,10},
{0,20,5}};
String names[]={"Amy","John","Nick","Maria"};
int[] sumPerDay=new int[3];
int[] sumPerTutor=new int[numOfTutors];
for(i=0;i<3;i++)
sumPerDay[i]=0;
for(i=0;i<numOfTutors;i++)
sumPerTutor[i]=0;
for(i=0;i<numOfTutors;i++)
for(j=0;j<3;j++)
sumPerTutor[i]+=tutorData[i][j];
for(i=0;i<3;i++)
for(j=0;j<numOfTutors;j++)
sumPerDay[i]+=tutorData[j][i];
for(i=0;i<3;i++)
totalStudents+=sumPerDay[i];
System.out.println(" Usage");
System.out.println("tutor Mon Tue Wed Total");
for(i=0;i<numOfTutors;i++)
{System.out.print(names[i]);
for(j=0;j<3;j++)
System.out.print(" "+tutorData[i][j]);
System.out.println(" "+sumPerTutor[i]);
}
System.out.print("Daily Total ");
for(i=0;i<3;i++)
System.out.print(sumPerDay[i]+" ");
System.out.println();
System.out.println(" Total number of students using the center: "+totalStudents);
System.out.println("Max of days "+max1dArray(sumPerDay,3)+"-min of days "+min1dArray(sumPerDay,3));
System.out.println("max of tutors "+max1dArray(sumPerTutor,numOfTutors)+"-min of tutors "+min1dArray(sumPerTutor,numOfTutors));
}
public static int max1dArray(int a[],int n)
{int i,m=a[0];
for(i=1;i<n;i++)
if(a[i]>m)
m=a[i];
return m;
}
public static int min1dArray(int a[],int n)
{int i,m=a[0];
for(i=1;i<n;i++)
if(a[i]<m)
m=a[i];
return m;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.