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

Java

The document contains two Java classes for a bank customer interest calculation system. The first class, BankCustomer, takes user input for customer details and calculates compound interest based on eligibility criteria. The second class, BankCustomerInterestCalculator, provides a graphical user interface for the same functionality, allowing users to input their details and view the results in a text area.
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 views7 pages

Java

The document contains two Java classes for a bank customer interest calculation system. The first class, BankCustomer, takes user input for customer details and calculates compound interest based on eligibility criteria. The second class, BankCustomerInterestCalculator, provides a graphical user interface for the same functionality, allowing users to input their details and view the results in a text area.
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/ 7

import java.util.

Scanner;

public class BankCustomer {

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

// Input customer details

System.out.print("Enter your name: ");

String name = scanner.nextLine();

System.out.print("Enter your account number: ");

String accountNumber = scanner.nextLine();

System.out.print("Enter your phone number: ");

String phoneNumber = scanner.nextLine();

System.out.print("Enter your initial investment (Principal amount): ");

double principal = scanner.nextDouble();

System.out.print("Enter the annual interest rate (in percentage): ");

double annualInterestRate = scanner.nextDouble();

System.out.print("Enter the number of times interest is compounded per year: ");

int timesCompounded = scanner.nextInt();


System.out.print("Enter the time in years: ");

double timeInYears = scanner.nextDouble();

System.out.print("Enter the number of withdrawals made this month: ");

int numberOfWithdrawals = scanner.nextInt();

// Check eligibility for interest

if (numberOfWithdrawals < 4 && principal >= 50000) {

// Convert annual interest rate from percentage to decimal

double rate = annualInterestRate / 100;

// Calculate compound interest

double amount = principal * Math.pow((1 + rate / timesCompounded), timesCompounded *


timeInYears);

double compoundInterest = amount - principal;

// Display results

System.out.printf("Customer Name: %s%n", name);

System.out.printf("Account Number: %s%n", accountNumber);

System.out.printf("Phone Number: %s%n", phoneNumber);

System.out.printf("Final Amount after %.1f years: N%.2f%n", timeInYears, amount);

System.out.printf("Compound Interest Earned: N%.2f%n", compoundInterest);

} else {

System.out.println("You are not eligible for interest.");

if (numberOfWithdrawals >= 4) {

System.out.println("Reason: Number of withdrawals exceeds 3.");


}

if (principal < 50000) {

System.out.println("Reason: Minimum balance requirement not met (N50,000).");

scanner.close();

2)import javax.swing.*;

import java.awt.*;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

public class BankCustomerInterestCalculator extends JFrame {

private JTextField nameField, accountNumberField, phoneNumberField, principalField,


interestRateField, withdrawalsField;

private JTextArea resultArea;

private JButton calculateButton;

public BankCustomerInterestCalculator() {

setTitle("Bank Customer Interest Calculator");

setSize(400, 400);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new GridLayout(8, 2));

// Input fields

add(new JLabel("Name:"));

nameField = new JTextField();

add(nameField);

add(new JLabel("Account Number:"));

accountNumberField = new JTextField();

add(accountNumberField);

add(new JLabel("Phone Number:"));

phoneNumberField = new JTextField();

add(phoneNumberField);

add(new JLabel("Principal Amount (N):"));

principalField = new JTextField();

add(principalField);

add(new JLabel("Annual Interest Rate (%):"));

interestRateField = new JTextField();

add(interestRateField);

add(new JLabel("Number of Withdrawals:"));

withdrawalsField = new JTextField();


add(withdrawalsField);

calculateButton = new JButton("Calculate Interest");

add(calculateButton);

resultArea = new JTextArea();

resultArea.setEditable(false);

add(new JScrollPane(resultArea));

calculateButton.addActionListener(new CalculateInterestAction());

setVisible(true);

private class CalculateInterestAction implements ActionListener {

@Override

public void actionPerformed(ActionEvent e) {

String name = nameField.getText();

String accountNumber = accountNumberField.getText();

String phoneNumber = phoneNumberField.getText();

double principal = Double.parseDouble(principalField.getText());

double annualInterestRate = Double.parseDouble(interestRateField.getText()) / 100;

int withdrawals = Integer.parseInt(withdrawalsField.getText());

// Check eligibility for interest


if (withdrawals < 4 && principal >= 50000) {

double compoundInterest = calculateCompoundInterest(principal, annualInterestRate, 4, 1);

double finalAmount = principal + compoundInterest;

resultArea.append("Customer: " + name + "\n");

resultArea.append("Account Number: " + accountNumber + "\n");

resultArea.append("Phone Number: " + phoneNumber + "\n");

resultArea.append("Final Amount: N" + String.format("%.2f", finalAmount) + "\n");

resultArea.append("Compound Interest Earned: N" + String.format("%.2f", compoundInterest)


+ "\n\n");

} else {

resultArea.append("Customer: " + name + "\n");

resultArea.append("Account Number: " + accountNumber + "\n");

resultArea.append("Phone Number: " + phoneNumber + "\n");

resultArea.append("Not eligible for interest due to withdrawal or balance conditions.\n\n");

private double calculateCompoundInterest(double principal, double rate, int n, int t) {

return principal * Math.pow((1 + rate / n), n * t) - principal;

public static void main(String[] args) {

new BankCustomerInterestCalculator();

}
}

You might also like