You are on page 1of 8

OBJECT ORIENTED

PROGRAMMING
Implementation of Different Java Programs
21-April-2024
TABLE OF CONTENT

1: Savings Calculator..................................................................................................................

2: Lottery Number Generator:.................................................................................................

3: Mean And Standard Deviation Calculator:........................................................................

4. Bubble Sort Algorithm.........................................................................................................

5. Binary Operations Calculator:.............................................................................................

Summary:..................................................................................................................................

Conclusion:...............................................................................................................................

PAGE 1
1: Savings Calculator.
Task: The task was to create a Java program that calculates the value of a savings
account after a certain number of months, taking into account a fixed monthly
deposit and an annual interest rate

Solution: The program prompts the user to enter the initial amount, annual
interest rate, and the number of months. Then, it calculates the value of the
savings account after the given number of months using compound interest
formula and displays the result.

The program calculates the amount in a savings account after a given number of
months, considering monthly deposits and compound interest. It follows these
steps:

 Input: Prompts the user for the initial amount, annual interest rate, and
number of months.

 Calculation: Calculates the amount after the given number of months


considering the monthly interest rate and adding $100 each month.

 Output: Displays the amount in the savings account after the specified number
of months.

CODE:

RESULT:

PAGE 2
2: LOTTERY NUMBER GENERATOR:
Task: The task was to create a Java program that generates a two-digit lottery number
with distinct digits.

Solution: The program generates the first digit between 1 and 9 and then continuously
generates the second digit until it's different from the first one. Finally, it combines the
digits to form the two-digit lottery number and displays it.

The program generates a two-digit lottery number with distinct digits. It follows these
steps:

 Random Number Generation: It generates the first digit between 1 and 9 and
the second digit between 0 and 9, ensuring it's different from the first digit.
 Combination: It combines the digits to form the two-digit lottery number.
 Output: It displays the generated lottery number.

CODE:

OUTPUT:

PAGE 3
3: MEAN AND STANDARD DEVIATION CALCULATOR:
Task: The task was to create a Java program that calculates the mean and standard
deviation of ten numbers entered by the user.

Solution: The program prompts the user to enter ten numbers, calculates their mean,
and then calculates the standard deviation. Finally, it displays the mean and standard
deviation.

The program calculates the mean and standard deviation of ten numbers provided by
the user. It follows the steps outlined below:

 Input: The program prompts the user to enter ten numbers.


 Calculation: It calculates the mean and standard deviation using the formulas:
 Mean: The sum of all numbers divided by the total count of numbers.
 Standard Deviation: The square root of the average of squared differences
between each number and the mean.
 Output: Finally, it displays the calculated mean and standard deviation.

CODE:

OUTPUT:

PAGE 4
4. BUBBLE SORT ALGORITHM
Task: The task was to create a Java program that implements the bubble sort algorithm
to sort ten double numbers entered by the user.

Solution: The program reads in ten double numbers from the user, then sorts them
using the bubble sort algorithm and finally displays the sorted numbers.

The program implements the bubble sort algorithm to sort ten double numbers
provided by the user. It performs the following steps:

 Input: Reads ten double numbers from the user.


 Sorting: Uses the bubble sort algorithm to sort the numbers in ascending order.
 Output: Displays the sorted numbers.

CODE:

OUTPUT:

PAGE 5
5. BINARY OPERATIONS CALCULATOR:
Task: The task was to create a Java program that performs binary operations on
integers based on the given operator and operands.

Solution: The program takes three parameters: an operator (+, -, *, /) and two integers.
It then performs the specified operation on the integers and displays the result

The program performs binary operations on two integers based on the provided
operator. It follows these steps:

 Input: Receives three parameters: two integers and an operator.


 Parsing: Parses the input parameters and checks for correctness.
 Operation: Performs the operation based on the operator (+, -, *, /).
 Output: Displays the result of the operation or an error message if the input is
invalid.

CODE:

OUTPUT:

PAGE 6
SUMMARY:
Each of the five Java programs fulfills a specific task:

 Savings Calculator: Calculates the value of a savings account after a certain


number of months.
 Lottery Generator: Generates a two-digit lottery number with distinct digits.
 Mean and Standard Deviation Calculator: Calculates the mean and standard
deviation of ten numbers.
 Bubble Sort: Sorts ten double numbers using the bubble sort algorithm.
 Integer Calculator: Performs binary operations on integers based on the given
operator and operands.

CONCLUSION:
Each of these Java programs addresses specific tasks: generating lottery numbers and
calculating savings growth over time, calculating statistics, sorting data, and
performing arithmetic operations. By explaining the questions and the solutions
provided, users can better understand the purpose and functionality of each program.
Each program addresses a specific problem and provides a clear solution, enhancing
the versatility and usefulness of the collection of programs.

SUBMITTED BY:
Dua Fatima (BB-7577), Alishba Arif (BB-7917), Sineha (BB-7608), Rimsha Saher
(BB-7407), Sakeena Tahir (BB-7904)

PAGE 7

You might also like