0% found this document useful (0 votes)
8 views7 pages

OOPJ

This document is a practical file for an Object-Oriented Programming course using Java, submitted by Himani Gupta. It includes a table of contents listing various programming experiments covering data types, loops, conditional statements, inheritance, interfaces, and file handling. Each section contains specific programming tasks and examples to demonstrate the concepts learned during the course from January to April 2024.

Uploaded by

jack76666666666
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)
8 views7 pages

OOPJ

This document is a practical file for an Object-Oriented Programming course using Java, submitted by Himani Gupta. It includes a table of contents listing various programming experiments covering data types, loops, conditional statements, inheritance, interfaces, and file handling. Each section contains specific programming tasks and examples to demonstrate the concepts learned during the course from January to April 2024.

Uploaded by

jack76666666666
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
You are on page 1/ 7

OBJECT ORIENTED

PROGRAMMING USING JAVA


(BAI - 102)

Practical File

Submitted By
Himani Gupta
CSE-AI 1
JAVA practice
06701172023

Submitted to
Mr. Rahul Sachdeva
Assistant Professor
Dept. of AI & DS

Indira Gandhi Delhi Technical University for Women


Kashmere Gate, Delhi – 110006
January to April 2024
Table of Content

S. No. Topic Experiment


1. Introduction to 1. Write a program to multiply two floating point numbers
Data Types 2. Write a program to swap two numbers
3. Write a program to add two binary strings
4. Write a program to add two complex numbers
5. Write a program to calculate simple interest
6. Write a program to calculate compound interest
7. Write a program to find perimeter of rectangle
8. Write a program to find area of circle for radius entered by user

2. Practice in Loops 1. * Print using loops


**
***
****
2. Print (a+(b*c))/(b-c) taking a, b, c as input
3. Print table of a number taken from user
4. Convert rupees, taken as input, to paise

3. Conditional 1. Convert degree Celsius, taken as input, to degree Fahrenheit


Statements 2. Input marks and print grade 85-100: A 70-85: B 60-70: C 50-60: D
<50:FAIL

4. Loops and 1. Convert binary to decimal


Conditionals 2. Find roots of quadratic equation
3. Find sum of series (1/x) + (1/x^2) +…. Till n terms.

5. Application 1. Create a calendar, enter date to get its previous date, next date and days
Program 2. Use 2D array to print matrix, perform addition and multiplication on it
with another matrix.

6. Calculator 1. Create calculator


2. Create calculator using Switch
7. Introduction to 1. Create base class distance, give private parameter d1. Create
classes constructors for add, subtract and print. Two derived classes Dinch
(convert d1 to inches) Dmiles (convert d1 to miles), give them the same
constructors. Use override to print and add
2. Create an employee class with private members name address age
gender taken as input, use constructor to initialize values to the
variable, display all. Derive employee class into full time employee,
with members salary and designation (display all) and part time
employee with members work hour and rate per hour from which pay
can be calculated (work hour * rate per hour), display pay
3. Create class vehicles with members color type weight and read()
print(). Derive it into two classes, Car with members model engine
number of seats and read() print(), Bike with members engine tyre and
read() print()
4. Create class addTime that can add two times in hr, min, sec

8. Inheritance 1. Create class addTime that can add two times in hr, min, sec
2. Create a base class account having acc number, acc type, name of
holder, read(), print().Derive this class into savings and current acc
class where savings acc has interest rate 10%, update balance; and
current acc has maximum number of transactions. If the number of
transactions >30, deduct 1500. Create 10 objects, 5 of savings type and
5 of current type
3. Create a class to read and print details of students. Also create a
function to get average, minimum and maximum marks.

9. Interfaces 1. Design an interface with a method reverse that reverses the digits of a
number
2. Design an interface having method to get velocity with parameter r that
calculates and returns velocity of a satellite given by the formula
velocity=root mu/r where r is the altitude of satellite taken from the
earth and mu is Kepler’s constant with value 3.986004418* (10**5).
Create a nested interface with a method to get acceleration with
parameter r that calculates and returns the acceleration of the satellite
given by the formula mu/(r**2)
3. Write a program having a mean interface. Create a method mean that
calculates the mean of user entered numbers arranged in an array.
Extend the interface having method deviation that calculates the
(absolute) deviation from the mean value for each of the numbers in the
array.
4. Write a program in which 3 interfaces I1 I2 I3 are defined, I2 extends
I1, I3 extends I1 and I2. I1 declares a method withdraw, I2 declares a
method deposit, I3 declares a display that shows balance of account
number. Create a class with var acc number, name, address, balance
that implements the interfaces
10. File Handling-1 1. Write a program that calculates the area of a room and the cost of white
washing, include provision for window on any of the walls. The
parameters for the room length height width are taken from the user. If
there is a window then its length and width are taken from the user. In
any case of parameter, if input is less than 1 then throw an invalid
dimension exception; otherwise calculate and display area and cost of
white washing
2. Write a program that reads data for name class roll number marks of a
student and print them to a file. Also read details from the file and
show on the monitor
3. Write a program to copy contents of one file into another

11. File Handling-2 1. Write a program to check whether the contents in two files is same or
not
2. Write a program to count the number of digits stored in the file
3. Write a program to write a string character by character to a file and
read the string character by character from the file, print it on the screen
4. Read the data from the keyboard using buffered reader class

12. Application 1. Create a class with members name, roll number, stream, marks, write it
Program in a file for 10 students such that when you enter roll number, only the
details of that student are printed.
EXPERIMENT-1

INTRODUCTION TO DATA TYPES

Program 1:
Write a program to multiply two floating point numbers

public class FloatingPointMultiplication {


public static void main(String[] args) {
// Define two floating-point numbers
float num1 = 3.5f;
float num2 = 2.0f;

// Multiply the two numbers


float result = num1 * num2;

// Print the result


System.out.println("The product of " + num1 + " and " + num2 + " is: " + result);
}
}
Program 2:
Write a program to swap two numbers

public class SwapNumbers {


public static void main(String[] args) {
// Define two numbers
int num1 = 5;
int num2 = 10;

System.out.println("Before swapping:");
System.out.println("num1 = " + num1);
System.out.println("num2 = " + num2);

// Swap the numbers using a temporary variable


int temp = num1;
num1 = num2;
num2 = temp;

System.out.println("\nAfter swapping:");
System.out.println("num1 = " + num1);
System.out.println("num2 = " + num2);
}
}
Program 3:
Write a program to add two binary strings

public class AddBinaryStrings {


public static void main(String[] args) {
String binary1 = "1010"; // Binary string 1
String binary2 = "1101"; // Binary string 2
String sum = addBinary(binary1, binary2);
System.out.println("Binary sum: " + sum);
}
public static String addBinary(String binary1, String binary2) {
StringBuilder result = new StringBuilder();
int carry = 0;

int i = binary1.length() - 1;
int j = binary2.length() - 1;

while (i >= 0 || j >= 0 || carry > 0) {


int digit1 = (i >= 0) ? binary1.charAt(i--) - '0' : 0;
int digit2 = (j >= 0) ? binary2.charAt(j--) - '0' : 0;

int sum = digit1 + digit2 + carry;


result.insert(0, sum % 2);
carry = sum / 2;
}
return result.toString();
}
}

You might also like