English

Write a program as per the given specification. Design a class called DeptStore with the following description: Class Name: DeptStore Instance variables/Member Data

Advertisements
Advertisements

Question

Write a program as per the given specification.

Design a class called DeptStore with the following description:

Class Name: DeptStore
Instance variables/Member Data
int cust_num stores the customer number
String name stores the name of the customer
double amt stores the amount of purchase made
double vat stores the value-added tax amount which is 7% of the purchase amount
Member Methods
i. void Input () To input the customer number, name, purchase amount,
ii. void Calculate () To calculate the value added tax amount and modify the purchase amount accordingly.
iii. void Display() To display all the member data with proper output statements.
iv. void main () To create an object of the class and call the member methods.
Code Writing
Advertisements

Solution

import java.util.*;
class DeptStore
{
    int cust_num; String name;
    double amt, vat;
    void Input()
    {
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter Customer number:");
        cust_num = sc.nextInt();
        String tmp = sc.nextLine();//to clear buffer
        System.out.print("Enter Customer name:");
        name = sc.nextLine();
        System.out.print("Enter Purchase amount:");
        amt = sc.nextDouble();
    }
    void Calculate()
    {
        vat = 7.0/100 * amt;
        amt = amt + vat;
        System.out.println(" Vat amount : " + vat);
        System.out.println(" Final amount: "+ amt);
    }
    void Display()
    {
        System.out.println("\n Customer number : " + cust_num);
        System.out.println(" Customer name : " + name);
        System.out.println(" Purchase amount : "+ amt);
    }
    void main()
    {
        DeptStore ds = new DeptStore();
        ds. Input();
        ds.Display();
        ds.Calculate();
    }
}

Output:

Enter Customer number: 2

Enter Customer name: ee 

Enter Purchase amount: 1000 

Customer number: 2 Customer name: ee 

Purchase amount: 1000.0

Vat amount: 70.0

Final amount: 1070.0

shaalaa.com
  Is there an error in this question or solution?
Chapter 3: User-Defined Methods - Exercises [Page 94]

APPEARS IN

Rupa Pandit Computer Applications [English] Class 10 ICSE
Chapter 3 User-Defined Methods
Exercises | Q 8. (iv) | Page 94
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×