1.

Design a class name ShowRoom with the following description :Instance variables/ Data members : String name – To store the name of the customer long mobno – To store the mobile number of the customerdouble cost – To store the cost of the items purchased double dis – To store the discount amount double amount – To store the amount to be paid after discountMember methods: – ShowRoom() – default constructor to initialize data members void input() – To input customer name, mobile number, cost void calculate() – To calculate discount on the cost of purchased items, based on following criteriaCostDiscount (in percentage)Less than or equal to ₹ 100005%More than ₹ 10000 and less than or equal to ₹ 2000010%More than ₹ 20000 and less than or equal to ₹ 3500015%More than ₹ 3500020% 

Answer»

Solution. 

import java.io.*; 

import java.util.*; 

class ShowRoom 

String name; 

long mobno; 

double cost; 

double dis; 

double amount; 

ShowRoom( ) 

name = ” “; 

mobno =0;

cost = 0; 

dis = 0; 

amount = 0; 

void input( ) 

Scanner sc = new Scanner(System.in); 

System.out.println(“EnterName:”); 

name = sc.nextLine( ); 

System.out.println(“Enter Mobile number:”); 

mobno = sc.nextLong( ); 

System.out.println(“Enter cost:”); 

cost = sc.nextDouble( ); 

}

void calculate( ) 

if (cost 10000 && cost < = 20000)

dis = cost* 10/100; 

amount cost – dis; 

else 

if (cost > 20000 && cost < = 35000)

{ dis = cost* 15/100; 

amount = cost – dis; 

else 

if (cost > 35000)

dis = cost*20/100; 

amount = cost – dis; 

}

void display( ) 

System.out.println(“Name::” +name); 

System.out.println(“Mobile No.::” +mobno); 

System.out.println(“Amount::” +amount); 

public static void main(String args( )) 

ShowRoom ob = new ShowRoom( ); 

ob.input( ); 

ob.calculate( ); 

ob.display( ); 

}



Discussion

No Comment Found

Related InterviewSolutions