

- Java Programs
- Java Programs - Home
- Short Questions/Answers
- Class & Object Based Program - CloudStorage
- Square root of sum of squares of all elements - NORM
- Super String Program
- Binary Search Program
- Menu Driven Program
- Check Sum Program
- Short Questions/Answers
- Class & Object Based Program - Bank
- Binary Search Program
- String to Uppercase Program
- Sum of Row in Array Program
- SUPERSPY Program
- Menu Driven Program - Overload Method
- Short Questions/Answers
- Class & Object Based Program - Courier Service Program
- Method Overloading Program
- EvenPal Program
- Diagonal Array Program
- Selection Sort Program
- Gmail ID Validation Program
- Short Questions/Answers
- Class & Object Based Program - Eshop
- Selection Sort Program
- Count the Vowels Program
- Sum of Even & Odd Elements in Array Program
- Duck Number Program
- Method Overloading Program
- Short Questions/Answers
- Class & Object Based Program - Student Stream Allocation
- Bubble Sort Program
- Menu Driven Program - Overload Method
- Print Number of Digits, Alphabets and Special Characters Program
- Linear Search Program
- Sum of Single and Double Digit Number in Array Program
- Short Questions/Answers
- Class & Object Based Program - Hotel Bill Calculation
- Bubble Sort Program
- Menu Driven Program - Overload Method
- Method Overloading - Pattern & Series
- EvenPal Program
- Student Range Program
- Short Questions/Answers
- Class & Object Based Program - Cab Service
- Binary Search Technique Program
- UpperCase Conversion Program
- Method Overloading
- Menu Driven Program - Pattern & Series
- Double Dimensional Array - Diagonal Sum
- Short Questions/Answers
- Class & Object Based Program
- Arrange Student details using Selection Sort Method
- Class Overload Program
- Menu Driven Program
- Sum of elements in Double Dimensional Array Program
- Pair of Vowels Program
- Short Questions/Answers
- Class & Object Based Program
- Menu Driven Program - Generate Unicode, Pattern
- Sort Array Elements in Ascending Order using the Bubble Sort Technique Program
- Series Overload Program
- Count Letters in a Sentence Program
- Tech Number Program
- Short Questions/Answers
- Class & Object Based Program - Railway Ticket
- Pronic Number
- Proper Case Sentence Program
- Function Overloading - Volume Program
- Menu Driven Program - Pattern
- Deviation Program
- Short Questions/Answers
- Class & Object Based Program - Electric Bill
- Spy Number Program
- Menu Driven Program - Series Program
- Array Based Program - Largest Number, Smallest Number, Sum of Numbers Program
- Function Overload - String Program
- Alphabet Sort - Selection Sort Techniques Program
- Short Questions/Answers
- Class & Object Based - Taxi Meter Program
- Menu driven - Sum of Series Program
- Abbreviation Program
- Largest & Smallest Integer in Array Program
- Sum of Prime Numbers Program
- Sort Names in Array Program
- Short Questions/Answers
- Class & Object - Book Fair Program
- Menu Driven - Pattern Program
- Palindrome or Special Word Program
- Function Overloading - Sum of Series Program
- Niven Number Program
- Two Different Arrays Program
- Short Questions/Answers
- Class & Object - Parking Lot Program
- Pattern Program
- Array Based Student Result Program
- Function Overloading String Based Program
- Arrange Names - Bubble Sort Technique Program
- Menu Driven - Factors/Factorial Program
- Short Questions/Answers
- Class & Object - Movie Magic Program
- Special Two-digit Number Program
- Assign Full Path and File name Program
- Function Overloading - Area Program
- Menu Driven - Bank Deposit Program
- Array Sort - Binary Search Program
- Short Questions/Answers
- Class & Object - FruitJuice Program
- International Standard Book Number (ISBN) Program
- Piglatin Program
- Descending Order Bubble Sort Program
- Function Overloading - Sum of Series Program
- Menu Driven - Composite Number / Smallest digit in Number Program
- Short Questions/Answers
- Class & Object - Library Program
- Income Tax Calculation Program
- Double Letter Sequences in a String Program
- Function Overloading - Polygon Program
- Menu Driven - Fibonacci / Sum of Digits Program
- STD (Subscriber Trunk Dialing) Codes Program
- Short Questions/Answers
- Class & Object - Mobike Program
- Descending Order - Selection Sort Program
- Special Number Program
- New Word by replacing Vowels with the next Character Program
- Function Overloading - Compare Integers, Characters, Strings Program
- Menu Driven - Series Program
- Short Questions/Answers
- Binary Search Program
- Class & Object - Student Marks Program
- Ticket Discount Program
- Menu Driven - Prime Number / Automorphic Number Program
- Combine Two Arrays in Third Array Program
- Frequency of Characters in a String Program
- Short Questions/Answers
- Electronic Shop Discount Program
- Generate Triangle / Inverted Triangle Program
- Longest Word Program
- Function Overloading - Number Calculation Program
- Menu driven - BUZZ Number / GCD Program
- Exam Results Program
- Short Questions/Answers
- Tax Computation Program
- Reverse Uppercase & Lowercase in String Program
- Sort String Bubble Sort Program
- Menu Driven - Palindrome / Perfect Number Program
- Function Overloading - Volume Program
- Sum of Series Program
- Short Questions/Answers
- Salary Calculation Program
- Sum of Series Program
- Maximum & Minimum Program
- Count of a word in String Program
- Menu Driven - Temperature Program
- Palindrome Program
Java Programs - Solved 2019 ICSE Computer Science Paper
![]() Share with a Friend |
Class & Object Based Program - Java Programs
Design a class 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 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 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.
import java.util.Scanner; class ShowRoom{ String name; long mobNo; double cost; double dis; double amount; public ShowRoom(){ name = ""; mobNo = 0L; cost = 0.0; dis = 0.0; amount = 0.0; } public void input(){ Scanner in = new Scanner(System.in); System.out.print("Name: "); name = in.nextLine(); System.out.print("Mobile number: "); mobNo = Long.parseLong(in.nextLine()); System.out.print("Cost of items: "); cost = Double.parseDouble(in.nextLine()); } public void calculate(){ if(cost <= 10000) dis = 5.0; else if(cost <= 20000) dis = 10.0; else if(cost <= 35000) dis = 15.0; else dis = 20.0; dis = dis / 100 * cost; amount = cost - dis; } public void display(){ System.out.println("Name: " + name); System.out.println("Mobile number: " + mobNo); System.out.println("Amount: " + amount); } public static void main(String[] args){ ShowRoom obj = new ShowRoom(); obj.input(); obj.calculate(); obj.display(); } }
Output
OUTPUT 1: Name: Anand Rao Mobile number: 1234567890 Cost of items: 12000 Name: Anand Rao Mobile number: 1234567890 Amount: 10800.0 OUTPUT 2: Name: Ajay Singh Mobile number: 9087654321 Cost of items: 21000 Name: Ajay Singh Mobile number: 9087654321 Amount: 17850.0