forked from sonumahajan/All_Program_helper
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudentGrades.java
More file actions
96 lines (85 loc) · 2.88 KB
/
StudentGrades.java
File metadata and controls
96 lines (85 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import java.util.Scanner;
public class StudentGrades
{
public static void main(String[] args)
{
//String array to hold first names
String firstName[] = new String[5];
//string array to hold last name
String lastName[] = new String[5];
//double array to hold average
double average[] = new double[5];
//double 2 dimensional array to hold grades
double[][] studentGrades = new double[5][3];
//variable to hold over seventy
int overSeventy = 0;
//scanner object
Scanner in = new Scanner(System.in);
//for loop to create array of first name and last name
for(int i = 0; i < 5; i++)
{
//prompt user
System.out.print("Enter the first name: ");
firstName[i] = in.nextLine();//user input
//prompt user
System.out.print("Enter the last name: ");
lastName[i] = in.nextLine();//user input
}//for
//Display students names
//print underline
System.out.println("----------------------");
//for loop to display firstname and last name form arrays
for(int i = 0; i < 5; i++)
{
// print names
System.out.println(firstName[i] + " " + lastName[i]);
}//for
System.out.println();// blank lines
//store student grades
// first for loop to create rows
for(int row = 0; row < studentGrades.length; row++)
{
//second for loop to create columns
for(int column = 0; column < studentGrades[row].length; column++)
{
//prompt the user to enter grades
System.out.println("Enter grade for each course for " + firstName[row] +
" " + lastName[row]);
//Prompting to enter course grade
System.out.println("Course" + (column+1) + ": ");
studentGrades[row][column] = in.nextDouble();//user input
}//end column for
}//end row for
//Print Table
System.out.println(" Student Grades ");
System.out.println(" Class1 class 2 class3 ");
System.out.println("----------------------------------------------");
//print student names and test scores
for(int row = 0; row < studentGrades.length; row++)
{
System.out.print(firstName[row] + " " + lastName[row] + " ");
//for loop to print names and grades
for(int column = 0; column < studentGrades[row].length; column++)
{
System.out.print(studentGrades[row][column] +" ");
}
System.out.println();
}//end for
//find the average
for(int i = 0; i < 5; i++)
{
average[i] = (studentGrades[i][0] + studentGrades[i][1] +
studentGrades[i][2]) / 3;
//If average over 70, increase over seventy
if(average[i] > 70)
overSeventy += 1;
}//for
System.out.println();// Blank lines
//If half of the students are over 70% print message
if(overSeventy > 2)
System.out.println("Tution is being incresed by 10% for the next semester");
//If half of the students are under 70% print message
else
System.out.println("Tution will not be increased");
}//class
}//main