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

OOP Lab Report 1

The document describes a lab report for an object oriented programming class. It includes flowcharts and code for exercises calculating factorials, series sums, and area calculations for shapes using classes and methods. The output shows calculations for circle area.

Uploaded by

rezanurbinshamim
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
59 views

OOP Lab Report 1

The document describes a lab report for an object oriented programming class. It includes flowcharts and code for exercises calculating factorials, series sums, and area calculations for shapes using classes and methods. The output shows calculations for circle area.

Uploaded by

rezanurbinshamim
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

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 # 1
Course Title: Object
Oriented Programming
lab
Course Code: CSE 202 Section: 222 D10

Lab Experiment Name: Lab Manual 1 Task 1 & Lab Manual 2 Exercise 1 Task 1

Student Details
Name ID

1. Labib Tahmid 221002269

Lab Date : 2 October 2023


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

Lab Report Status


Marks: ………………………………… Signature:.....................
Comments:.............................................. Date:..............................
Lab Exercise 1 FlowChart :

Lab Exercise 1 Code:


import java.util.*;

public class Main {


public static int facto (int n) {
int fact = 1 ;
for (int i = 1 ; i <= n ; i++) {
fact = fact * i;
}
return fact;
}
public static double sum (int x , int n ) {
double sum = 0;
while (n >= 1) {
sum = sum + (Math.pow(x,n) / facto(n-1));
n = n-2;
}
return sum;
}
public static void main (String[] args) {
int x , n ;
Scanner scanf = new Scanner(System.in);
System.out.println("Enter your number: ");
x = scanf.nextInt();
System.out.println("Enter how long you want it to
go: ");
n = scanf.nextInt();
System.out.println("Sum is : "+sum(x,n));
}
}

Output:
Enter your number:
2
Enter how long you want it to go:
6
Sum is : 7.199999999999999
Lab Exercise 2 & Lab Task 2 FlowChart:

Lab Exercise 2 Code:


import java.util.*;

class Area {
public void area (double ta , double tb) {
double area = 0.5 * ta * tb;
System.out.println("Area is: "+area);
}
public void area (int ra , int rb) {
double area = ra * rb;
System.out.println("Area is: "+area);
}
public void area (int r) {
double area = 3.1416 * Math.pow(r,2);
System.out.println("Area is: "+area);
}
}

public class Main1 {


public static void main (String[] args){
Area A1 = new Area();
System.out.println("For area of traingle,rectangle
or circle,Enter 1,2 or 3");
Scanner scanf = new Scanner(System.in);
int x = scanf.nextInt();

if(x == 1) {
System.out.println("Enter the two length of
triangle");
double ta = scanf.nextDouble();
double tb = scanf.nextDouble();
A1.area(ta,tb);
} else if (x == 2) {
System.out.println("Enter the two length of
rectangle");
int ra = scanf.nextInt();
int rb = scanf.nextInt();
A1.area(ra,rb);
} else {
System.out.println("Enter the radius of
circle");
int r = scanf.nextInt();
A1.area(r);
}
}

Lab Task 2 Code:


import java.util.*;

class Area1 {
public void area (double ta , double tb) {
double area = 0.5 * ta * tb;
System.out.println("Area is: "+area);
}
public void area (int ra , int rb) {
double area = ra * rb;
System.out.println("Area is: "+area);
}
public void area (int r) {
double area = 3.1416 * Math.pow(r,2);
System.out.println("Area is: "+area);
}
}

public class Main2 {


public static void main (String[] args){
Area1 A1 = new Area1();
System.out.println("For area of traingle,rectangle
or circle,Enter 1,2 or 3");
Scanner scanf = new Scanner(System.in);
int x = scanf.nextInt();

switch(x) {
case(1) :
System.out.println("Enter the two length of
triangle");
double ta = scanf.nextDouble();
double tb = scanf.nextDouble();
A1.area(ta,tb);
break;
case(2) :
System.out.println("Enter the two length of
rectangle");
int ra = scanf.nextInt();
int rb = scanf.nextInt();
A1.area(ra,rb);
break;
case(3) :
System.out.println("Enter the radius of
circle");
int r = scanf.nextInt();
A1.area(r);
break;
default :
break;
}
}
}

Output:
For area of traingle,rectangle or circle,Enter 1,2 or 3
3
Enter the radius of circle
5
Area is: 78.53999999999999

You might also like