Write a program to find the percentage and decide the result of a student using function in java.

Introduction:

Hii everyone, here we are constructing a program to help the teachers to find there student’s result status.In this, we are going to construct our program in function and the interesting part of this program is we take here p,c,m.As I suppose you have read PCM at least once in your lifetime, so let’s recall it again!.

Description Of Program:

First of all, we have to decide our required parameters and initialise those parameters globally, moving forward made a constructor and input a scanner, since our program is going to be user flexible(user will be able to enter the data according to there need), then we made a function to check the result we take double as a data type of “percent”  so that we could have exact value of the percentage obtained by the student,set the required condition to pass the session and then put it in the “if” condition. Again construct the main function and define a new function for the result so that the system can provide the required space for the new statement made.Hope it would be helpful.                         Thank You!

CODE:
package oops;

import java.util.Scanner;
public class Result {
int rollnumber,max,p,c,m;
public Result(){
Scanner s=new Scanner(System.in);
System.out.println(“Enter RollNumber,Maximum Marks,Physics, Maths and Chemistry”);
rollnumber=s.nextInt();
max=s.nextInt();
p=s.nextInt();
c=s.nextInt();
m=s.nextInt();
}

public double CheckResult(){
double percent=(double)((p+c+m)/(3.0*max))*100.0;
System.out.println(“Percetage obtained by student”+percent);
if(percent<=30)
System.out.println(“Fail”);
else
System.out.println(“Pass”);
return percent;
}

public static void main(String[] args) {
Result r=new Result();
double p=r.CheckResult();
System.out.println(p);

}
}

OUTPUT :

 

Leave a Reply