Knowee
Questions
Features
Study Tools

Mohit wants a financial calculator program for Fixed Deposits and Simple Interest. He needs a program that uses multi-level inheritance. The program should have three classes:class Investment - Holds the principal, interest rate, and time period as attributes.class FixedDeposit - Derived from the Investment class, calculates the maturity amount using a method called calculateMaturityAmount(). class SimpleInterest - Derived from FixedDeposit class, prints the maturity amount using a method called printFD(). It then computes the simple interest and prints it using a method called calculateSimpleInterest().Formulas used:Maturity Amount = P * (1 + (R/100)) ^ T where the power value is calculated using pow() function from the math library.Simple Interest = P * N * R/100where P - principal, R - interest rate, and N - time period in years.Input format :The first line consists of three double-point numbers separated by a space representing the principal amount, interest rate, and time period in years to calculate Fixed Deposit and Simple Interest.Output format :The first line displays "Maturity Amount: " followed by a double value which is the calculated Maturity amount rounded to two decimal places.The second line displays "Simple Interest: " followed by a double value which is the calculated Simple interest rounded to two decimal places.Refer to the sample outputs for the formatting specifications.Code constraints :In this scenario, the test cases fall under the following constraints:1 ≤ Principal amount ≤ 1060.1 ≤ Interest rate ≤ 100.1 ≤ Time period ≤ 10Sample test cases :Input 1 :1000.0 5.0 2Output 1 :Maturity Amount: 1102.50Simple Interest: 100.00Input 2 :1500.0 4.5 4Output 2 :Maturity Amount: 1788.78Simple Interest: 270.00

Question

Mohit wants a financial calculator program for Fixed Deposits and Simple Interest. He needs a program that uses multi-level inheritance. The program should have three classes:class Investment - Holds the principal, interest rate, and time period as attributes.class FixedDeposit - Derived from the Investment class, calculates the maturity amount using a method called calculateMaturityAmount(). class SimpleInterest - Derived from FixedDeposit class, prints the maturity amount using a method called printFD(). It then computes the simple interest and prints it using a method called calculateSimpleInterest().Formulas used:Maturity Amount = P * (1 + (R/100)) ^ T where the power value is calculated using pow() function from the math library.Simple Interest = P * N * R/100where P - principal, R - interest rate, and N - time period in years.Input format :The first line consists of three double-point numbers separated by a space representing the principal amount, interest rate, and time period in years to calculate Fixed Deposit and Simple Interest.Output format :The first line displays "Maturity Amount: " followed by a double value which is the calculated Maturity amount rounded to two decimal places.The second line displays "Simple Interest: " followed by a double value which is the calculated Simple interest rounded to two decimal places.Refer to the sample outputs for the formatting specifications.Code constraints :In this scenario, the test cases fall under the following constraints:1 ≤ Principal amount ≤ 1060.1 ≤ Interest rate ≤ 100.1 ≤ Time period ≤ 10Sample test cases :Input 1 :1000.0 5.0 2Output 1 :Maturity Amount: 1102.50Simple Interest: 100.00Input 2 :1500.0 4.5 4Output 2 :Maturity Amount: 1788.78Simple Interest: 270.00

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

Here is a Python program that fulfills Mohit's requirements:

import math

class Investment:
    def __init__(self, principal, rate, time):
        self.principal = principal
        self.rate = rate
        self.time = time

class FixedDeposit(Investment):
    def calculateMaturityAmount(self):
        return self.principal * math.pow((1 + (self.rate / 100)), self.time)

class SimpleInterest(FixedDeposit):
    def printFD(self):
        maturity_amount = self.calculateMaturityAmount()
        print("Maturity Amount: {:.2f}".format(maturity_amount))
        return maturity_amount

    def calculateSimpleInterest(self):
        simple_interest = (self.principal * self.time * self.rate) / 100
        print("Simple Interest: {:.2f}".format(simple_interest))

# Test the program
principal = float(input())
rate = float(input())
time = float(input())

si = SimpleInterest(principal, rate, time)
si.printFD()
si.calculateSimpleInterest()

This program first takes the principal, rate, and time as input. It then creates an instance of the SimpleInterest class, which is derived from the FixedDeposit class, which in turn is derived from the Investment class. The printFD method is called to calculate and print the maturity amount, and then the calculateSimpleInterest method is called to calculate and print the simple interest.

This problem has been solved

Similar Questions

Write a program to demonstrate multiple inheritance. Consider two base classes worker(int code, char name, float salary), HR who calculates the different allowances like (float DA, HRA). You have another class manger with calculates (float TA(is 10% of salary), gross salary) where the properties of worker and HR is used in this class. Write a test application class to create an array of 10 workers and display their details with gross salary.

Nandhini is tasked with creating a program to calculate and display the speed of a car based on the distance covered and the time taken.Write a program with two classes: Vehicle as the base class and Car as the derived class, which inherits the properties from the Vehicle class for calculating the speed. The base class fetches the input as a float value, whereas the derived class calculates and prints the output as a float value.Note: Use public inheritanceNote: This kind of question will help in clearing Wipro recruitment.Input format :The input consists of two floating-point numbers separated by a space. The first number represents the distance traveled by the car, and the second number represents the time taken to cover that distance, separated by a space.Output format :The output displays a single line of output, showing the speed of the car in kilometers per hour.Refer to the sample output for the formatting specifications.Code constraints :The input distance and time should be non-negative floating-point numbers.The input time should not be zero (to avoid division by zero).Sample test cases :Input 1 :15.0 5.0Output 1 :Speed of car: 3 km/hrInput 2 :100.23 96.0Output 2 :Speed of car: 1.04406 km/hrNote :The program will be evaluated only after the “Submit Code” is clicked.Extra spaces and new line characters in the program output will result in the failure of the test case.

Dinesh is working in a supermarket and he is developing a program to calculate the cost of different types of items. Help him write the program that does the following:a) Create a base class, ItemType, with one virtual function double calculateAmount()b) Create a class called wooden that extends ItemType class with a number of items and cost as its private attributes. Obtain the data members and override the virtual function and calculate the total amount.c) Create a class called electronics that extends ItemType class with cost as its private attribute. Obtain the data member and override the virtual function and calculate the amount with 20% discount.Note: This question helps in clearing Infosys tests.Input format :The first line consists of an integer choice (1 or 2) representing the choice of item type.If the choice is 1 (wooden items), the next line consists of two space-separated integers: noOfItems and cost, representing the number of wooden items and their individual cost, respectively.If the choice is 2 (electronics), the next line consists of a single floating-point number cost, representing the cost of the electronic item.Output format :The output prints a floating-point number representing the calculated total cost of the chosen item type rounded off to two decimal places.Code constraints :10 < cost < 1060 < noOfItems < 20Sample test cases :Input 1 :15 840.5Output 1 :4202.50Input 2 :21800.56Output 2 :1440.45Note :

Write a Python program to create a calculator class. Include methods for basicarithmetic operations.I. Create a class named Calculator.II. Create four methods that do operations.(i.e. add., sub., div., mult.)III. Create a Calculator object via instantiation, and then perform arithmeticoperations

Program on Polymorphism: Implement a Program to demonstrate method overriding A boy has his money deposited $1000, $1500, and $2000 in banks-Bank A, Bank B and Bank C respectively. We have to print the money deposited by him in a particular bank.Create a class 'Bank' with a method 'getBalance' which returns 0. Make its three subclasses named 'BankA', 'BankB' and 'BankC' with a method with the same name 'getBalance' which returns the amount deposited in that particular bank. Call the method 'getBalance' by the object of each of the three bankswrite a java code and its explaination

1/2

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.