-
Notifications
You must be signed in to change notification settings - Fork 0
/
Result.java
221 lines (146 loc) · 4.47 KB
/
Result.java
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
import java.util.Scanner;
class Result {
private double[] course1;
private double[] course2;
private double[] course3;
private double[] gpa1;
private double[] gpa2;
private double[] gpa3;
private int size1;
private int size2;
private int size3;
Scanner sc = new Scanner(System.in);
public void setSize1(int size1) {
if (size1 >= 0) {
this.size1 = size1;
}
else{
System.out.println("Invalid Size - !");
}
}
public int getSize1() {
if (this.size1 != 0) {
return size1;
}else{
return 1;
}
}
public void setSize2(int size2) {
if (size2 >= 0) {
this.size2 = size2;
}
else{
System.out.println("Invalid Size - !");
}
}
public int getSize2() {
if (this.size2 != 0) {
return size2;
}else{
return 1;
}
}
public void setSize3(int size3) {
if (size3 >= 0) {
this.size3 = size3;
}
else{
System.out.println("Invalid Size - !");
}
}
public int getSize3() {
if (this.size3 != 0) {
return size3;
}else{
return 1;
}
}
Result(int size1, int size2, int size3){
setSize1(size1);
setSize2(size2);
setSize3(size3);
course1 = new double[size1];
gpa1 = new double[size1];
course2 = new double[size2];
gpa2 = new double[size2];
course3 = new double[size3];
gpa3 = new double[size3];
}
public void getMarks(){
System.out.println("Total Courses: " + (size1+size2+size3));
System.out.println();
System.out.println("Enter 3 Cerdit Course Marks");
for (int i = 0; i < getSize3(); i++) {
System.out.print("Course - " + (i+1) + ": ");
course3[i] = sc.nextDouble();
}
System.out.println();
System.out.println("Enter 2 Credit Course Marks");
for (int i = 0; i < getSize2(); i++) {
System.out.print("Course - " + (i+1) + ": ");
course2[i] = sc.nextDouble();
}
System.out.println();
System.out.println("Enter 1 Credit Course Marks");
for (int i = 0; i < getSize1(); i++) {
System.out.print("Course - " + (i+1) + ": ");
course1[i] = sc.nextDouble();
}
System.out.println();
}
public double calculateGPA(double courseMarks){
double per = courseMarks ;
double GPA = 0.0;
if (per >= 90 && per <= 100) {
GPA = 4.0;
} else if (per >= 85 && per < 90) {
GPA = 3.75;
} else if (per >= 80 && per < 85) {
GPA = 3.5;
} else if (per >= 75 && per < 80) {
GPA = 3.25;
} else if (per >= 70 && per < 75) {
GPA = 3.0;
} else if (per >= 66 && per < 70) {
GPA = 2.75;
} else if (per >= 63 && per < 66) {
GPA = 2.5;
} else if (per >= 60 && per < 63) {
GPA = 2.0;
} else if (per >= 55 && per < 60) {
GPA = 1.5;
} else if (per >= 0 && per < 55) {
GPA = 0.0;
} else {
System.out.println("Invalid Input or Error !");
}
return GPA;
}
public void calculateResult(){
double total = 0.0;
total = total + getSize1();
total = total + (getSize2()*2);
total = total + (getSize3()*3);
double total1 = 0.0;
double total2 = 0.0;
double total3 = 0.0;
for (int i = 0; i < getSize1(); i++) {
total1 = total1 + calculateGPA(course1[i]);
}
for (int i = 0; i < getSize2(); i++) {
total2 = total2 + calculateGPA(course2[i]);
}
for (int i = 0; i < getSize3(); i++) {
total3 = total3 + calculateGPA(course3[i]) ;
}
total2 = total2 * 2;
total3 = total3 * 3;
double megaTotal = total1 + total2 + total3;
double CGPA = megaTotal / total;
System.out.println("CGPA: " + CGPA);
}
}
class Main5 {
public static void main(String[] args) {
}
}