Object Oriented Concepts LAB
Object Oriented Concepts LAB
LAB
Name: ASHTER MENDES
Roll No: 18826
Course: SYBCA
College Name: VVMS Shree Damodar College Of
Commerce &Economics
Subject Teacher: Surekha Patil
INDEX
/**
* @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
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
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
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
Output:
class Employee
{
int emp_ID;
String name;
double salary;
String desig;
int noOfLeaves;
}while(choice!=4);
}
}
Output:
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 {
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