Table of Contents
Example
Acnt.java
FDacnt.java
RDacnt.java
Intrst.java
Output
in conclusion
Home Java javaTutorial Calculate interest on fixed deposits (FDs) and fixed deposits (RDs) using inherited Java program

Calculate interest on fixed deposits (FDs) and fixed deposits (RDs) using inherited Java program

Aug 20, 2023 pm 10:49 PM
inherit java program time deposit

Calculate interest on fixed deposits (FDs) and fixed deposits (RDs) using inherited Java program

Inheritance is a concept that allows us to access the properties and behavior of one class from another class. The class that inherits methods and member variables is called a superclass or parent class, and the class that inherits these methods and member variables is called a subclass or subclass. In Java, we use "extends" keyword to inherit a class.

In this article, we will discuss a Java program to calculate interest on term deposits and time deposits using inheritance. First, create these four Java files in your local machine IDE -

  • Acnt.java − This file will contain an abstract class ‘Acnt’ used to store account details such as interest rate and amount. It will also have an abstract method 'calcIntrst' with parameter 'amnt' for calculating the interest rate.

  • FDacnt.java − It will calculate the interest rate on Fixed Deposits (FDs). In it, 'FDacnt' class will inherit 'Acnt' class and override 'calcIntrst' method.

  • RDacnt.java − It will calculate the interest rate on Fixed Deposits (FDs). In it, 'RDacnt' class will inherit 'Acnt' class and override 'calcIntrst' method.

  • Intrst.java − This file will contain the main method.

Example

Acnt.java

public abstract class Acnt{
    double intrstRate;
    double amnt; 
    abstract double calcIntrst(double amnt);
}
Copy after login

FDacnt.java

import java.util.*;
public class FDacnt extends Acnt {
   double FDintrstRate;
   double FDAmnt;
   int period;
   int age;
   double Gen, SenCitizen;
   Scanner input = new Scanner(System.in);
   @Override
   double calcIntrst(double amnt){
      this.FDAmnt = amnt;
      System.out.println("Enter your FD days");
      period = input.nextInt();
      System.out.println("Enter the age of account holder ");
      age = input.nextInt();
      if (amnt < 10000000) {
         if (period >= 7 && period <= 14) {
            Gen = 0.0450;
            SenCitizen = 0.0500;
         } else if (period >= 15 && period <= 29) {
            Gen = 0.0470;
            SenCitizen = 0.0525;
         } else if (period >= 30 && period <= 45) {
            Gen = 0.0550;
            SenCitizen = 0.0600;
         } else if (period >= 45 && period <= 60) {
            Gen = 0.0700;
            SenCitizen = 0.0750;
         } else if (period >= 61 && period <= 184) {
            Gen = 0.0750;
            SenCitizen = 0.0800;
         } else if (period >= 185 && period <= 365) {
            Gen = 0.0800;
            SenCitizen = 0.0850;
         }
         FDintrstRate = (age < 50) ? Gen : SenCitizen;
      } else {
         if (period >= 7 && period <= 14) {
            intrstRate = 0.065;
         } else if (period >= 15 && period <= 29) {
            intrstRate = 0.0675;
         } else if (period >= 30 && period <= 45) {
            intrstRate = 0.00675;
         } else if (period >= 45 && period <= 60) {
            intrstRate = 0.080;
         } else if (period >= 61 && period <= 184) {
            intrstRate = 0.0850;
         } else if (period >= 185 && period <= 365) {
            intrstRate = 0.10;
         }
      }
      return FDAmnt * FDintrstRate;
   }
}
Copy after login
The translation of

RDacnt.java

is:

RDacnt.java

