English

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

Question

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.
Code Writing
Advertisements

Solution

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
  Is there an error in this question or solution?
Chapter 4: Constructors - Exercises [Page 115]

APPEARS IN

Rupa Pandit Computer Applications [English] Class 10 ICSE
Chapter 4 Constructors
Exercises | Q 4. (a) | Page 115
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×