Posts

Showing posts from February, 2020

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 customer’s mobile number. double cost: to store the cost of the item purchased. double dis: to store the discount amount. double amount: to store the amount to be paid after discount. Methods: ShowRoom(): default constructor to initialize the data members void input(): to input customer name, mobile number, cost void calculate(): to calculate discount on the cost of purchased items, based on the following criteria Cost Discount(In percentage) Less than or equal to ₹ 10000 5 % More than ₹ 10000 and less than or equal to ₹ 20000 10 % More than ₹ 20000 and less than or equal to ₹ 35000 15 % More than ₹ 35000 20% void display()- To display customer, mobile number, amount to be paid after discount. Write a main() method to create an object of the class and call the above methods.

import java . util . Scanner ; class ShowRoom { String name ; long mobno ; double cost , dis , amount ; ShowRoom ( ) //default constructor { name = "" ; mobno = 0L ; cost = 0.0d ; dis = 0.0d ; amount = 0.0d ; } void input ( ) { Scanner kb = new Scanner ( System . in ) ; System . out . print ( "Enter your name: " ) ; name = kb . nextLine ( ) ; System . out . print ( "Enter your Mobile Number: " ) ; mobno = kb . nextLong ( ) ; System . out . print ( "Enter cost of item purchased: " ) ; cost = kb . nextDouble ( ) ; } void calculate ( ) { if ( cost <= 10000 ) { dis = cost * 5 / 100 ; amount = cost - dis ; } else if ( cost > 10000 && cost <= 20000 ) { dis = cost * 10 / 100 ; amount = cost - dis ; } else if ( cost > 20000 && cost <= 35000 ) { dis = c