Rotate your phone or change to desktop for better experience

Rotate your phone or change to desktop for better experience

Pgm 7 || Program to create a student class with following attributes; Enrollment No: Name, Mark of sub1, Mark of sub2, mark of sub3, Total Marks. Total of the three marks must be calculated only when the student passes in all three subjects. The passing mark for each subject is 50. If a candidate fails in any one of the subjects his total mark must be declared as zero. Using this condition write a constructor for this class.Write separate functions for accepting and displaying student details. In the main method create an array of three student objects and display the details.

 import java.io.*;

import java.util.Scanner;

class Student

{

int rno,sub1,sub2,sub3,total;

String name;

Scanner ins = new Scanner(System.in);

Student()

{

read();

display();

}

void read()

{

System.out.println("Enter Roll Number: ");

rno=ins.nextInt();

System.out.println("Enter Name:");

name=ins.next();

System.out.println("Enter Marks of Subject-1:");

sub1=ins.nextInt();

System.out.println("Enter Marks of Subject-2:");

sub2=ins.nextInt();

System.out.println("Enter Marks of Subject-3:");

sub3=ins.nextInt();

}


void display()

{

if(sub1>=50 && sub2>=50 && sub3>=50)

{

total=sub1+sub2+sub3;

System.out.println("Total Marks is="+total);

}

else

{

total=0;

System.out.println("Your subject Marks is less than 50 marks");

System.out.println("Total Marks is="+total);

}


}

}

class Pgm7

{

public static void main(String args[])

{

Student s1=new Student();

Student s2=new Student();

Student s3=new Student();

}

}

Post a Comment

0 Comments