0% found this document useful (0 votes)
67 views32 pages

Object Oriented Concepts LAB

This document contains a lab report submitted by a student named Ashter Mendes for their Object Oriented Concepts lab. It includes an index listing 7 programs completed by the student with their date and title. For each program, it provides the full Java code and sample input/output. The programs cover concepts like calculating area, checking prime numbers, accepting student/employee details, and a menu-driven employee management program.

Uploaded by

ashter mendes
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)
67 views32 pages

Object Oriented Concepts LAB

This document contains a lab report submitted by a student named Ashter Mendes for their Object Oriented Concepts lab. It includes an index listing 7 programs completed by the student with their date and title. For each program, it provides the full Java code and sample input/output. The programs cover concepts like calculating area, checking prime numbers, accepting student/employee details, and a menu-driven employee management program.

Uploaded by

ashter mendes
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/ 32

OBJECT ORIENTED CONCEPTS

LAB
Name: ASHTER MENDES
Roll No: 18826
Course: SYBCA
College Name: VVMS Shree Damodar College Of
Commerce &Economics
Subject Teacher: Surekha Patil

INDEX

Sr. Date Program title Tr.sign


01 05-07-19 Write a java program to find the
area of rectangle.

02 05-07-19 Write a program to accept the


marks of students
subject(maths,english,science)and
calculate the total and
percentage

03 05-07-19 Write a program to check


whether a number is prime or
not.

04 12-07-19 Write a java program to enter


the details of the employees by
the input given by the user.

05 12-07-19 Write a java program to enter the


student details by the input given
by the user.

06 12-07-19 Write a menu driven program to


enter the details of the
employees by the input given by
the user.

07 18-07-19 Write a program to create a


shape class to calculate area of
different objects like
rectangle,circle,triangle and
square.
Sr no:01 Date:05-07-19

Program title: Write a java program to find the