import java.util.*;
public class RDacnt extends Acnt{
   double RDIntrstRate;
   double RDamnt;
   int periods;
   double monthlyAmnt;
   double Gen, SenCitizen;
   Scanner input = new Scanner(System.in);
   @Override
   double calcIntrst(double amnt){
      this.RDamnt = amnt;
      System.out.println("Enter your RD months");
      periods =input.nextInt();
      System.out.println("Enter the age of account holder");
      int age =input.nextInt();
      if (periods >= 0 && periods <= 6) {
         Gen = .0750;
         SenCitizen = 0.080;
      } else if (periods >= 7 && periods <= 9) {
         Gen = .0775;
         SenCitizen = 0.0825;
      } else if (periods >= 10 && periods <= 12) {
         Gen = .0800;
         SenCitizen = 0.0850;
      } else if (periods >= 13 && periods <= 15) {
         Gen = .0825;
         SenCitizen = 0.0875;
      } else if (periods >= 16 && periods <= 18) {
         Gen = .0850;
         SenCitizen = 0.0900;
      } else if (periods >= 22) {
         Gen = .0875;
         SenCitizen = 0.0925;
      }
      RDIntrstRate = (age < 50) ? Gen : SenCitizen;
      return RDamnt * RDIntrstRate;
   }
}
Copy after login
The translation of

Intrst.java

is:

Intrst.java

import java.util.*;
public class Intrst{
   public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      System.out.println("Choose from the Options: " + "\n1." + " FD Interest" + " \n2." + " RD Interest"
      + "\n3." + " Exit");
      int choice = sc.nextInt();
      switch (choice){
         case 1:
         FDacnt fds = new FDacnt();
         System.out.println("Enter your FD Amount");
         double fAmnt = sc.nextDouble();
         System.out.println("Interest gained on your FD Amount is: $ " + fds.calcIntrst(fAmnt));
         break;
         case 2:
         RDacnt rds = new RDacnt();
         System.out.println("Enter your RD amount");
         double RAmnt = sc.nextDouble();
         System.out.println("Interest gained on your RD Amount is: $ " + rds.calcIntrst(RAmnt));
         break;
         default:
         System.out.println("Choose correct choice");
      }
   }
}
Copy after login

To compile this code, type the following command: javac Intrst.java

Now to run: java Intrst

Output

Choose from the Options: 
1. FD Interest
2. RD Interest
3. Exit
1
Enter your FD Amount
56000
Enter your FD days
325
Enter the age of account holder 
32
Interest gained on your FD Amount is: $ 4480.0
Copy after login

The above program is a menu driver. When we execute the program, three options will appear on the screen. Select 1 to calculate the interest rate for time deposits, and select 2 to calculate the interest rate for time deposits.

in conclusion

We use the concept of hierarchical inheritance to calculate fixed deposits and fixed deposit interest. Class "Acnt" is inherited by its two subclasses "FDacnt" and "RDacnt".

The above is the detailed content of Calculate interest on fixed deposits (FDs) and fixed deposits (RDs) using inherited Java program. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Detailed explanation of C++ function inheritance: How to use 'base class pointer' and 'derived class pointer' in inheritance? Detailed explanation of C++ function inheritance: How to use 'base class pointer' and 'derived class pointer' in inheritance? May 01, 2024 pm 10:27 PM

In function inheritance, use "base class pointer" and "derived class pointer" to understand the inheritance mechanism: when the base class pointer points to the derived class object, upward transformation is performed and only the base class members are accessed. When a derived class pointer points to a base class object, a downward cast is performed (unsafe) and must be used with caution.

Java program used to check if TPP students are eligible for interviews Java program used to check if TPP students are eligible for interviews Sep 06, 2023 pm 10:33 PM

Please consider the table below to know the eligibility criteria of different companies - The Chinese translation of CGPA is: GPA greater than or equal to 8 Eligible companies Google, Microsoft, Amazon, Dell, Intel, Wipro greater than or equal to 7 Tutorial points, accenture, Infosys , Emicon, Rellins greater than or equal to 6rtCamp, Cybertech, Skybags, Killer, Raymond greater than or equal to 5Patronics, Shoes, NoBrokers Let us enter the java program to check the eligibility of tpp students for interview. Method 1: Using ifelseif condition Normally when we have to check multiple conditions we use

Write a Java program to calculate the area and perimeter of a rectangle using the concept of classes Write a Java program to calculate the area and perimeter of a rectangle using the concept of classes Sep 03, 2023 am 11:37 AM

