0% found this document useful (0 votes)
14 views

OOP Lab Report 3

The document describes a lab report for an object oriented programming class. It includes code to calculate the power of a number using a class and encapsulation. It also includes code for multiple inheritance with three classes A, B, and C where C inherits from both A and B. The discussion section describes the tools and concepts used.

Uploaded by

rezanurbinshamim
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)
14 views

OOP Lab Report 3

The document describes a lab report for an object oriented programming class. It includes code to calculate the power of a number using a class and encapsulation. It also includes code for multiple inheritance with three classes A, B, and C where C inherits from both A and B. The discussion section describes the tools and concepts used.

Uploaded by

rezanurbinshamim
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

Green University of Bangladesh

Department of Computer Science and Engineering (CSE)


Faculty of Sciences and Engineering
Semester: (Spring, Year:2023), B.Sc. in CSE (Day)

Lab Report NO # 2
Course Title: Object
Oriented Programming
lab
Course Code: CSE 202 Section: 222 D10

Lab Experiment Name: 1. Calculate power of a number using Class and


Encapsulation. 2. Implement Multiple inheritance, 3 Classes A, B, C. Class C
inherits both A and B.

Student Details
Name ID

1. Labib Tahmid 221002269

Lab Date : 16 October 2023


Submission Date : 30 October 2023
Course Teacher’s Name: Md. Parvez Hossain

Lab Report Status


Marks: ………………………………… Signature:.....................
Comments:.............................................. Date:..............................
Calculate power of a number using Class
and Encapsulation :

Fig 1: Power of a number Flowchart

Code:
import java.util.*;

class Power {
private int number , power ;
public void getnumber (int number , int power) {
this.number = number;
this.power = power;
}
public int power () {
number = (int)Math.pow(number, power);
return number;
}
}

public class Encapsulation {


public static void main (String args[]) {
Power pow = new Power();
System.out.println("Enter number and its desire
power :");
Scanner scanf = new Scanner(System.in);
int number = scanf.nextInt();
int power = scanf.nextInt();
pow.getnumber(number,power);
System.out.println("Power is : " + pow.power());
}
}
Output:
Implement Multiple inheritance. 3 Classes A,B,C. Class C
inherits both A and B.

Fig 2 : Inheritance Flowchart

Code:
import java.util.Scanner;

class Radius {
public int radius;
protected void radius (int radius) {
this.radius = radius;
}
}

class Color extends Radius {


public String color;
protected void color (String color) {
this.color = color;
}
}

class Circle extends Color {


private double area;
public void circleinfo () {
area = 3.1416 * radius * radius ;
System.out.println("The Circle color is " + color +
" and Area is " + area);
}
}

public class Inheritance {


public static void main (String args[]) {
Circle cir = new Circle();
Scanner scanf = new Scanner(System.in);
System.out.println("Enter circles radius and color :
");
cir.radius = scanf.nextInt();
cir.color = scanf.next();
cir.circleinfo();
}
}
Output:
Discussion:

1. I used draw.io to draw the flowchart and used VScode to run the
program.

2. I used Encapsulation for the first program , which helps to


manage the data more perefctly and ensure data hiding , to achive
the data hiding I also used private keyword.

3. For the 2nd program I used inheritance. As java doesn’t support


multiple inheritance I inherited the A class in B , and B in C , so C
inherit both classes. I also used many keyword like priavte , public
and protected here.

4. I ran into some problem while doing this lab project but finally
overcomed it after trying some times.

You might also like