area of rectangle.
import java.io.*;
public class recTest {

/**
* @param args
*/
public static void main(String[] args) throws
Exception {
// TODO Auto-generated method stub
int length,breadth,area;
DataInputStream d=new DataInputStream
(System.in);
System.out.println("Enter any two numbers");
length=Integer.parseInt(d.readLine());
breadth=Integer.parseInt(d.readLine());
area=length * breadth;
System.out.println("Area: "+area);

Output:
Enter any two numbers
4
5
Area: 20

Sr no:02 Date:12-07-19

Program title:Write a program to accept the marks


of students subject(Maths ,English ,Science)and
calculate the total and percentage.

import java.io.*;
public class studentTest {

/**
* @param args
*/
public static void main(String[] args) throws
Exception {
int maths,sci,eng,total;
double per;
DataInputStream d=new DataInputStream
(System.in);
System.out.println("Enter marks of maths");
maths=Integer.parseInt(d.readLine());
System.out.println("Enter marks of sci");
sci=Integer.parseInt(d.readLine());
System.out.println("Enter marks of eng");
eng=Integer.parseInt(d.readLine());

total=maths+sci+eng;
System.out.println("The total is" +total);
per=(double)total/300*100;
System.out.println("The per is" +per);
if(per>=40)
{
System.out.println("You have passed");
}
else
{
System.out.println("You have failed");
}
}

Output:
Enter marks of maths
40
Enter marks of sci
50
Enter marks of eng
60
The total is150
The per is50
You have passed
Sr no:03 Date:12-07-19

Program title: Write a program to check whether a


number is prime or not.
import java.io.DataInputStream;
public class primeTest {
/**
* @param args
*/
public static void main(String[] args) throws
Exception{
// TODO Auto-generated method stub
int no,prime,flag=0,i=0;
DataInputStream d=new DataInputStream
(System.in);
System.out.println("Enter an number");
no=Integer.parseInt(d.readLine());
for(i=2;i<no;i++)
{
if(no%i==0)
{
flag=1;
break;
}
}
if(flag==0)
{
System.out.println("it is a prime number");
}
else
{
System.out.println("it is not a prime number");
}
}

Output:

1:Enter an number
2
it is a prime number
2:Enter an number
6
it is not a prime number
Sr no:04 Date:12-07-19

Program title: Write a java program to enter the


details of the employees by the input given by the
user.
import java.io.*;
class Employee
{
int emp_ID;
String name;
double salary;
String desig;
int noOfLeaves;

void addEmployee(int ID, String Name, double s,


String dn, int l)
{
emp_ID=ID;
name=Name;
salary=s;
desig=dn;
noOfLeaves=l;
}
void display()
{
System.out.println("Your ID is: "+emp_ID);
System.out.println("Your name is: "+name);
System.out.println("Your salary is: "+salary);
System.out.println("Your designation is: "+desig);
System.out.println("Your no of Leaves are:
"+noOfLeaves);
}
void calSalary()
{
double hra=(10*salary)/100;
double da=(5*salary)/100;
double grossSal=salary+hra+da;
System.out.println("Your gross salary is:
"+grossSal);
}
}
public class empTest {

public static void main(String[] args) throws


IOException{
// TODO Auto-generated method stub
int ID;
String Name;
double s;
String dn;
int l;
DataInputStream d=new DataInputStream(System.in);
System.out.println("Enter your employee ID");
ID=Integer.parseInt(d.readLine());
System.out.println("Enter your name");
Name=d.readLine();
System.out.println("Enter your salary");
s=Double.parseDouble(d.readLine());
System.out.println("Enter your designation");
dn=d.readLine();
System.out.println("Enter your Leaves");
l=Integer.parseInt(d.readLine());
Employee e1=new Employee();
e1.addEmployee(ID,Name,s,dn,l);
e1.display();
e1.calSalary();

Output:
Enter your employee ID
18826
Enter your name
ashter
Enter your salary
15000
Enter your designation
designer
Enter your Leaves
20
Your ID is: 18826
Your name is: ashter
Your salary is: 15000.0
Your designation is: designer
Your no of Leaves are: 20
Your gross salary is: 17250.0
Sr no:05 Date:12-07-19

Program title: Write a java program to enter the


student details by the input given by the user.
import java.io.*;
class Student
{
int rollno;
String name;
double marks;
void addStudent (int rno,String n,double m)
{
rollno=rno;
name=n;
marks=m;
}
void display()
{
System.out.println("Your rollno is: "+rollno);
System.out.println("Your name is: "+name);
System.out.println("Your marks are: "+marks);
}
}
public class sTest {
public static void main(String[] args)throws
IOException {
// TODO Auto-generated method stub
int rno;
String name;
double m;
DataInputStream d=new DataInputStream(System.in);
System.out.println("Enter your RollNo");
rno=Integer.parseInt(d.readLine());
System.out.println("Enter your name");
name=d.readLine();
System.out.println("Enter marks");
m=Double.parseDouble(d.readLine());
Student s1=new Student();
s1.addStudent(rno, name, m);
s1.display();

Output:

Enter your RollNo


18826
Enter your name
ashter
Enter marks
70
Your rollno is: 18826
Your name is: ashter
Your marks are: 70.0
Sr no:06 Date:12-07-19

Program title:Write a menu driven program to enter


the details of the employees by the input given by
the user.
import java.io.DataInputStream;

class Employee
{
int emp_ID;
String name;
double salary;
String desig;
int noOfLeaves;

void addEmployee(int ID, String Name, double s,


String dn, int l)
{
emp_ID=ID;
name=Name;
salary=s;
desig=dn;
noOfLeaves=l;
}
void display()
{
System.out.println("Your ID is: "+emp_ID);
System.out.println("Your name is: "+name);
System.out.println("Your salary is: "+salary);
System.out.println("Your designation is: "+desig);
System.out.println("Your no of Leaves are:
"+noOfLeaves);
System.out.println("**************");
}
void calSalary()
{
double hra=(10*salary)/100;
double da=(5*salary)/100;
double grossSal=salary+hra+da;
System.out.println("Your gross salary is:
"+grossSal);
System.out.println("****************");
}
}
public class empTestMenu {

public static void main(String[] args) throws


Exception{
// TODO Auto-generated method stub
Employee e[]=new Employee[10];
int ID;
int i=0,flag=1;
String Name;
double s;
String dn;
int l;
int choice;
DataInputStream d=new DataInputStream(System.in);
do
{
System.out.println("What would you like to
do?");
System.out.println("1.ADD an employee");
System.out.println("2.Display Employee");
System.out.println("3.Calculate Employee gross
salary");
System.out.println("4.Exit");
System.out.println("Enter your choice");
choice=Integer.parseInt(d.readLine());
switch(choice)
{
case 1:
System.out.println("Adding employee");
e[i]=new Employee();
System.out.println("Enter your employee ID");
ID=Integer.parseInt(d.readLine());
System.out.println("Enter your name");
Name=d.readLine();
System.out.println("Enter your salary");
s=Double.parseDouble(d.readLine());
System.out.println("Enter your designation");
dn=d.readLine();
System.out.println("Enter your Leaves");
l=Integer.parseInt(d.readLine());
e[i].addEmployee(ID,Name,s,dn,l);
i++;
break;
case 2:
System.out.println("Displaying employee");
for(int x=0;x<i;x++)
{
System.out.println("**********Record
"+(x+1)+"***********");
e[x].display();
}
break;
case 3:
System.out.println("Enter your employee ID");
ID=Integer.parseInt(d.readLine());
for(int x=0;x<i;x++)
{
if(ID==e[x].emp_ID)
{
e[x].calSalary();
flag=0;
}
}
if(flag==1)
System.out.println("Employee does not exit");
break;
case 4:
break;
default:
System.out.println("You entered wrong
choice");
break;
}

}while(choice!=4);
}
}

Output:

What would you like to do?


1.ADD an employee
2.Display Employee
3.Calculate Employee gross salary
4.Exit
Enter your choice
1
Adding employee
Enter your employee ID
101
Enter your name
rajesh
Enter your salary
60000
Enter your designation
CEO
Enter your Leaves
9
What would you like to do?
1.ADD an employee
2.Display Employee
3.Calculate Employee gross salary
4.Exit
Enter your choice
2
Displaying employee
**********Record 1***********
Your ID is: 101
Your name is: rajesh
Your salary is: 60000.0
Your designation is: CEO
Your no of Leaves are: 9
What would you like to do?
1.ADD an employee
2.Display Employee
3.Calculate Employee gross salary
4.Exit
Enter your choice
3
Enter your employee ID
101
Your gross salary is: 69000.0
What would you like to do?
1.ADD an employee
2.Display Employee
3.Calculate Employee gross salary
4.Exit
Enter your choice
Sr no:07 Date:12-07-19

Program title: Write a program to create a shape


class to calculate area of different objects like
rectangle,circle,triangle and square.
import java.io.DataInputStream;

class shape
{
double area;
shape()
{
area=0;
}
void calculateArea (int radius)
{
area=3.14*radius*radius;
System.out.println("Area of circle is: "+area);
}
void calculateArea (double length,double breadth)
{
area=length*breadth;
System.out.println("Area of rectangle is: "+area);
}
void calculateArea (double length)
{
area=length*length;
System.out.println("Area of square is: "+area);
}
void calculateArea (int base,int height)
{
area=0.5*base*height;
System.out.println("Area of triangle is: "+area);
}

void display()
{
System.out.println("Area of circle is: "+area);
System.out.println("Area of rectangle is: "+area);
System.out.println("Area of square is: "+area);
System.out.println("Area of triangle is: "+area);
System.out.println("**************");
}
}
public class shTest {

public static void main(String[] args) throws


Exception{
// TODO Auto-generated method stub
shape s1=new shape();

int choice;
DataInputStream d=new DataInputStream(System.in);
do
{
System.out.println("What would you like to
display?");
System.out.println("1.Area of circle");
System.out.println("2.Area of rectangle");
System.out.println("3.Area of square");
System.out.println("4.Area of triangle");
System.out.println("5.Exit");
System.out.println("Enter your choice");
choice=Integer.parseInt(d.readLine());
switch(choice)
{
case 1:
System.out.println("Enter radius of circle");
int r=Integer.parseInt(d.readLine());
s1.calculateArea (r);
break;
case 2:
System.out.println("Enter length of
rectangle");
double l=Double.parseDouble(d.readLine());
System.out.println("Enter breadth of
rectangle");
double b=Double.parseDouble(d.readLine());
s1.calculateArea (l,b);
break;
case 3:
System.out.println("Enter lenght of square");
double side=Double.parseDouble(d.readLine());
s1.calculateArea (side);
break;
case 4:
System.out.println("Enter base of
triangle");
int bs=Integer.parseInt(d.readLine());
System.out.println("Enter height of
triangle");
int h=Integer.parseInt(d.readLine());
s1.calculateArea (bs,h);
break;
case 5:
break;
default:
System.out.println("You entered wrong
choice");
break;
}
}while(choice!=5);
}
}

Output:
What would you like to display?
1.Area of circle
2.Area of rectangle
3.Area of square
4.Area of triangle
5.Exit
Enter your choice
1
Enter radius of circle
10
Area of circle is: 314.0
What would you like to display?
1.Area of circle
2.Area of rectangle
3.Area of square
4.Area of triangle
5.Exit
Enter your choice
2
Enter length of rectangle
10
Enter breadth of rectangle
15
Area of rectangle is: 150.0
What would you like to display?
1.Area of circle
2.Area of rectangle
3.Area of square
4.Area of triangle
5.Exit
Enter your choice
3
Enter lenght of square
11
Area of square is: 121.0
What would you like to display?
1.Area of circle
2.Area of rectangle
3.Area of square
4.Area of triangle
5.Exit
Enter your choice
4
Enter base of triangle
10
Enter height of triangle
4
Area of triangle is: 20.0
What would you like to display?
1.Area of circle
2.Area of rectangle
3.Area of square
4.Area of triangle
5.Exit
Enter your choice
5

You might also like