Advertisements
Advertisements
प्रश्न
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. |
कोड लेखन
Advertisements
उत्तर
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
क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
अध्याय 3: User-Defined Methods - Exercises [पृष्ठ ९४]
