0

Help me

public class Result_Card { int English; int Islamiat; int Math; int english(int eng){ English = eng; return English; } int islamiat(int isl){ Islamiat = isl; return Islamiat; } int math(int math){ Math = math; return Math; } int total(){ return English + Islamiat + Math; } float average(){ return ((English + Islamiat + Math)*100)/300; } } public class Main { public static void main(String[] args) { Result_Card Subject = new Result_Card(); System.out.println(Subject.english(50)); System.out.println(Subject.islamiat(60)); System.out.println(Subject.math(70)); System.out.println("Total: " + Subject.total()); System.out.println("Average: " + Subject.average() + "%"); } }

25th Apr 2022, 2:33 AM
kalsoom akhtar
kalsoom akhtar - avatar
4 Answers
+ 2
Average méthode must return float value. You Can Do this double average(){ return ((English + Islamiat + Math)*100.0)/300.0; } Or float average(){ return ((float)(English + Islamiat + Math)*100)/300; } Good pratice : attribut must be in camelCase (int english; int islamiat; ...)
25th Apr 2022, 6:50 AM
Roland
Roland - avatar
+ 1
There are no error in your program running perfectly just one correction required average method return the float value👍
25th Apr 2022, 4:46 AM
Raj D-Coder
Raj D-Coder - avatar
+ 1
if input is 60 +70 +70 average is 200/3 = 66.6666666 but your code prints 66.0 because result of dividing two int a / b is integer instead of float (float) a / b
25th Apr 2022, 5:53 AM
zemiak
0
It is giving one error
25th Apr 2022, 2:34 AM
kalsoom akhtar
kalsoom akhtar - avatar