On the final part of a project i'm doing for school, I am supposed to use a if-else
statement inside a for
loop, but I have no idea how to do this. I could just use a huge lot of if-else
statements to do the same thing, but I dont think my teacher would appreciate it.
Here are the instructions for the final part of the homework...
Compute the Grade (A, B, C, D or F) and store in another Array8 called grades using if-else loop and the following cutoff inside a for-loop to assign grades.
1. Average Grade 2. >= 90 A 3. >=80 and <90 B 4. >=70 and <80 C 5. >=60 and <70 D 6. <60 F
This is my code so far...
public class Proj5 {
public static void main (String[] args) {
String[] Array1= {new String("Adam"),new String("Smith"),new String("Jones"),new String("Becky"),new String("Taylor")};
Integer[] Array2={new Integer(90),new Integer(89),new Integer(86),new Integer(76),new Integer(95)};
Integer[] Array3={new Integer(92),new Integer(79),new Integer(85),new Integer(90),new Integer(87)};
Integer[] Array4={new Integer(93),new Integer(80),new Integer(90),new Integer(87),new Integer(92)};
Integer[] Array5={new Integer(90),new Integer(77),new Integer(86),new Integer(92),new Integer(89)};
double av1 = (((Array2[0]+Array3[0]+Array4[0])/3));
double av2 = (((Array2[1]+Array3[1]+Array4[1])/3));
double av3 = (((Array2[2]+Array3[2]+Array4[2])/3));
double av4 = (((Array2[3]+Array3[3]+Array4[3])/3));
double av5 = (((Array2[4]+Array3[4]+Array4[4])/3));
double[] Array6 = {(av1),(av2),(av3),(av4),(av5)};
double avf1 = (av1*.30)+(Array5[0]*.7);
double avf2 = (av2*.30)+(Array5[1]*.7);
double avf3 = (av3*.30)+(Array5[2]*.7);
double avf4 = (av4*.30)+(Array5[3]*.7);
double avf5 = (av5*.30)+(Array5[4]*.7);
double[] Array7 = {(avf1),(avf2),(avf3),(avf4),(avf5)};
System.out.println("Report for Spring Semester 2009"+
"\n-------------------------------------------");
System.out.println("Name Test1 Test2 Test3 Final Average Grade");
for (int column = 0; column<Array1.length; column++){
System.out.printf("%s ", Array1[column]);
System.out.printf("%s ", Array2[column]);
System.out.printf("%s ", Array3[column]);
System.out.printf("%s ", Array4[column]);
System.out.printf("%s ", Array5[column]);
System.out.printf("%s ", Array7[column]);
System.out.println(); //start new line of output
}
}
}