Grade 10 Computer Appications Project PDF
Grade 10 Computer Appications Project PDF
Project
2020-21
Name:
Karthikeya Kakarlapudi
Grade: X – F
Roll No:
Karthikeya Kakarlapudi 1
ACKNOWLEDGEMENT
Karthikeya Kakarlapudi 2
INDEX
S.No. Programs Pg.No.
1. For Loop Pattern Program with switch-case 4-10
2. For Loop Series program 11-14
3. Number Programs (Special Number & Harshad 15-21
Number )
4. If-else without slab 22-26
5. HCF/GCD 27-30
6. Function (Parcel) 31-35
7. Function (Consecutive Natural Numbers) 36-39
8. Call by Reference(Finding midpoint using call by 40-44
reference)
9. Constructor (Finding the roots of a quadratic
equation)
10. Nested functions (Sum of factorial of even
digits)
11. Character function
12. Palindrome Words
13. Arranging letters in alphabetical order
14. Piglatin Word
15. Linear Search
16 Binary Search
17. Selection Sort
18. Bubble Sort
19. Row Sum and Column Sum
20. Matrix Subtraction
Karthikeya Kakarlapudi 3
Question 1:
Write a program to generate a pattern of numbers in the form of a triangle or in the form
of an inverted triangle depending upon User’s choice. For an incorrect choice, an
appropriate error message should be displayed.
1 1 2 3 4 5
2 1 5 4 3 2
3 2 1 2 3 4
4 3 2 1 4 3
5 4 3 2 1 3
Karthikeya Kakarlapudi 4
Program 1:
import java.util.Scanner;
void patterns()
//taking input
int x;
int y;
switch (num)
case 1 : x = 1;
y = 1;
x=y;
System.out.print(" ");
Karthikeya Kakarlapudi 5
}
x--;
System.out.println();
y++;
break;
case 2 : x=5;
int m = 12345;
int n = m;
int digit;
int reverse=0;
y=5;
n=m;
for(int k = i-1;k>=1;k--)
System.out.print(" ");
Karthikeya Kakarlapudi 6
}
while(n>0)
//extracting digit
digit = n%10;
//reversing number
n=n/10;
m=reverse/10;
while (reverse>0)
digit = reverse%10;
reverse = reverse/10;
System.out.println();
break;
default:
Karthikeya Kakarlapudi 7
}
//creating object
obj.patterns();
Karthikeya Kakarlapudi 8
Output:
Karthikeya Kakarlapudi 9
Karthikeya Kakarlapudi 10
Question 2:
Write a program to calculate and print the sum of each of the following series within one
class:
𝑎 𝑎4 𝑎7 𝑎10
(i) S = 2! - + - + ………..upto n terms
4! 6! 8!
Karthikeya Kakarlapudi 11
Program 2:
import java.util.Scanner;
public class PROJECT2
{
public static void main(String[]args)
{
//invoking output method
PROJECT2 obj = new PROJECT2();
obj.output();
}
void output()
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number to use in the first series:");
int a = sc.nextInt();
System.out.println("Enter the number of terms to compute in both the series");
int n = sc.nextInt();
int power = 1;
int num = 2;
int factorial = 1;
int b = 1;
double sum1 = 0;
double sum2 = 0;
int x = 0;
int y = 1;
int z;
sum2 = x + y;
for(int i = 1; i<=n; i++)
{
factorial = 1;
for( int k = 1; k<=num; k++)
{
//factorial loop
factorial*=k;
}
sum1+=(((Math.pow(a,power))/factorial)*b);
b*=-1;
num+=2;
power+=3;
}
//first series output
System.out.println("The sum of the first series = "+sum1);
for( int j = 1; j<=(n-2); j++)
{
//fibbonaci summation loop
Karthikeya Kakarlapudi 12
z = x+y;
sum2+=z;
x=y;
y=z;
}
//second series output
System.out.println("The sum of the second series = "+sum2);
}
}
Karthikeya Kakarlapudi 13
Output:
Karthikeya Kakarlapudi 14
Question 3:
Write a menu driven program to accept a number from the user and check whether it is
a Special number or a Harshad number.
a) A number is said to be a special number , if the sum of the factorial of each digits of
the number is same as the original number.
Karthikeya Kakarlapudi 15
Program 3:
import java.util.Scanner;
public class PROJECT3
{
public static void main(String[]args)
{
PROJECT3 obj = new PROJECT3();
obj.output();
}
void output()
{
//creating scanner class object
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number:");
int num = sc.nextInt();
System.out.println("Enter 1 to check if it is a Special Number \n Enter 2 to check if it is Harshad
Number");
int a = sc.nextInt();
switch (a)
{
//switch case
case 1:
int digit;
int factorial=1;
int num2 = num;
int num3=0;
while(num2>0)
{
//while loop body
digit = num2%10;
for(int i =1;i<=digit;i++)
{
//factorial loop
factorial*=i;
}
num3 += factorial;
factorial=1;
Karthikeya Kakarlapudi 16
num2/=10;
}
if(num3==num)
{
System.out.println("The number entered is a Special Number");
}
else
{
System.out.println("The number entered was not a special number");
}
break;
case 2:
int sum = 0;
int d;
int num4 = num;
while(num4>0)
{
d = num4%10;
sum+=d;
num4/=10;
}
if(num%sum==0)
{
System.out.println("The number is a Harshad Number");
}
else
{
System.out.println("The number is not a Harshad Number");
}
break;
default:
//default case
System.out.println("Incorrect number entered!");
}
}
}
Karthikeya Kakarlapudi 17
Variable Description Table:
Karthikeya Kakarlapudi 18
Output:
Karthikeya Kakarlapudi 19
Karthikeya Kakarlapudi 20
Karthikeya Kakarlapudi 21
Question 4:
Class : Employee
Methods:
Write a main method to create the object of the above class and call the above method
to calculate and print the Employee_No, Name, Gross_Salary and PF of an employee.
Karthikeya Kakarlapudi 22
Program 4:
import java.util.Scanner;
public class Employee
{
void calculate()
{
// scanner object creation
Scanner sc = new Scanner(System.in);
System.out.println("Enter Employee Name:");
String name = sc.nextLine();
System.out.println("Enter Employee No.:");
long employee_no = sc.nextLong();
System.out.println("Enter Basic Salary:");
int basicsalary = sc.nextInt();
double DA = 0;
double TA = 0;
double HRA = 0;
double PF = 0;
//if else conditions
if (basicsalary<10000&&basicsalary>=0)
{
DA = 40;
TA = 8;
HRA = 14;
PF = 7;
}
else if(basicsalary>=10000&&basicsalary<20000)
{
DA = 45;
TA = 10;
HRA = 12;
PF = 7.5;
}
else if(basicsalary>=20000)
{
DA = 53;
TA = 12;
HRA = 10;
PF = 8;
}
//output
if(basicsalary>0)
{
double gross_salary = basicsalary + basicsalary*((DA+TA+HRA-PF)/100);
PF = basicsalary*PF/100;
System.out.println("Employee No.\t\tName\t\tGross Salary\t\tPF");
Karthikeya Kakarlapudi 23
System.out.println(employee_no+"\t\t"+name+"\t\t"+gross_salary+"\t\t"+PF);
}
else
{
System.out.println("Incorrect Salary entered!");
}
}
public static void main(String[]args)
{
//object creation
Employee obj = new Employee();
//method invocation
obj.calculate();
}
}
Karthikeya Kakarlapudi 24
Output:
Karthikeya Kakarlapudi 25
Karthikeya Kakarlapudi 26
Question 5:
Define a class sub1 in which define a method f1() to calculate and print hcf (highest
common factor) by division method of any two given numbers entered by user in the
main class. Define another class sub2 in which define a method f2() to calculate and
print the area and perimeter of a rectangle by using the required parameters accepted
in main class. Define main class to input the parameters required in the above two
methods and call the two functions.
[Hint : GCD
3. Take divisor as number and remainder as divisor and repeat steps 2 and 3.]
Karthikeya Kakarlapudi 27
Program 5:
import java.util.Scanner;
public class PROJECT5
{
public static void main(String[]args)
{ //Scanner object creation
Scanner sc = new Scanner(System.in);
System.out.println("Enter the first number to find GCD:");
int x = sc.nextInt();
System.out.println("Enter the second number to find GCD:");
int y = sc.nextInt();
//object creation
sub1 obj1 = new sub1();
System.out.print("The GCD of the two numbers is: ");
System.out.print(obj1.f1(x,y));
System.out.println();
System.out.println("Enter the length of the rectangle to find its area: ");
int l = sc.nextInt();
System.out.println("Enter the breadth of the rectangle to find its area: ");
int b = sc.nextInt();
sub2 obj2 = new sub2();
System.out.print("The area of the rectangle is :");
System.out.print(obj2.f2(l,b));
}
}
public class sub1
{
int f1(int num1, int num2 )
{ //parameterized function
int remainder=Math.max(num1, num2)%Math.min(num1, num2);
while(num2!=0)
{ //while loop
remainder=Math.max(num1, num2)%Math.min(num1, num2);
num1 = num2;
num2 = remainder;
}
return num1;
}
}
public class sub2
{
long f2(int length, int breadth)
{ //parameterized constructor
long area = length*breadth;
return area;
}
Karthikeya Kakarlapudi 28
Variable Description Table:
Karthikeya Kakarlapudi 29
Output:
Karthikeya Kakarlapudi 30
Question 6:
void display(int w2, String name2) : Invoke the calculate(int) to display the
total amount to be paid by the person as given
below:
Name Weight of the parcel Charge
……… ……….. ……….
Write a main method to create an object par of the class and call the required method.
Eg : Sample Input : Wt. of the parcel = 180 gms.
Sample Output: Total Charge = Rs.80
Karthikeya Kakarlapudi 31
Program 6:
import java.util.Scanner;
public class parcel
{
int calculate(int w1)
{ //parameterized constructor
int cost = 0;
if(w1<=100&&w1>=0)
{ //if condition
cost+=40;
}
else if(w1>100)
{
cost+=40;
w1-=100;
if(w1%50==0)
{
cost+=20*(w1/50);
}
else
{ //else condition
cost+=20*(w1/50)+20;
}
}
else
{
System.out.println("Invalid weight of object!");
}
return cost;
}
void display(int w2,String name2)
{ //double parameterized constructor
parcel obj1 = new parcel();
int charges = obj1.calculate(w2);
System.out.println("Name\t\t\tWeight of the Parcel\t\tCharges");
System.out.println(name2+"\t\t"+w2+"\t\t\t"+charges);
}
public static void main(String[]args)
{ //Scanner object creation
Scanner sc = new Scanner(System.in);
System.out.println("Enter your name:");
String name = sc.nextLine();
System.out.println("Enter the weight of the parcel: ");
int weight = sc.nextInt();
parcel obj2 = new parcel();
obj2.display(weight, name);
Karthikeya Kakarlapudi 32
}
}
Karthikeya Kakarlapudi 33
Output:
Karthikeya Kakarlapudi 34
Karthikeya Kakarlapudi 35
Question 7:
Write a program to input a positive natural number N and output all combination of
consecutive natural numbers which added up to give N
Example: If the N is 15 then output should be
1 2 3 4 5 = 15
4 5 6 = 15
7 8 = 15
Define a class consecutive that has the following functions.
private static void printSet(int i, int j) -> which print one line series of numbers starting
public static void main(int N) ->It accepts positive natural number N and invokes
above example.
Karthikeya Kakarlapudi 36
Program 7:
import java.util.Scanner;
}
if (sum > N)
break;
}
sum = 0; //reinitializing sum to 0
start++;
}
}
private static void printSet(int i, int j)
{ //output method
for (int k = i; k <= j; k++)
Karthikeya Kakarlapudi 37
Variable Description Table:
Karthikeya Kakarlapudi 38
Output:
Karthikeya Kakarlapudi 39
Question 8:
Karthikeya Kakarlapudi 40
Program 8:
import java.util.Scanner;
long n;
void input()
{//input method
n = sc.nextLong();
{//parameterized constructor
long factorial=1;
{//factorial loop
factorial*=i;
return factorial;
long evenDigit()
Karthikeya Kakarlapudi 41
long digit;
long num = n;
long sum = 0;
while(num>0)
{//while loop
digit = num%10;
if(digit%2==0)
sum+=fact;
num/=10;
return sum;
{//object creation
obj.input();
Karthikeya Kakarlapudi 42
Variable Description Table:
Karthikeya Kakarlapudi 43
Output:
Karthikeya Kakarlapudi 44
Karthikeya Kakarlapudi 45