פתרון השאלה במטלה של שיעורי הבית

 

 

 

int maxTime,minTime,total,currTime;

String currName,minName,maxName;

int N = 25;

System.out.println("Please insert student name");

currName = reader.next();

System.out.println("Please insert "+currName+" reading time");

currTime = reader.nextInt();

total = currTime;

maxTime = currTime;

minTime = currTime;

maxName = currName;

minName = currName;

        

for (int i=0;i<N-1;i++) {

         System.out.println("Please insert student name");

         currName =  reader.next();

         System.out.println("Please insert "+currName+" reading time");

        

         currTime = reader.nextInt();

        

         System.out.println("The student "+ currName+" has "+currTime+" reading time");

         if (currTime > maxTime) {

                 maxTime = currTime;

                 maxName = currName;

         }

         if (currTime < minTime) {

                 minTime = currTime;

                 minName = currName;

         }

         total += currTime;

}

System.out.println("The student "+maxName+" with longest time : "+maxTime);

System.out.println("The student "+minName+" with shotest time : "+minTime);

int h,m;

h = total/60;

m = total%60;

System.out.println("Total reading time is : "+h+" hours and "+m+" minutes");

double avg = (double)total/N;

System.out.println("avg = "+avg);