0% found this document useful (0 votes)
2 views3 pages

Oops Using Java Exp PDF

The document outlines an experiment for a Computer Science and Engineering course focusing on Object Oriented Programming using Java. It includes two aims: creating a package for shapes with classes for circle and rectangle to calculate area, and implementing a custom exception for invalid age input. Sample code for both aims is provided along with expected outputs.

Uploaded by

sjha12223
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)
2 views3 pages

Oops Using Java Exp PDF

The document outlines an experiment for a Computer Science and Engineering course focusing on Object Oriented Programming using Java. It includes two aims: creating a package for shapes with classes for circle and rectangle to calculate area, and implementing a custom exception for invalid age input. Sample code for both aims is provided along with expected outputs.

Uploaded by

sjha12223
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

DEPARTMENT OF

COMPUTER SCIENCE & ENGINEERING

Experiment - 3
Student Name: Saket kumar UID: 24BCS12223
Branch: B.E.-CSE Section/Group: 617-B
Date of Performance: 11-03-2026 Semester: 4th
Subject Name: Object Oriented Programming Using Java Subject Code: 24CSH-207

Aim1 : Packageforshape
Createapackageshapewith the following classes:
[Link] 2. rectangle
Eachclassesshouldhave method to calculate area now acces the method in
main class.

Aim 2 : custom exception


Createacustomexception class called invalid age Exception write a program that

throwsthisexceptionifthe age entered by the user less than 18.

Code 1:
Aim 1:
packageShapes;

public class circle {


publicdoublecarea(int r){
return3.14*r*r;
}
}

publicclassrectangle{
publicintrarea(int l,int b){
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

return l*b;
}
}

import [Link];
import [Link];
publicclassAccesing_package {
staticvoidmain(){
rectangleR=new rectangle();

circleC=newcircle();

[Link]([Link](5,6));
[Link]([Link](4));

}
}

Code 2:
Aim 2:
import [Link];
publicclassInvalidAgeException {
static void main() {
Scannersc=newScanner([Link]);
try{
int age;
age=[Link]();
if(age<18) throw new Exception();
[Link]("you are eligible");
}
catch (Exception e) {
[Link]("age must be 18 or above");
}
}
}
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

Output:
Aim:1

Output:
Aim:2

You might also like