DHIVYASRI M 710724104040
[Link]: 2(a)
PROBLEM STATEMENT:
Raj is curious about how old he is in the current year. He has asked you to
create a simple program that calculates a person's age based on their birth year. You decide to implement
this functionality using the AgeCalcu interface and the HumanAgeCalculator class. Note: The current
year is 2023. Calculate the current age by using the formula: current year - birth year.
AIM:
To create a Java program using the AgeCalcu interface and HumanAgeCalculator class to
calculate a person’s age in the year 2023 based on their birth year.
ALGORITHM:
1. Start
2. Define AgeCalcu interface with calculateAge method
3. Implement it in HumanAgeCalculator class
4. Subtract birth year from 2023 to get age
5. Take birth year input, call method, display age
6. End
.
PROGRAM:
22UIT304 – Java Programming PAGE NO: 1
DHIVYASRI M 710724104040
OUTPUT:
RESULT:
Thus, the implementation of java program to calculate a person’s age in the year 2023 based on
their birth year is verified Successfully.
22UIT304 – Java Programming PAGE NO: 2
DHIVYASRI M 710724104040
[Link]: 2(b)
PROBLEM STATEMENT:
Raj is curious about how old he is in the current year. He has asked you to
create a simple program that calculates a person's age based on their birth year. You decide to implement
this functionality using the AgeCalcu interface and the HumanAgeCalculator class. Note: The current
year is 2023. Calculate the current age by using the formula: current year - birth year.
AIM:
To develop a Java program that calculates the difference in days between two given dates (in the
format "yyyy-mm-dd") using the [Link] package.
ALGORITHM:
1. Start
2. Define DateDifferenceCalculator class
3. Take input for two dates (dateStr1 and dateStr2) in "yyyy-mm-dd" format
4. Parse the strings into LocalDate objects (date1 and date2)
5. Calculate the difference in days using [Link]()
6. Print the absolute difference in days
7. End
PROGRAM:
22UIT304 – Java Programming PAGE NO: 3
DHIVYASRI M 710724104040
OUTPUT:
RESULT:
Thus, the implementation of java program to calculate a person’s age in the year 2023 based on
their birth year is verified Successfully.
22UIT304 – Java Programming PAGE NO: 4
DHIVYASRI M 710724104040
[Link]: 2(c)
PROBLEM STATEMENT:
Anu, a new recruit at a multinational firm, is assigned to develop a salary
calculation system for Workers, Officers, and Managers using multilevel inheritance. She establishes a
base class, WorkerDetail, with attributes ID (c), basic salary (S), and HRA (60%). An Officersal class
extends this with Dearness Allowance DA (98%), and Managersal further extends with City Allowance
CA (20%) and Gross Salary. The MultilevelMain class takes employee ID, and Basic Salary as input,
calculating HRA, DA, CA, and Gross salary.
Formula:
The basic salary is 'S’
HRA (60%) = (double) $160/100 DA (98%) = (double) $98/100
CA (20%) (double) 520/100
Gross Salary = S + HRA+ DA+ CA
AIM:
To develop a Java program using multilevel inheritance to calculate the salary components (HRA,
DA, CA) and gross salary for Workers, Officers, and Managers based on their basic salary.
ALGORITHM:
1. Start
2. Create base class WorkerDetail with ID, basicSalary and HRA (60% of basic)
3. Create derived class OfficerSal extending WorkerDetail with DA (98% of basic)
4. Create derived class ManagerSal extending OfficerSal with CA (20% of basic)
5. Calculate gross salary as basicSalary + HRA + DA + CA
6. In main class, take ID and basic salary input, create ManagerSal object, calculate and display all
salary components
7. End
22UIT304 – Java Programming PAGE NO: 5
DHIVYASRI M 710724104040
PROGRAM:
22UIT304 – Java Programming PAGE NO: 6
DHIVYASRI M 710724104040
OUTPUT:
RESULT:
Thus, the implementation of Java program is verified successfully.
22UIT304 – Java Programming PAGE NO: 7
DHIVYASRI M 710724104040
22UIT304 – Java Programming PAGE NO: 8