CSC 210 Intro to Computer Programming II (Java) Week 2 -September 15 2018 Employ
ID: 3753687 • Letter: C
Question
CSC 210 Intro to Computer Programming II (Java) Week 2 -September 15 2018 Employee 2 Hours worked: Pay rate: Check amount: Employee 3 Hours worked Pay rate: Check amount Total Amount Paid Employee that worked the most hours for the week The highest number of hours worked by an employee in a day The lowest number of hours worked by an employee on a given day Average number of hours employees work per day Lab: At the end of the semester, a teacher has all of his students grades written on a sheet of paper. Write a program for the teacher to help him input the name of the student, their numeric grade for 2 midterms and a final. The program can be run for each of his classes. Assume that the class size will not exceed 30 (but the class size will vary). The program will show the following: Class summary: Highest grade: Student with highest grade: Lowest grade: Student with lowest grade: Average grade: Student Name Midterm 1 Grade Midterm 2 Grade Final Average Letter GradeExplanation / Answer
import java.util.*;
class Teacher {
String[] student;
int[] mid1, mid2, finl;
public Teacher() {
student = new String[30];
mid1 = new int[30];
mid2 = new int[30];
finl = new int[30];
}
public static void main(String arhs[]) {
Teacher t = new Teacher();
int n;
Scanner sc = new Scanner(System.in);
System.out.println("Enter number of students");
n = sc.nextInt();
int i;
System.out.println("Enter student name, midterm 1 grade, midterm 2 grade and final grade for each student");
int maxG = -1, minG = 1000000, maxS = -1, minS = -1;
double avgG = 0;
for(i=0;i<n;i++) {
t.student[i] = sc.next();
t.mid1[i] = sc.nextInt();
t.mid2[i] = sc.nextInt();
t.finl[i] = sc.nextInt();
maxG = Math.max(maxG, Math.max(t.mid1[i], Math.max(t.mid2[i], t.finl[i])));
if(maxG==t.mid1[i] || maxG == t.mid2[i] || maxG == t.finl[i]) maxS = i;
minG = Math.min(minG, Math.min(t.mid1[i], Math.min(t.mid2[i], t.finl[i])));
if(minG==t.mid1[i] || minG == t.mid2[i] || minG == t.finl[i]) minS = i;
avgG += t.mid1[i]+t.mid2[i]+t.finl[i];
}
avgG/=(n*3);
avgG = Math.round(avgG * 100.0) / 100.0;
System.out.println("Class Summary Highest Grade: "+maxG+" Student with highest grade: "+t.student[maxS]+" Lowest Grade: "+minG+" Student with lowest grade: "+t.student[minS]+" Average grade: "+avgG);
System.out.println("StudentName Midterm1Grade Midterm2Grade Final Average LetterGrade");
for(i=0;i<n;i++) {
double avg = (t.mid1[i]+t.mid2[i]+t.finl[i])/3.0;
avg = Math.round(avg * 100.0) / 100.0;
char letter;
if(avg>=8) letter = 'A';
else if(avg>=6) letter = 'B';
else if(avg>=4) letter = 'C';
else if(avg>=2) letter = 'D';
else letter = 'F';
System.out.println(t.student[i]+" "+t.mid1[i]+" "+t.mid2[i]+" "+t.finl[i]+" "+avg+" "+letter);
}
}
}