0% found this document useful (0 votes)
38 views6 pages

20BCE1723 Java Da1

The document provides examples of Java programs that demonstrate various OOP concepts: 1. A Student class with attributes like enrollment number, name, subject marks, total marks. It calculates total only if student passes all subjects. An array of Student objects is created and details displayed. 2. An Employee class with name and appointment date attributes. An array of Employee objects is sorted based on appointment date to print in seniority order. 3. A Box class with a parameterized volume method. Two Box objects are created and their volumes printed. The document contains code snippets for classes implementing different OOP concepts like classes, arrays, methods, inheritance.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views6 pages

20BCE1723 Java Da1

The document provides examples of Java programs that demonstrate various OOP concepts: 1. A Student class with attributes like enrollment number, name, subject marks, total marks. It calculates total only if student passes all subjects. An array of Student objects is created and details displayed. 2. An Employee class with name and appointment date attributes. An array of Employee objects is sorted based on appointment date to print in seniority order. 3. A Box class with a parameterized volume method. Two Box objects are created and their volumes printed. The document contains code snippets for classes implementing different OOP concepts like classes, arrays, methods, inheritance.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Digital Assignment-1

1. Write a java program to create a Student class with following attributes.


Enrolment 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 pass 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.

Code:
import java.util.*;
public class student
{
Scanner sc= new Scanner(System.in);
String Enrollment_No;
String name;
int mks_sub1,mks_sub2,mks_sub3;
int total_mks;
student()
{
accept();
if(mks_sub1<50||mks_sub2<50||mks_sub3<50)
total_mks=0;
else
total_mks=mks_sub1+mks_sub2+mks_sub3;

}
void accept()
{
System.out.println("Enter Enrollment Nunber: ");
Enrollment_No=sc.nextLine();
System.out.println("Enter Name: ");
name=sc.nextLine();
System.out.println("Enter marks obtained in 1st subject: ");
mks_sub1=sc.nextInt();
System.out.println("Enter marks obtained in 2nd subject: ");
mks_sub2=sc.nextInt();
System.out.println("Enter marks obtained in 3rd subject: ");
mks_sub3=sc.nextInt();
}
void display()
{
System.out.println("Enrollment Nunber of the student:"+Enrollment_No);
System.out.println("Name of the student:"+name);
System.out.println("Marks obtained in 1st subject:"+mks_sub1);
System.out.println("Marks obtained in 2nd subject:"+mks_sub2);
System.out.println("Marks obtained in 3rd subject:"+mks_sub3);
System.out.println("Total marks obtained:"+total_mks);
}
public static void main(String args[])
{
student s[]=new student[3];
for(int i=0;i<3;i++)
s[i]=new student();
for(int i=0;i<3;i++)
s[i].display();
}
}

2. Write a Java program to define a class called employee with the name and date of
appointment. Create ten employee objects as an array and sort them as per their date
of appointment. ie, print them as per their seniority.

import java;

class employee

String name;

Date appdate;

public employee(String nm,Date apdt)

name=nm;

appdate=apdt;

public void display()

{
System.out.println("employee name:"+name+" appoinment date:"+
appdate.getDate()+"/" +appdate.getMonth()+"/"+appdate.getYear());

class EmployeeDemo

public static void main(String as[])

employee emp[]=new employee[5];

emp[0]=new employee("shaha PD",new Date(1999,05,22));

emp[1]=new employee("Patil AS",new Date(2000,01,12));


emp[2]=new employee("Phadake PV",new Date(2009,04,25));

emp[3]=new employee("Shinde SS",new Date(2005,02,19));

emp[4]=new employee("Shrivastav RT",new Date(2010,01,01));

System.out.println("List of employees");

for(int i=0;i<emp.length;i++)

emp[i].display();

for(int i=0;i<emp.length;i++)

{
for(int j=0;j<emp.length;j++)

if(emp[i].appdate.after(emp[j].appdate))

employee t=emp[i];

emp[i]=emp[j];

emp[j]=t;

}
}

System.out.println("List of employees seniority wise");

for(int i=0;i<emp.length;i++)
emp[i].display();

3. Develop a java application to make use of a parameterized method inside a class.


Take the following case: Create a class Box and define a method in this class which
will return the volume of the box. Initialize two objects for your class and print out
the volumes respectively.
4. Write a java program using interface concepts and abstract class.
5. Write a java program using Package concept

You might also like