-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPercentageIfElse.java
More file actions
77 lines (64 loc) · 1.97 KB
/
PercentageIfElse.java
File metadata and controls
77 lines (64 loc) · 1.97 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
import java.util.Scanner; // #include <iostream>
// DONE
public class PercentageIfElse {
public static void main(String[] args)
{
Scanner obj = new Scanner(System.in);
float sub1 = 0, sub2 = 0, sub3 = 0; // 3 subjects with default asg
float total = 150; // all three subjects
float p1, p2, p3; // individual percentages
float percentage; // total percentage
// PROMPT with validation
do
{
System.out.print(" Enter subject no 1 marks out of 50 : ");
sub1 = obj.nextInt();
} while (sub1 < 0 || sub1 > 50);
do
{
System.out.print(" Enter subject no 2 marks out of 50 : ");
sub2 = obj.nextInt();
} while (sub2 < 0 || sub2 > 50);
do
{
System.out.print(" Enter subject no 3 marks out of 50 : ");
sub3 = obj.nextInt();
} while (sub3 < 0 || sub3 > 50);
// i will use nested if else for this matter
// first calculate indivdidual percentages
p1 = (sub1/50) * 100;
p2 = (sub2/50) * 100;
p3 = (sub3/50) * 100;
if (p1 >= 33)
{
if (p2 >= 33)
{
if (p3 >= 33)
{
float sum = sub1 + sub2 + sub3;
percentage = (sum/total) * 100;
if (percentage >= 40)
{
System.out.println(" CONGRATS! PASSED!");
}
else
{
System.out.println(" FAILED! OVERALL");
}
}
else
{
System.out.println(" FAILED! in sub 3");
}
}
else
{
System.out.println(" FAILED! in sub 2");
}
}
else
{
System.out.println(" FAILED! in sub 1");
}
}
}