0% found this document useful (0 votes)
107 views2 pages

Sample Programs Class 10

The document outlines specifications for various classes in Java, including Eshop for item purchases with discount calculations, Pizza for pizza details and cost calculations, and Mobike for bike rental management. It also includes tasks for searching values using binary search, sorting pin codes and arrays, checking for special arrays, and determining properties of numbers like duck numbers and EvenPal numbers. Each question requires the definition of a class with specific instance variables and methods to perform the described functionalities.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
107 views2 pages

Sample Programs Class 10

The document outlines specifications for various classes in Java, including Eshop for item purchases with discount calculations, Pizza for pizza details and cost calculations, and Mobike for bike rental management. It also includes tasks for searching values using binary search, sorting pin codes and arrays, checking for special arrays, and determining properties of numbers like duck numbers and EvenPal numbers. Each question requires the definition of a class with specific instance variables and methods to perform the described functionalities.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Question 1

Define a class called with the following specifications:


Class name: Eshop
Member variables:
String name: name of the item purchased
double price: Price of the item purchased
Member methods:
void accept(): Accept the name and the price of the item using the methods of Scanner class.
void calculate(): To calculate the net amount to be paid by a customer, based on the following criteria:
Price Discount
1000 – 25000 5.0%
25001 – 57000 7.5 %
57001 – 100000 10.0%
More than 100000 15.0 %
void display(): To display the name of the item and the net amount to be paid.
Write the main method to create an object and call the above methods.
Question 2
Create a class named Pizza that stores details about a pizza. It should contain the following:
Instance Variables:
String pizzaSize — to store the size of the pizza (small, medium, or large)
int cheese — the number of cheese toppings
int pepperoni — the number of pepperoni toppings
int mushroom — the number of mushroom toppings
Member Methods:
Constructor — to initialise all the instance variables
CalculateCost() — A public method that returns a double value, that is, the cost of the pizza.
Pizza cost is calculated as follows:
• Small: Rs.500 + Rs.25 per topping
• Medium: Rs.650 + Rs.25 per topping
• Large: Rs.800 + Rs.25 per topping
PizzaDescription() — A public method that returns a String containing the pizza size, quantity of each topping, and the
pizza cost as calculated by CalculateCost().
Question 3
Define a class called mobike with the following description:
Instance variables/Data members:
int bno - to store the bike's number
int phno - to store the phone number of the customer
String name - to store the name of the customer
int days - to store the number of days the bike is taken on rent
int charge - to calculate and store the rental charge
Member Methods:
void input() - to input and store the details of the customer
void compute() - to compute the rental charge
The rent for a mobike is charged on the following basis:
First five days Rs 500 per day;
Next five days Rs 400 per day;
Rest of the days Rs 200 per day.
void display () - to display the details in the following format:
Question 4
Define a class to search for a value input by the user from the list of values given below. If it is found display the message
"Search successful", otherwise display the message "Search element not found" using Binary search technique.
5.6, 11.5, 20.8, 35.4, 43.1, 52.4, 66.6, 78.9, 80.0, 95.5.
Question 5
Define a class pin code and store the given pin codes in a single dimensional array. Sort these pin codes in ascending
order using the Selection Sort technique only. Display the sorted array.
110061, 110001, 110029, 110023, 110055, 110006, 110019, 110033
Question 6
Define a class to accept values in integer array of size 10. Sort them in an ascending order using selection sort technique.
Display the sorted array.
Question 7
Define a class to accept values into a 3 × 3 array and check if it is a special array. An array is a special array if the sum of
the even elements = sum of the odd elements.
Example:
A[ ][ ]={{ 4 ,5, 6}, { 5 ,3, 2}, { 4, 2, 5}};
Sum of even elements = 4 + 6 + 2 + 4 + 2 = 18
Sum of odd elements = 5 + 5 + 3 + 5 = 18
Question 8
Define a class to accept values into 4x4 array and find and display the sum of each row.
Example:
A[][]={{1,2,3,4},{5,6,7,8},{1,3,5,7},{2,5,3,1}}
Question 9
Define a class to accept values into an integer array of order 4 x 4 and check whether it is a DIAGONAL array or not. An
array is DIAGONAL if the sum of the left diagonal elements equals the sum of the right diagonal elements. Print the
appropriate message.
Example:
3425
2523
5327
1371
Sum of the left diagonal element = 3 + 5 + 2 + 1 = 11
Sum of the right diagonal element = 5 + 2 + 3 + 1 = 11
Define a class to overload the method display as follows:
void display( ): To print the following format using nested loop

void display(int n): To print the square root of each digit of the given number.
Example:
n = 4329
Output – 3.0
1.414213562
1.732050808
2.0
Question 10
Define a class to overload the method display() as follows:
void display(): To print the following format using nested loop.
12121
12121
12121
void display (int n, int m) : To print the quotient of the division of m and n if m is greater than n otherwise print the sum of
twice n and thrice m.
double display (double a, double b, double c) — to print the value of z where

Question 11
Define a class to overload the method perform as follows:
double perform (double r, double h) — to calculate and return the value of curved surface area of cone

void perform (int r, int c) — Use NESTED FOR LOOP to generate the following format
r = 4, c = 5
output
12345
12345
12345
12345
void perform (int m, int n, char ch) — to print the quotient of the division of m and n if ch is Q else print the remainder of
the division of m and n if ch is R
Question 12
Define a class to accept a 3 digit number and check whether it is a duck number or not.
Note: A number is a duck number if it has zero in it.
Example 1:
Input: 2083
Output: Invalid
Example 2:
Input: 103
Output: Duck number
Question 13
Define a class to accept a number from user and check if it is an EvenPal number or not.
(The number is said to be EvenPal number when number is palindrome number (a number is palindrome if it is equal to its
reverse) and sum of its digits is an even number.)
Example: 121 – is a palindrome number
Sum of the digits – 1+2+1 = 4 which is an even number

You might also like