0% found this document useful (0 votes)
562 views11 pages

Experiment No.5: (For Applied/experimental Sciences/materials Based Labs)

The document describes a programming experiment in Java that implements an interface called Student with methods to display grade and attendance for postgraduate and undergraduate student classes, with the program defining these classes and interfaces and including a main method to create objects and call their methods to output student data. The experiment demonstrates using interfaces to group related methods and creating classes that implement interfaces to define behavior for different types of students.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
562 views11 pages

Experiment No.5: (For Applied/experimental Sciences/materials Based Labs)

The document describes a programming experiment in Java that implements an interface called Student with methods to display grade and attendance for postgraduate and undergraduate student classes, with the program defining these classes and interfaces and including a main method to create objects and call their methods to output student data. The experiment demonstrates using interfaces to group related methods and creating classes that implement interfaces to define behavior for different types of students.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Experiment No.

5
Write a program in java that implements interface Student which has two methods Display_Grade and
Attendance for PG_Students and UG_Students (PG_Students and UG_Students are two different classes for
Post Graduate and Under Graduate Students respectively).

Student Name: Anshul Verma UID:19BCS3537


Branch: CSE –IS Section/Group - A
Semester: 3rd Date of Performance:
Subject Name - Programming in java lab Subject Code: CSP 218

1. Aim/Overview of the practical:

Write a program in java that implements interface Student which has two methods
Display_Grade and Attendance for PG_Students and UG_Students (PG_Students
and UG_Students are two different classes for Post Graduate and Under Graduate
Students respectively).
2. Task to be done:

To create interface for displaying attendance and grade of PG and UG students.

3. Apparatus(For applied/experimental sciences/materials based labs):

1. System with any Operating System.


2. Jdk
3. Ide or any other Texteditor

4. Algorithm/Flowchart (For programming based labs):

1. Create a interface class


2. Create two abstract method for grade and attendance respectively inside
interface.
3. Create a class which inherite the properties of interface class.
4. Now give the functions to those abstract classes.
5. Create a main class and initialize the value there.
6. Create the objets of the methods.
7. Exit.

5. Theme/Interests definition( For creative domains):

Interface: An interface is a abstract class that is used to group related methods


with empty bodies.

Java:-Java is a class-based, object-oriented programming language that is


designed to have as few implementation dependencies as possible.

Java Class:-
Java is an object-oriented programming language. Everything in Java is associated
with classes and objects, along with its attributes and methods. ... A Class is like an
object constructor, or a "blueprint" for creating objects.
6. Steps for experiment/practical:

Step1-Open Ide “Eclipse ide”.


Step2-Left click on file form menu tab.
Step 3-Select new Java project.
Step 4-Click on project and select package.
Step 5-Click on package select new class.
Step 6-Now you successfully create class,start programming

Program:-

interface Student

void Display_Grade();

void Display_Atten();

class PG_Student implements Student

String name, grade;


int m1, m2, m3, attendence, total;

PG_Student(String name, int m1, int m2, int m3, int attendence)

this.name = name;

this.m1 = m1;

this.m2 = m2;

this.m3 = m3;

this.attendence = attendence;

void Display()

System.out.println("Name is " + name);

System.out.println("Marks are " + m1 + " " + m2 + " " + m3);

public void Display_Atten()

System.out.println("The attendence is " + attendence);

public void Display_Grade()

{
total = m1 + m2 + m3;

if (total > 250)

grade = "A";

else if (total < 250)

grade = "B";

} else if (total < 200)

grade = "C";

else

grade = "D";

System.out.println("The Grade is " + grade);

class UG_Student implements Student


{

String name, grade;

int m1, m2, m3, attendence, total;

UG_Student(String name, int m1, int m2, int m3, int attendence)

this.name = name;

this.m1 = m1;

this.m2 = m2;

this.m3 = m3;

this.attendence = attendence;

void Display()

System.out.println("Name is " + name);

System.out.println("Marks are " + m1 + " " + m2 + " " + m3);

public void Display_Atten()

System.out.println("The attendence is " + attendence);

}
public void Display_Grade()

total = m1 + m2 + m3;

if (total > 300)

grade = "S";

else if (total > 250)

grade = "A";

else if (total < 250)

grade = "B";

else if (total < 200)

grade = "C";

else
{

grade = "D";

System.out.println("The Grade is " + grade);

class Demo {

public static void main(String[] args) {

PG_Student pg = new PG_Student("Alex", 45, 68, 47, 35);

pg.Display();

pg.Display_Atten();

pg.Display_Grade();

UG_Student ug = new UG_Student("Aman", 95, 88, 77, 25);

ug.Display();

ug.Display_Atten();

ug.Display_Grade();

}
7. Observations/Discussions(For applied/experimental sciences/materials based labs):

In this program we observe the range of grade put by the user and the uses of
interface
8. Percentage error (if any or applicable):

There is no percentage error.

9. Result/Output/Writing Summary:
10. Graphs (If Any): Image /Soft copy of graph paper to be attached here

There is no Graphs in this Practical.


Learning outcomes (What I have learnt):

1. We learned about the uses of interface

2. We learned about the uses of different methods

3. We learned about how to create objects

Evaluation Grid (To be created as per the SOP and Assessment guidelines by the faculty):

Sr. No. Parameters Marks Obtained Maximum Marks


1.
2.
3.

You might also like