मराठी

Write a program for the following. Define a class Mortgage, described as below: Data Members: loan (int), time (double), rate (double), interest (double), repay (double)

Advertisements
Advertisements

प्रश्न

Write a program for the following.

Define a class Mortgage, described as below:

Data Members:
loan (int), time (double), rate (double), interest (double), repay (double)
Member Methods:
(i) Mortgage(int p, constructor to initialize member data - loan to p, double r, double t) rate to r, time to t and rest to null.
(ii) Estimate() to calculate the Interest using the formula interest = (loan * rate * time )/100 and also to calculate Amount to Repay using the formula repay = loan + interest.
(iii) Display() to display all the member data.
Write a main() method to create and object of the class and call the above member methods.
कोड लेखन
Advertisements

उत्तर

class Mortgage
{
    int loan;
    double time, rate, interest, repay;
    //Parameterized Constructor
    Mortgage(int p, double r, double t)
    {
        loan = p;
        rate = r;
        time = t;
        interest = 0.0;
        repay = 0.0;
    }
    //Estimate method
    void Estimate()
    {
        interest = (loan * rate * time) / 100;
        repay = loan + interest;
    }
    //Display method
    void Display()
    {
        System.out.println("Loan =" + loan);
        System.out.println("Rate =" + rate);
        System.out.println("Time =" + time);
        System.out.println("Interest =" + interest);
        System.out.println("Amount to Repay =" + repay);
    }
    //Main method
    public static void main(String args[])
    {
        Mortgage obj = new Mortgage(100000, 8.5, 2);
        obj.Estimate();
        obj.Display();
    }
}
shaalaa.com
  या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
पाठ 4: Constructors - Exercises [पृष्ठ ११६]

APPEARS IN

रूपा पंडित Computer Applications [English] Class 10 ICSE
पाठ 4 Constructors
Exercises | Q 4. (d) | पृष्ठ ११६
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×