mehnat
mehnat
I would like to express my sincere gratitude to all those who have supported and
helped me in completing this Computer Science project for Class 10 at Rani
Laxmibai Public School.
First and foremost, I would like to thank my Computer Science teacher, Archna
Ma’am, for guiding me throughout the project. Their valuable insights,
encouragement, and patience have been instrumental in enhancing my
understanding of the subject and ensuring the success of this project.
I also extend my heartfelt thanks to the principal, Ashok Sir, and the entire school
staff for providing the necessary resources and creating a conducive learning
environment.
I am grateful to my classmates and friends for their constant support, ideas, and
constructive feedback, which helped me improve the quality of my work.
Lastly, I would like to thank my family for their unwavering support and
encouragement throughout the course of this project. Their understanding and
motivation have been a constant source of strength.
This project would not have been possible without the help and encouragement of
all the above-mentioned individuals.
Page | 2
S. No. Particulars Page No.
1. Program to find the net price based on the amount after 4
reducing a suitable discount
2. Program to sort a 1D Array by using Selection Sort 8
3. Program to overload a function named JoyString() 11
4. Program to form patterns 14
5. Program to accept the vehicle number, hours parked and 17
calculate and print the vehicle number, hours parked, and
the calculated bill.
6. Program to check if the entered number Is ISBN number or 20
not.
7. Program to find the price of fruit juice and display its price 22
8. Program to encode a word into Piglatin 26
9. Program to overload and print series 28
10. Menu-driven Program to check composite nature or find the 30
largest digit
11. Program to calculate Income tax and remaining salary 34
12. Program to convert the string into upper case and count 37
number of double letter sequences in the string
13. Program with overloading to print patterns 39
14. Menu driven program to display the first 10 terms of the 42
Fibonacci series and find the sum of the digits of an integer
15. Program to calculate the wages of a Mobike 46
16. Program to input a number and check whether the number is 49
a special number
17. Program to accept a word and convert it into lower case 52
and print new word by replacing only the vowels with the
letter following.
18. Menu driven program to print series 54
19. Program to merge two arrays of length 6 and 4.Create new 57
array of length 10.
20. Program to find an element using Linear Search 60
INDEX
QUESTION 1:
Page | 3
Define a class called with the following specifications:
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.
Page | 4
ANSWER 1:
import java.util.Scanner;
String name;
double price;
double disc;
double amount;
name = in.nextLine();
price = in.nextDouble();
double d = 0.0;
d = 0.0;
d = 5.0;
d = 7.5;
Page | 5
d = 10.0;
else
d = 15.0;
obj.accept();
obj.calculate();
obj.display();
VARIABLE DESCRIPTION:
Name of the Data Type Purpose/description
Variable
name String To store the name of the product
price double To store the price of the product
disc double To store the discount on price of the product
amount double To store the amount of the product
Page | 6
SAMPLE INPUT:
SAMPLE OUTPUT:
Page | 7
QUESTION 2:
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.
ANSWER 2:
import java.util.Scanner;
class Arrray
void main()
for(int i=0;i<10;i++)
A[i]=abc.nextInt();
int t=0;
System.out.print("Unsorted Array");
for(int i=0;i<10;i++)
System.out.print(A[i]+"\t");
for(int i=0;i<9;i++)
for(int j=i+1;j<10;j++)
Page | 8
{
if(A[i]>A[j])
t=A[i];
A[i]=A[j];
A[j]=t;
System.out.print("\nSorted Array");
for(int i=0;i<10;i++)
System.out.print(A[i]+"\t");
VARIABLE DESCRIPTION:
Name of the Data Type Purpose/description
Variable
abc object To use the Scanner
A[] int To store array
i int To use in outer loop
j int To use in inner loop
Page | 9
SAMPLE INPUT:
SAMPLE OUTPUT:
Page | 10
QUESTION 3:
Design a class to overload a function Joystring( ) as follows:
void Joystring(String s, char ch1, char ch2) with one string argument and two character
arguments that replaces the character argument ch1 with the character argument ch2 in the given
String s and prints the new string.
Output: "TECHNOLOGY"
void Joystring(String s) with one string argument that prints the position of the first space and the
last space of the given String s.
Last Index: 36
void Joystring(String s1, String s2) with two string arguments that combines the two strings with
a space between them and prints the fant string.
ANSWER 3:
public class Joystring
System.out.println(f);
void Joystring(String s)
Page | 11
int fI = s.indexOf(' ');
VARIABLE DESCRIPTION:
Page | 12
SAMPLE INPUT:
SAMPLE OUTPUT:
SAMPLE INPUT:
SAMPLE OUTPUT:
SAMPLE INPUT:
SAMPLE OUTPUT:
Page | 13
QUESTION 4:
Write two separate programs to generate the following patterns using iteration (loop) statements:
(a)
*#
*#*
*#*#
*#*#*
(b)
54321
5432
543
54
ANSWER 4:
(a)
class Pattern
void main()
if (j % 2 != 0) {
Page | 14
System.out.print("* ");
} else {
System.out.print("# ");
System.out.println();
(b)
class Pattern
void main()
System.out.println();
Page | 15
VARIABLE DESCRIPTION:
Name of the Data Type Purpose/description
Variable
i int Controls the number of rows
j int Controls the number of columns
i int Controls the number of rows
j int Controls the number of columns
SAMPLE OUTPUT:
(a)
(b)
Page | 16
QUESTION 5:
Define a class called ParkingLot with the following description:
int hours — To store the number of hours the vehicle is parked in the parking lot.
Member Methods:
void calculate() — To compute the parking charge at the rate of ₹3 for the first hour or part
thereof, and ₹1.50 for each additional hour or part thereof.
Write a main() method to create an object of the class and call the above methods.
ANSWER 5:
import java.util.Scanner;
class ParkingLot
int vno;
int hours;
double bill;
void input()
vno = sc.nextInt();
Page | 17
hours = sc.nextInt();
void calculate()
if (hours <= 1) {
bill = 3;
} else {
void display()
parking.input();
parking.calculate();
parking.display();
Page | 18
VARIABLE DESCRIPTION:
Name of the Data Type Purpose/description
Variable
vno int To store the vehicle number.
hours int To store the number of hours the vehicle is parked
in the parking lot
bill double To store the bill amount.
SAMPLE INPUT:
SAMPLE OUTPUT:
Page | 19
QUESTION 6:
The International Standard Book Number (ISBN) is a unique numeric book identifier which is
printed on every book. The ISBN is based upon a 10-digit code. The ISBN is legal if: 1 × digit1
+ 2 × digit2 + 3 × digit3 + 4 × digit4 + 5 × digit5 + 6 × digit6 + 7 × digit7 + 8 × digit8 + 9 ×
digit9 + 10 × digit10 is divisible by 11.
Sum = 1 × 1 + 2 × 4 + 3 × 0 + 4 × 1 + 5 × 6 + 6 × 0 + 7 × 1 + 8 × 4 + 9 × 9 + 10 × 9 = 253
which is divisible by 11.
If the ISBN is not a 10-digit integer, output the message "Illegal ISBN" and terminate the
program.
If the number is divisible by 11, output the message "Legal ISBN". If the sum is not divisible by
11, output the message "Illegal ISBN".
ANSWER 6:
import java.util.Scanner;
long n = scanner.nextLong();
int c = 0;
c++;
Page | 20
if (c != 10) {
System.out.println("Illegal ISBN");
int sum = 0;
sum += d * j;
i /= 10;
if(sum%11==0)
System.out.println("Legal ISBN");
else
System.out.println("Illegal ISBN");
VARIABLE DESCRIPTION:
Name of the Data Type Purpose/description
Variable
vno int To store the vehicle number.
hours int To store the number of hours the vehicle is parked
in the parking lot
bill double To store the bill amount.
SAMPLE INPUT:
SAMPLE OUTPUT:
Page | 21
QUESTION 7:
Define a class named FruitJuice with the following description:
ANSWER 7:
import java.util.Scanner;
class FruitJuice {
int product_code;
String flavour;
String pack_type;
int pack_size;
int product_price;
FruitJuice()
product_code = 0;
flavour = "";
Page | 22
pack_type = "";
pack_size = 0;
product_price = 0;
void input()
product_code = abc.nextInt();
abc.nextLine();
flavour = abc.nextLine();
pack_type = abc.nextLine();
pack_size = abc.nextInt();
product_price = abc.nextInt();
void discount()
product_price -= 10;
void display()
Page | 23
System.out.println("Product Code: " + product_code);
juice.input();
juice.discount();
juice.display();
VARIABLE DESCRIPTION:
Variable Description
int product_code To store the product code number
String flavour To store the flavour of the juice (e.g., orange,
apple, etc.)
String pack_type To store the type of packaging (e.g., tera-pack, PET
bottle, etc.)
int pack_size To store package size (e.g., 200 mL, 400 mL, etc.)
int product_price To store the price of the product
Page | 24
SAMPLE INPUT:
SAMPLE OUTPUT:
Page | 25
QUESTION 8:
Write a program that encodes a word into Piglatin.
To translate word into Piglatin word, convert the word into uppercase and then place the first
vowel of the original word as the start of the new word along with the remaining alphabets.The
alphabets present before the vowel being shifted towards the end followed by "AY".
ANSWER 8:
import java.util.Scanner;
class PIGLATIN {
String s = abc.next();
String n = s.toUpperCase();
char ch = n.charAt(0);
String o = "";
o = n + "AY";
System.out.println(o);
else
ch = n.charAt(i);
Page | 26
o = n.substring(i) + n.substring(0, i) + "AY";
break;
System.out.println(o);
VARIABLE DESCRIPTION:
Name of the Data Type Purpose/description
Variable
s String Store original string
n String Store capitalised string
ch char Store characters of string
o String Stores new String
abc object Scanner object
SAMPLE INPUT:
SAMPLE OUTPUT:
Page | 27
QUESTION 9:
Design a class to overload a function series( ) as follows:
double series(double n) with one double argument and returns the sum of the series.
double series(double a, double n) with two double arguments and returns the sum of the series.
ANSWER 9:
class SeriesCalculator
double s = 0;
s += 1.0 / i;
return s;
double s=0;
double i=1;
double d=2;
Page | 28
s += i / Math.pow(a, d);
i += 3;
d +=3;
return s;
VARIABLE DESCRIPTION:
Name of the Data Type Purpose/description
Variable
s double Stores the sum of the series. It accumulates the
. results as terms are added in each series method
n double Represents the number of terms for the first series
method
a double Represents the base value used for exponentiation
in the second series method
i double Used as the numerator in the second series
method
SAMPLE INPUT:
SAMPLE OUTPUT:
Page | 29
QUESTION 10:
Using the switch statement, write a menu driven program:
To check and display whether a number input by the user is a composite number or not. A number is
said to be composite, if it has one or more than one factors excluding 1 and the number itself.
Example: 4, 6, 8, 9...
Sample input: 6524 Sample output: Smallest digit is 2 For an incorrect choice, an appropriate error
message should be displayed.
ANSWER 10:
import java.util.Scanner;
int choice;
for (;;)
System.out.println("Menu:");
System.out.println("3. Exit");
choice = sc.nextInt();
switch (choice)
Page | 30
{
case 1:
if (isComposite(number)) {
} else {
break;
case 2:
int n = sc.nextInt();
break;
case 3:
sc.close();
default:
Page | 31
}
if (number <= 1) {
return false;
if (number % i == 0) {
return true;
return false;
int smallest = 9;
smallest = digit;
number /= 10;
return smallest;
Page | 32
}
VARIABLE DESCRIPTION:
Name of the Data Type Purpose/description
Variable
choice Stores the user's choice from the menu to
perform specific actions.
int
SAMPLE INPUT:
SAMPLE OUTPUT:
Page | 33
QUESTION 11:
Given below is a hypothetical table showing rates of income tax for male citizens below the age
of 65 years:
Write a program to input the age, gender (male or female) and Taxable Income of a person. If the
age is more than 65 years or the gender is female, display “wrong category”. If the age is less
than or equal to 65 years and the gender is male, compute and display the income tax payable as
per the table given above.
ANSWER 11:
import java.util.Scanner;
sc.nextLine();
Page | 34
if (age > 65 || gender.equals("female"))
System.out.println("Wrong category");
} else
double tax = 0;
tax = 0;
} else {
VARIABLE DESCRIPTION:
Name of the Data Type Purpose/description
Variable
age Stores the age of the person.
int
Page | 35
gender String Stores the gender of the person (male or female).
SAMPLE INPUT:
SAMPLE OUTPUT:
Page | 36
QUESTION 12:
Write a program to accept a string. Convert the string into upper case letters. Count and output
the number of double letter sequences that exist in the string.
Sample Input: "SHE WAS FEEDING THE LITTLE RABBIT WITH AN APPLE" Sample
Output: 4
ANSWER 12:
import java.util.Scanner;
String uS = input.toUpperCase();
int count = 0;
count++;
Page | 37
VARIABLE DESCRIPTION:
Name of the Data Type Purpose/description
Variable
sc Scanner Used to take user input from the console.
SAMPLE INPUT:
SAMPLE OUTPUT:
Page | 38
QUESTION 13:
Design a class to overload a function polygon() as follows:
void polygon(int n, char ch) — with one integer and one character type argument to draw a filled
square of side n using the character stored in ch.
void polygon(int x, int y) — with two integer arguments that draws a filled rectangle of length x
and breadth y, using the symbol '@'.
void polygon() — with no argument that draws a filled triangle shown below:
Output:
OO
OO
Input value of x = 2, y = 5
Output:
@@@@@
@@@@@
Output:
**
***
ANSWER 13:
import java.util.Scanner;
Page | 39
{
System.out.print(ch);
System.out.println();
System.out.print('@');
System.out.println();
void polygon()
System.out.print('*');
System.out.println();
Page | 40
}
VARIABLE DESCRIPTION:
Name of the Data Type Purpose/description
Variable
n int Stores the side length of the square for drawing a
filled square.
choice int Stores the user's choice for the type of polygon to
be drawn.
Page | 41
QUESTION 14:
Using a switch statement, write a menu driven program to:
(a) Generate and display the first 10 terms of the Fibonacci series 0, 1, 1, 2, 3, 5 The first two
Fibonacci numbers are 0 and 1, and each subsequent number is the sum of the previous two.
(b) Find the sum of the digits of an integer that is input. Sample Input: 15390 Sample Output:
Sum of the digits = 18 For an incorrect choice, an appropriate error message should be displayed.
ANSWER 14:
import java.util.Scanner;
while (true) {
System.out.println("Menu:");
System.out.println("3. Exit");
switch (choice)
case 1:
generateFibonacci();
break;
case 2:
Page | 42
sumOfDigits();
break;
case 3:
sc.close();
System.exit(0);
default:
break;
int n = 10;
int a = 0, b = 1;
int c = a + b;
a = b;
b = c;
System.out.println();
Page | 43
public static void sumOfDigits() {
int sum = 0;
while (num != 0) {
num /= 10;
VARIABLE DESCRIPTION:
Name of the Data Type Purpose/description
Variable
Used for taking input from the user via the
sc Scanner console.
choice int Stores the user's choice from the menu options.
SAMPLE INPUT:
Page | 44
SAMPLE OUTPUT:
SAMPLE INTPUT:
SAMPLE OUTPUT:
Page | 45
QUESTION 15:
Define a class called 'Mobike' with the following specifications:
Days Charge
For first five days ₹500 per day
For next five days ₹400 per day
Rest of the days ₹200 per day
Output:
ANSWER 15:
import java.util.Scanner;
class Mobike {
int bno;
int phno;
String name;
int days;
int charge;
void input()
Page | 46
{
bno = sc.nextInt();
phno = sc.nextInt();
sc.nextLine();
name = sc.nextLine();
days = sc.nextInt();
void compute() {
if (days <= 5) {
} else {
void display()
System.out.println("\nBike No. " + bno + " Phone No. " + phno + " Name " + name + " No.
of days " + days + " Charge ₹" + charge);
Page | 47
}
bike.input();
bike.compute();
bike.display();
VARIABLE DESCRIPTION:
Name of the Data Type Purpose/description
Variable
Stores the bike number
bno int
SAMPLE INTPUT:
SAMPLE OUTPUT:
Page | 48
QUESTION 16:
Write a program to input a number and print whether the number is a special number or not. (A
number is said to be a special number, if the sum of the factorial of the digits of the number is
same as the original number).
(Where ! stands for factorial of the number and the factorial value of a number is the product of
all integers from 1 to that number, example 5! = 1 * 2 * 3 * 4 * 5 = 120)
ANSWER 16:
import java.util.Scanner;
class SpecialNumber
int fact = 1;
fact *= i;
return fact;
Page | 49
int sum = 0;
sum += factorial(digit);
num /= 10;
if (sum == originalNum)
} else {
VARIABLE DESCRIPTION:
Name of the Data Type Purpose/description
Variable
num int . Stores the user input number to be checked
for being specia
Page | 50
SAMPLE INTPUT:
SAMPLE OUTPUT:
Page | 51
QUESTION 17:
Write a program to accept a word and convert it into lower case, if it is in upper case. Display the
new word by replacing only the vowels with the letter following it. Sample Input: computer
Sample Output: cpmpvtfr
ANSWER 17:
import java.util.Scanner;
class VowelReplacement
word = word.toLowerCase();
char ch = word.charAt(i);
result.append((char)(ch + 1));
} else {
result.append(ch);
Page | 52
System.out.println("Modified word: " + result.toString());
VARIABLE DESCRIPTION:
Name of the Data Type Purpose/description
Variable
word String . Stores the input word entered by the user
SAMPLE INTPUT:
SAMPLE OUTPUT:
Page | 53
QUESTION 18:
Write a menu driven program to perform the following tasks by using Switch case statement:
(a) To print the series: 0, 3, 8, 15, 24, ............ to n terms. (value of 'n' is to be an input by the
user)
(b) To find the sum of the series: S = (1/2) + (3/4) + (5/6) + (7/8) + ........... + (19/20)
ANSWER 18:
import java.util.Scanner;
class SeriesOperations {
int choice;
for (;;) {
System.out.println("Menu:");
System.out.println("2. Find the sum of the series: (1/2) + (3/4) + (5/6) + ... + (19/20)");
System.out.println("3. Exit");
choice = sc.nextInt();
switch (choice) {
case 1:
int n = sc.nextInt();
System.out.print("Series: ");
Page | 54
System.out.print(i * i + " ");
System.out.println();
break;
case 2:
double sum = 0;
break;
case 3:
System.out.println("Exiting...");
return;
default:
Page | 55
VARIABLE DESCRIPTION:
Name of the Data Type Purpose/description
Variable
Stores the user's menu choice to decide
choice int the action (1, 2, or 3).
SAMPLE INTPUT:
SAMPLE OUTPUT:
SAMPLE INPUT:
SAMPLE OUTPUT:
Page | 56
QUESTION 19:
Write a program to store 6 elements in an array P and 4 elements in an array Q. Now, produce a
third array R, containing all the elements of array P and Q. Display the resultant array.
ANSWER 19:
import java.util.Scanner;
P[i] = sc.nextInt();
Page | 57
for (int i = 0; i < Q.length; i++)
Q[i] = sc.nextInt();
R[i] = P[i];
R[P.length + i] = Q[i];
VARIABLE DESCRIPTION:
Name of the Data Type Purpose/description
Variable
To store 6 elements for the first array.
P int[]
.
Page | 58
Q int[] To store 4 elements for the second array.
SAMPLE INPUT:
SAMPLE OUTPUT:
Page | 59
QUESTION 20:
Define a class to accept values into an array of double data type of size 20. Accept a double
value from user and search in the array using linear search method.
If value is found display message "Found" with its position where it is present in the array.
Otherwise display message "not found"
ANSWER 19:
import java.util.Scanner;
class LinearSearchArray
arr[i] = sc.nextDouble();
if (arr[i] == value)
Page | 60
found = true;
position = i;
break;
if (found)
else
System.out.println("Not found");
VARIABLE DESCRIPTION:
Name of the Data Type Purpose/description
Variable
arr double[] To store the 20 double values entered by the
user.
Page | 61
SAMPLE INPUT:
SAMPLE OUTPUT:
Page | 62