The Java language is one of the most commonly used object-oriented programming languages ​​in the world today. The concept of classes is one of the most important features of object-oriented languages. A class is like a blueprint for an object. For example, when we want to build a house, we first create a blueprint of the house, in other words, we create a plan that shows how we are going to build the house. According to this plan we can build many houses. Likewise, using classes, we can create many objects. Classes are blueprints for creating many objects, where objects are real-world entities like cars, bikes, pens, etc. A class has the characteristics of all objects, and the objects have the values ​​of these characteristics. In this article, we will write a Java program to find the perimeter and faces of a rectangle using the concept of classes

How do inheritance and polymorphism affect class coupling in C++? How do inheritance and polymorphism affect class coupling in C++? Jun 05, 2024 pm 02:33 PM

Inheritance and polymorphism affect the coupling of classes: Inheritance increases coupling because the derived class depends on the base class. Polymorphism reduces coupling because objects can respond to messages in a consistent manner through virtual functions and base class pointers. Best practices include using inheritance sparingly, defining public interfaces, avoiding adding data members to base classes, and decoupling classes through dependency injection. A practical example showing how to use polymorphism and dependency injection to reduce coupling in a bank account application.

Java program to get the size of a given file in bytes, kilobytes and megabytes Java program to get the size of a given file in bytes, kilobytes and megabytes Sep 06, 2023 am 10:13 AM

The size of a file is the amount of storage space that a specific file takes up on a specific storage device, such as a hard drive. The size of a file is measured in bytes. In this section, we will discuss how to implement a java program to get the size of a given file in bytes, kilobytes and megabytes. A byte is the smallest unit of digital information. One byte equals eight bits. One kilobyte (KB) = 1,024 bytes, one megabyte (MB) = 1,024KB, one gigabyte (GB) = 1,024MB and one terabyte (TB) = 1,024GB. The size of a file usually depends on the type of file and the amount of data it contains. Taking a text document as an example, the file size may be only a few kilobytes, while a high-resolution image or video file may be

Detailed explanation of C++ function inheritance: How to debug errors in inheritance? Detailed explanation of C++ function inheritance: How to debug errors in inheritance? May 02, 2024 am 09:54 AM

Inheritance error debugging tips: Ensure correct inheritance relationships. Use the debugger to step through the code and examine variable values. Make sure to use the virtual modifier correctly. Examine the inheritance diamond problem caused by hidden inheritance. Check for unimplemented pure virtual functions in abstract classes.

Packaging technology and application in PHP Packaging technology and application in PHP Oct 12, 2023 pm 01:43 PM

Encapsulation technology and application encapsulation in PHP is an important concept in object-oriented programming. It refers to encapsulating data and operations on data together in order to provide a unified access interface to external programs. In PHP, encapsulation can be achieved through access control modifiers and class definitions. This article will introduce encapsulation technology in PHP and its application scenarios, and provide some specific code examples. 1. Encapsulated access control modifiers In PHP, encapsulation is mainly achieved through access control modifiers. PHP provides three access control modifiers,

Detailed explanation of C++ function inheritance: How to understand the 'is-a' and 'has-a' relationship in inheritance? Detailed explanation of C++ function inheritance: How to understand the 'is-a' and 'has-a' relationship in inheritance? May 02, 2024 am 08:18 AM

Detailed explanation of C++ function inheritance: Master the relationship between "is-a" and "has-a" What is function inheritance? Function inheritance is a technique in C++ that associates methods defined in a derived class with methods defined in a base class. It allows derived classes to access and override methods of the base class, thereby extending the functionality of the base class. "is-a" and "has-a" relationships In function inheritance, the "is-a" relationship means that the derived class is a subtype of the base class, that is, the derived class "inherits" the characteristics and behavior of the base class. The "has-a" relationship means that the derived class contains a reference or pointer to the base class object, that is, the derived class "owns" the base class object. SyntaxThe following is the syntax for how to implement function inheritance: classDerivedClass:pu

See all articles