Show Room (Slab) Version 2

Design a class with the following description.

Class Name: ShowRoom

Data Members:

  • String name – To store the name of the consumer.
  • long mobile – To store consumer’s mobile number.
  • double cost – To store the cost of the item purchased.
  • double amount – To store the amount to be paid after discount.

Member Methods:

  • ShowRoom() – Default constructor to initialize the data members.
  • void input() – To input consumer name, mobile number and cost of item.
  • void calculate() – To calculate the discount on the cost of purchased items based on the following criteria.
    • First ₹500 discount will be ₹0.
    • Next ₹501 to ₹1000 discount will be ₹100.
    • Next ₹1001 to ₹5000 discount will be ₹300.
    • Next ₹5001 to ₹10000 discount will be ₹600.
    • More than ₹10000 discount will be ₹1000.
  • void display() – To print all details.

Write a main method to create an object of the class and call methods.

Java
import java.util.*;
public class ShowRoom
{
    String name;
    long mobile;
    double cost,amount;
    ShowRoom()
    {
        name="";
        mobile=0;
        cost=0.0;
        amount=0.0;
    }
    public void input()
    {
        Scanner sc=new Scanner(System.in);
        System.out.print("Consumer name: ");
        name=sc.nextLine();
        System.out.print("Consumer's mobile number: ");
        mobile=sc.nextLong();
        System.out.print("Cost of the item purchased: ");
        cost=sc.nextDouble();
        System.out.println();
    }
    public void calculate()
    {
        if(cost<500)
        {
          amount=cost-0;  
        }
        else if(cost>=500&&cost<=1000)
        {
           amount=cost-100-0;
        }
        else if(cost>1000&&cost<=5000)
        {
            amount=cost-300-100-0; 
        }
        else if(cost>5000&&cost<=10000)
        {
           amount=cost-600-300-100-0;
        }
        else if(cost>10000)
        {
          amount=cost-1000-600-300-100-0; 
        }
        else
        {
            System.out.println("Cost can not be zero or negative");
        }
    }
    public void display()
    {
        System.out.println("Customer's Name: "+name);
        System.out.println("Customer's Mobile Number: "+mobile);
        System.out.println("Cost of the product: "+cost);
        System.out.println("Amount to be paid after discount: "+amount);
    }
    public static void main(String args[])
    {
        ShowRoom ob=new ShowRoom();
        ob.input();
        ob.calculate();
        ob.display();
    }
}
Java