Write a program in java that calculate percentage marks of the student if marks of 6 subjects are given(using else-if)


Write a program that calculate percentage marks of the student if marks of 6 subjects are given(using else-if)

import java.util.Scanner;

class Percentage
{
int sub1;
int sub2;
int sub3;
int sub4;
int sub5;
int sub6;

String name;
String roll_no;

float per()
{
float ans = (sub1 + sub2 + sub3 + sub4 + sub5 + sub6)/6;
return ans;
}

void display()
{
float ans=per();
System.out.println("Student Name :" +name);
System.out.println("Student Roll_no :" +roll_no);
System.out.println("Student Percentage :" +ans+"%");

if(ans>85)
System.out.println("Congratulations...!!! You having 1st/Distinction class :");
else if(ans>75)
System.out.println("You having 2nd class :");
else if(ans>65)
System.out.println("You having pass class :");
else
System.out.println("Sorry...!!! You can not clear this examination :");

}

}

class PercentageDemo
{
public static void main(String arg[])
{
Percentage s1=new Percentage();
Scanner s=new Scanner(System.in);

System.out.println("Enter Marks of Subject-1 :");
s1.sub1=s.nextInt();
System.out.println("Enter Marks of Subject-2 :");
s1.sub2=s.nextInt();
System.out.println("Enter Marks of Subject-3 :");
s1.sub3=s.nextInt();
System.out.println("Enter Marks of Subject-4 :");
s1.sub4=s.nextInt();
System.out.println("Enter Marks of Subject-5 :");
s1.sub5=s.nextInt();
System.out.println("Enter Marks of Subject-6 :");
s1.sub6=s.nextInt();

System.out.println("Enter Your name :");
s1.name=s.next();

System.out.println("Enter Your Roll_number :");
s1.roll_no=s.next();

s1.display();
}

}

Comments

Popular posts from this blog

Write a java program to calculate gross salary & net salary taking the following data

WAP a program that illustrates interface inheritance. Create two interface p1 and p2 . create Interface p which extends p1 and p2 and then create interface p12 which extends p12. Each interface declare one constants and one method. Create class Q which implements p12 and define all the methods of interface which displays value of constants

WAP that create interface on that you declare one method interest(p,r,n) then create two class simple and compound that implements interest and find simple and compound interest.