/*
*Class StudentData is having data members and methods for accepting marks and calculating grades.
*HlyExam (later it can be FinalExam) inherits the class by using extends and accesses the methods *by the object of HlyExam ....
*/
package hlyexam;
/**
*
* @author Somnath
*/
import java.util.Scanner;
class StudentData
{
int p, c, m, b, comp;
float avg;
String name, grade;
void getData()
{
Scanner in = new Scanner(System.in);
System.out.println("Enter student's name ");
name=in.nextLine();
System.out.println("Enter marks for Phy-Chem-Math-Bio-Comp ");
p=in.nextInt();
c=in.nextInt();
m=in.nextInt();
b=in.nextInt();
comp=in.nextInt();
}
void calcData()
{
avg=(p+c+m+b+comp)/5;
if(avg>=90) {
grade="A+";
}
if(avg>=80 && avg <90) {
grade="A";
}
if(avg>=70 && avg <80) {
grade="B";
}
if(avg>=60 && avg <70) {
grade="C";
}
if(avg<60) {
grade="F";
}
}
void showdata()
{
System.out.println("Name is : "+name);
System.out.println("Average is : "+avg);
System.out.println("Grade is : "+grade);
}
}// end of StudentData class
public class HlyExam extends StudentData{
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
HlyExam hly = new HlyExam();
hly.getData();
hly.calcData();
hly.showdata();
}
}
Post the output (share it)
*Class StudentData is having data members and methods for accepting marks and calculating grades.
*HlyExam (later it can be FinalExam) inherits the class by using extends and accesses the methods *by the object of HlyExam ....
*/
package hlyexam;
/**
*
* @author Somnath
*/
import java.util.Scanner;
class StudentData
{
int p, c, m, b, comp;
float avg;
String name, grade;
void getData()
{
Scanner in = new Scanner(System.in);
System.out.println("Enter student's name ");
name=in.nextLine();
System.out.println("Enter marks for Phy-Chem-Math-Bio-Comp ");
p=in.nextInt();
c=in.nextInt();
m=in.nextInt();
b=in.nextInt();
comp=in.nextInt();
}
void calcData()
{
avg=(p+c+m+b+comp)/5;
if(avg>=90) {
grade="A+";
}
if(avg>=80 && avg <90) {
grade="A";
}
if(avg>=70 && avg <80) {
grade="B";
}
if(avg>=60 && avg <70) {
grade="C";
}
if(avg<60) {
grade="F";
}
}
void showdata()
{
System.out.println("Name is : "+name);
System.out.println("Average is : "+avg);
System.out.println("Grade is : "+grade);
}
}// end of StudentData class
public class HlyExam extends StudentData{
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
HlyExam hly = new HlyExam();
hly.getData();
hly.calcData();
hly.showdata();
}
}
Post the output (share it)
No comments:
Post a Comment