मराठी

Write a program for the following. Define a class Store, described as below: Member Methods: (i) Store() constructor to initialize member data to null.

Advertisements
Advertisements

प्रश्न

Write a program for the following.

Define a class Store, described as below:

Data Members: income (double), expenditure (double), net (double)
Member Methods:
(i) Store() constructor to initialize member data to null.
(ii) Input() to input values for member data income and expenditure.
(iii) Procedure() to calculate value of net using the following formula net = income - expenditure.
(iv) Display() to display all the member data.
Write a main() method to create an object of the class and call the above member methods.
कोड लेखन
Advertisements

उत्तर

import java.util.*;
class Store
{
    double income, expenditure, net;
    //Constructor
    Store()
    {
        income = 0.0;
        expenditure = 0.0;
        net = 0.0;
    }
    //Input method
    void Input()
    {
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter Income:");
        income = sc.nextDouble();
        System.out.print("Enter Expenditure:");
        expenditure = sc.nextDouble();
    }
    //Procedure method
    void Procedure()
    {
        net = income - expenditure;
    }
    //Display method
    void Display()
    {
        System.out.println("Income =" + income);
        System.out.println("Expenditure =" + expenditure);
        System.out.println("Net = " + net);
    }
    //Main method
    public static void main(String args[])
    {
        Store obj = new Store();
        obj.Input();
        obj.Procedure();
        obj.Display();
    }
}
shaalaa.com
  या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
पाठ 4: Constructors - Exercises [पृष्ठ ११५]

APPEARS IN

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

Englishहिंदीमराठी


      Forgot password?
Use app×