Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
7 views3 pages

Javaass 7

The document outlines the creation of custom packages for a finance application, specifically 'com.finance.accounts' for account operations and 'com.finance.tax' for tax calculations. It includes Java code for an Account class that manages deposits and withdrawals, a TaxCalculator class for calculating tax based on a fixed rate, and a MainApp class that demonstrates the usage of both packages. The application allows users to manage their account balance and compute tax on the current balance.

Uploaded by

aditigade9999
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views3 pages

Javaass 7

The document outlines the creation of custom packages for a finance application, specifically 'com.finance.accounts' for account operations and 'com.finance.tax' for tax calculations. It includes Java code for an Account class that manages deposits and withdrawals, a TaxCalculator class for calculating tax based on a fixed rate, and a MainApp class that demonstrates the usage of both packages. The application allows users to manage their account balance and compute tax on the current balance.

Uploaded by

aditigade9999
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Practical 7 : Create custom packages for logical separation in finance application with

multiple users defined packages: 1.com.finance.accounts for account opeartion 2.


com.finnace.tax for tax calculations
Code:
1. Package: com.finance.accounts File: Account.java
package com.finance.accounts;
public class Account {
private String accountHolder;
private double balance;
public Account(String accountHolder, double balance) {
this.accountHolder = accountHolder;
this.balance = balance;
}
public void deposit(double amount) {
balance += amount;
System.out.println(amount + " deposited. Current Balance: " + balance);
}
public void withdraw(double amount) {
if(amount <= balance) {
balance -= amount;
System.out.println(amount + " withdrawn. Current Balance: " + balance);
} else {
System.out.println("Insufficient Balance!");
}
}
public double getBalance() {
return balance;
}
public String getAccountHolder() {
return accountHolder;
}
}
2. Package: com.finance.tax File: TaxCalculator.java
package com.finance.tax;
public class TaxCalculator {
private static final double TAX_RATE = 0.1; // 10%
public double calculateTax(double income) {
return income * TAX_RATE;
}
}
3. Main Application to Use Both Packages File: MainApp.java
import com.finance.accounts.Account;
import com.finance.tax.TaxCalculator;
public class MainApp {
public static void main(String[] args) {
Account acc1 = new Account("Pecky", 5000);
acc1.deposit(2000);
acc1.withdraw(1000);
TaxCalculator taxCalc = new TaxCalculator();
double tax = taxCalc.calculateTax(acc1.getBalance());
System.out.println("Tax on current balance: " + tax);
}}
Output :

You might also like