Computer Applications
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 customer
double 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 discount
Member 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 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 name, mobile number, amount to be paid after discount.
Write a main method to create an object of the class and call the above member methods.
Java
Java Classes
ICSE 2019
227 Likes
Answer
import java.util.Scanner;
public class ShowRoom
{
private String name;
private long mobno;
private double cost;
private double dis;
private double amount;
public ShowRoom()
{
name = "";
mobno = 0;
cost = 0.0;
dis = 0.0;
amount = 0.0;
}
public void input() {
Scanner in = new Scanner(System.in);
System.out.print("Enter customer name: ");
name = in.nextLine();
System.out.print("Enter customer mobile no: ");
mobno = in.nextLong();
System.out.print("Enter cost: ");
cost = in.nextDouble();
}
public void calculate() {
int disPercent = 0;
if (cost <= 10000)
disPercent = 5;
else if (cost <= 20000)
disPercent = 10;
else if (cost <= 35000)
disPercent = 15;
else
disPercent = 20;
dis = cost * disPercent / 100.0;
amount = cost - dis;
}
public void display() {
System.out.println("Customer Name: " + name);
System.out.println("Mobile Number: " + mobno);
System.out.println("Amout after discount: " + amount);
}
public static void main(String args[]) {
ShowRoom obj = new ShowRoom();
obj.input();
obj.calculate();
obj.display();
}
}Output

Answered By
116 Likes
Related Questions
Define a class with the following specifications:
Class name: Bank
Member variables:
double p — stores the principal amount
double n — stores the time period in years
double r — stores the rate of interest
double a — stores the amountMember methods:
void accept () — input values for p and n using Scanner class methods only.
void calculate () — calculate the amount based on the following conditions:Time in (Years) Rate % Upto 1⁄2 9 > 1⁄2 to 1 year 10 > 1 to 3 years 11 > 3 years 12 void display () — display the details in the given format.
Principal Time Rate Amount XXX XXX XXX XXXWrite the main method to create an object and call the above methods.
The correct statement to create an object named mango of class fruit:
- Fruit Mango= new fruit();
- fruit mango = new fruit();
- Mango fruit=new Mango();
- fruit mango= new mango();