SandhyaP Exercise2
SandhyaP Exercise2
2
Exercise - 2
Date: 22.07.2024
AIM
Develop a java application with Employee class with Emp_name, Emp_id, Address, Mail_id,
Mobile_no as members. Inherit the classes, Programmer, Assistant Professor, Associate
Professor and Professor from employee class. Add Basic Pay (BP) as the member of all the
inherited classes with 97% of BP as DA, 10 % of BP as HRA, 12% of BP as PF, 0.1% of BP
for staff club fund. Generate pay slips for the employees with their gross and net salary
ALGORITHM
1. Initialize the scanner.
2. Define class `emp` with attributes: name, id, adr, mid, mob, bp.
3. Define method `details` to prompt and read employee name, id, address, mail id, and
mobile number.
4. Define method `sal` to:
- Calculate DA as 0.97 * bp.
- Calculate HRA as 0.10 * bp.
- Calculate PF as 0.12 * bp.
- Calculate SCF as 0.001 * bp.
- Calculate gross salary as bp + DA + HRA.
- Calculate net salary as gross - PF - SCF.
- Print employee details and salary information.
5. Define subclasses of `emp`:
- `Programmer` with `bp` set to 50000.
- `AssistantProfessor` with `bp` set to 60000.
- `AssociateProfessor` with `bp` set to 70000.
- `Professor` with `bp` set to 80000.
6. In `Main` method:
- Create instances of `Programmer`, `AssistantProfessor`, `AssociateProfessor`, and
`Professor`.
- Call `details` and `sal` methods for each instance and print them.
PROGRAM
import java.util.Scanner;
class emp {
String name;
int id;
String adr;
String mid;
String mob;
float bp;
OUTPUT
RESULT
The Java program to generate Employee pay slip is written and executed successfully.
AIM
The monthly payment for a given loan pays the principal and the interest. The monthly
interest is computed by multiplying the monthly interest rate and the balance (the remaining
principal). The principal paid for the month is therefore the monthly payment minus the
monthly interest. Write a program that lets the user enter the loan amount, number of years,
and interest rate then displays the amortization schedule for the loan.
ALGORITHM
1. Initialize Scanner to read user input.
2. Input Loan Details: loan amount, number of years, annual interest rate.
3. Calculate Monthly Rate and Payments:
- Compute monthly interest rate: `monRate = annRate / 1200`.
- Compute number of months: `numMonths = yrs * 12`.
- Compute monthly payment using the formula.
- Print monthly payment and total payment.
4. Initialize Balance and Total Interest: set balance to loan amount, initialize total interest
paid to 0.
5. Print Amortization Schedule Header.
6. Calculate and Print Each Payment:
- For each month from 1 to `numMonths`:
- Calculate interest payment: `intPay = monRate * bal`.
- Calculate principal payment: `prinPay = monPay - intPay`.
- Update balance: `bal -= prinPay`.
- Accumulate total interest: `totInt += intPay`.
- Print payment details: payment number, interest payment, principal payment, balance.
7. Print Total Interest Paid.
PROGRAM
import java.util.Scanner;
OUTPUT
RESULT
The Java program to generate Loan amortization schedule is written and executed
successfully.