Solution of Computer Practical Records For Class X - Part 1
Solution of Computer Practical Records For Class X - Part 1
1. Write a program in Java to accept two number and display the remainder by dividing greater
number by smaller number.
// Program to display the remainder by dividing two number
import java.util.*;
class PQ1
{
public static void main()
{
int num1, num2,rem;
Scanner sc = new Scanner (System.in);
System.out.println("Enter the perpendicular and base of the triangle");
num1=sc.nextInt();
num2=sc.nextInt();
if(num1 > num2)
rem = num1%num2;
else
rem = num2%num1;
System.out.println("Remainder by dividing two number ="+rem);
}
}
2. Mr. A.P.Singh is a software engineer. He pays annual income tax as per the given table
Annual Salary Rate of Income Tax
Upto Rs. 2,50,000 No tax
Rs. 2,50,001 to Rs 5,00,000 10% of the amount exceeding Rs. 2,50,000(excluding STD
deduction 50000)
Rs. 5,00,0001 to Rs 10,00,000 Rs. 12500 + 20% of the amount exceeding Rs. 5,00,000
Above Rs. 10,00,000 Rs. 1,12,500 + 30% of the amount exceeding Rs. 10,00,000
import java.util.*;
class PQ2
{
public static void main()
{
Scanner sc = new Scanner (System.in);
double A_sal, tax; tax=0.0;
System.out.println("Enter the Annual Salary of the person");
A_sal= sc.nextDouble();
if(A_sal<=250000)
tax = 0.0;
if(A_sal>250000 && A_sal<=500000)
tax = 10.0/100*(A_sal - 100000);
if(A_sal>500000 && A_sal<=250000)
tax = 5000 + 20.0/100*(A_sal - 150000);
if(A_sal>250000 )
tax = 25000 + 30.0/100*(A_sal - 250000);
System.out.println( "Tax to be paid by the person = "+tax);
}
}
// Program to display the Dearness Allowance, Special Allwance and Gross Salary of an employee
import java.util.*;
class PQ4
{
public static void main()
{
Scanner sc = new Scanner (System.in);
double bs,da,gs,sa; da=0.0;sa=0.0;gs = 0.0;
System.out.println("Enter the Basic salary");
bs = sc.nextDouble();
if( bs <= 10000)
{
da = 0.10*bs;
sa = 0.05*bs;
}
if (bs> 10000 && bs <=20000)
{
da = 0.12*bs;
sa = 0.08*bs;
}
if (bs> 200000 && bs <= 30000)
{
da = 0.15*bs;
sa = 0.10* bs;
}
if (bs >30000)
{
da = 0.20*bs;
sa = 0.12*bs;
}
gs = bs+da+sa;
System.out.println("Basic \t\t DA \t\t SA \t\t Gross Salary");
System.out.println(bs+"\t\t"+ da + "\t\t"+ sa +"\t\t\t"+ gs);
}
}
5. Write a program to accept a number and check whether the number is Sunny number or not.(Square root
of successor of the number is an integer.)
// Program to fin the Sunny number or not
import java.util.*;
class PQ5
{
public static void main()
{
Scanner sc = new Scanner(System.in);
int num, sunn;
System.out.println("Enter the number to find Sunny number");
num=sc.nextInt();
sunn = (int)Math.sqrt(num + 1);
if (sunn * sunn == num +1)
System.out.println( num + "is a Sunny number");
else
System.out.println( num + "is not a Sunny number");
}
}
6. Write a program to accept two numbers and find the Greatest Common Divisor (G.C.D) of two numbers.
Sample Input : 25, 45
Sample Output : The Greatest Divisor : 5
}
}
13. Write a program to accept a number and display the frequency of each digit present in the number.
Sample Input : 341124
Sample Output : The frequency of 1 = 2
The frequency of 4 = 2
15. Write a menu driven program to accept a number from the user and check whether it is a ‘BUZZ’ number
or to accept two numbers and print the ‘GCD’ of them.
(i) A Buzz number is the number which either ends with 7 or is divisible by 7
(ii) GCD (Greatest Common Divisor) of two integers is calculated by continued division method .
Divide the larger number by the smaller, the remainder then divides the previous. The process is
repeated till the remainder is zero. The divisor then result the GCD.
// program related menu driven
import java.util.*;
class PQ15
{
public static void main()
{
Scanner sc = new Scanner (System.in);
int ch;
System.out.println("1.BUZZ Number");
System.out.println("2.GCD Number");
System.out.println("Enter your choice (1 - 2)");
ch = sc.nextInt();
switch(ch)
{
case 1: int num,n,a,rev;rev=0;
System.out.println("Enter the number");
num = sc.nextInt();
if((num%10 == 7)|| (num%7 == 0))
System.out.println("It is BUZZ Number");
else
System.out.println("It is not a BUZZ Number");
break;
case 2:int n1,n2,r;
System.out.println("Enter the first number");
n1 = sc.nextInt();
System.out.println("Enter the second number");
n2 = sc.nextInt();
while(n2!=0)
{
r = n1%n2;
n1= n2;
n2= r;
}
System.out.println("GCD = "+n1);
break;
default : System.out.println("Invalid Input");
}
}
}
16. Write a program to accept two number and check whether they are twin prime or not, using function name
prime(). The function return 1 if the number is prime otherwise return 0. (Twin prime numbers are such
prime number whose difference is 2 (11,13), (17,19), …. Are the examples of twin prime numbers.
// To display the given number is Twin prime or not
import java.util.*;
class PQ16
{
public static int prime(int n)
{// function to check and return prime number
int i,c;c=0;
for(i=1;i<=n;i++)
{
if(n%i==0)
c++;
}
if (c==2)
return 1;
else
return 0;
}
// main function to invoke the prime for Twin Prime
public static void main()
{
Scanner sc = new Scanner(System.in);
int num1,num2,pri1,pri2;
System.out.println ("Enter the two number to check Twin Prime number or not");
num1 = sc.nextInt();
num2 = sc.nextInt();
pri1= prime(num1);
pri2= prime(num2);
if((pri1==1)&&(pri2==1)&&(num1-num2==2)||(num2-num1==2))
System.out.println("It is Twin Prime number");
else
System.out.println("It is not a Twin Prime number");
}
}
8 cm 8 cm
18. Write a program to find the total area of given figure using function.
8 cm
8 cm
// program related Function to find area of shadede parts
import java.util.*;
class PQ18
{
public static double tri(int s)
{// function to return area of equilateral Triangle
double ar=0.0;
ar = Math.sqrt(3)/4*s*s;
return ar;
}
public static double cir(int r)
{// function to return area of Circle
double ar=0.0;
ar = 3.14*r/2*r/2;
return ar;
}
public static double sqr(int s)
{// function to return area of Square
double ar=0.0;
ar = s*s;
return ar;
}
// main function to invoke the prime
public static void main()
{
Scanner sc = new Scanner(System.in);
double fig1,fig2,fig3,fig=0.0;
fig1 = tri(8);
fig2 = cir(8);
fig3 = sqr(8);
fig = fig1+fig3-fig2;
System.out.println("Area of the shaded figure ="+fig);
}
}
19. Write a menu riven program using a method Number() to perform the following tasks:
(i) Accept a number from the user and display in its Binary Equivalents.
e.g. Sample Input : (21)10, Sample Output : (10101)2
(ii) Accept a number from the user and display in its Octal Equivalents.
e.g. Sample Input : (158)10, Sample Output : (632)8
// program related menu driven
import java.util.*;
class PQ19
{
public static void main()
{
Scanner sc = new Scanner (System.in);
int ch;
System.out.println("1.Convert Decimal to Binary");
System.out.println("2.Convert Binary to Decimal");
System.out.println("Enter your choice (1 - 2)");
ch = sc.nextInt();
switch(ch)
{
case 1: int num,n,a,bin,c;bin=0;c=0;
System.out.println("Enter the number");
num = sc.nextInt();
n=num;
while(num>0)
{
a=num%2;
bin = bin+a*(int)Math.pow(10,c);
c++;
num=num/2;
}
System.out.println(n+" converted to "+bin);
break;
case 2:int num1,n1,a1,dec,c1;dec=0;c1=0;
System.out.println("Enter the number");
num1 = sc.nextInt();
n1=num1;
while(num1>0)
{
a1=num1%10;
dec = dec+a1*(int)Math.pow(2,c1);
c1++;
num1=num1/10;
}
System.out.println(n1+" converted to "+dec);
break;
default : System.out.println("Invalid Input");
}
}
}
20. Design a class overloading a function calculate () as follows :
(i) void calculate ( int m, char ch) with one integer argument and one character argument. It check
whether the integer argument is divided by 7 or not, if ch is ‘s’ otherwise, it check the last digit of
the integer argument contain 7 or not.
(ii) void calculate (int a, int b, char ch) with two integer arguments and one character argument. It
displays the greater of integer arguments if ch is ‘g’ otherwise, displays the smaller of integer
arguments.
// program for function overloading
class PQ20
{
void calculate(int m, char ch)
{
if(ch == 's' || ch == 'S')
{
if(m%7==0)
System.out.println("The number is divisible by 7");
else
System.out.println("The number is not divisible by 7");
}
else
{
if(m%10==7)
System.out.println("The last digit of the number is 7");
else
System.out.println("The last digit of the number is not 7");
}
}
void calculate(int a, int b, char ch)
{
if(ch == 'g' || ch == 'G')
{
if(a>b)
System.out.println(a+ "is greater than "+b);
else
System.out.println(b+ "is greater than "+a);
}
else
{
if(a<b)
System.out.println(a+ "is smaller than "+ b);
else
System.out.println(b+ "is smaller than "+ a);
}
}
}
1 4 7 10
𝑆𝑢𝑚 = + + + +⋯ , to n terms
𝑎2 𝑎5 a8 a11
From Rs. 1,00,001 to Rs. 1,50,000 10 % of the income exceeding Rs. 1,00,000
From Rs.1,50,001 to Rs. 2,50,000 Rs. 5000 + 20% of the income exceeding Rs. 1,50,000
Above Rs. 2,50,000 Rs. 25,000 + 30% of the income exceeding Rs. 2,50,000
void display()
{
System.out.println("Pan Number \t\t Name \t\t Tax Income \t\t Tax");
System.out.println( pan +"\t\t "+ name +"\t\t "+ ti +"\t\t "+ t);
}
import java.util.*;
class PQ26
{
String name;
double fine;
int price,day;
void accept()
{
Scanner sc = new Scanner(System.in);
System.out.println("\fEnter the Name ,Price of Book, and day");
name = sc.nextLine();
price =sc.nextInt();
day= sc.nextInt();
}
void calculate()
{
if(day<= 7)
fine = 0.25*day;
if(day>=8 && day <= 15)
fine = 0.40*day;
if(day>=16 && day <= 30)
fine = 0.60*day;
if (day >30 )
fine = 0.80*day;
}
void display()
{
System.out.println("Name \t\t price of book \t\t day \t\t fine ");
System.out.println( name +"\t\t\t "+ price +"\t\t "+ day +"\t\t"+ (float)fine);
}
import java.util.*;
class Mobike
{
String name;
int bno, phno, days, charge;
void input()
{
Scanner sc = new Scanner(System.in);
System.out.println("\fEnter the Name");
name = sc.nextLine();
System.out.println("Enter the Bike Number");
bno =sc.nextInt();
System.out.println("Enter the Phone Number");
phno =sc.nextInt();
System.out.println("Enter the Number of days the bike is taken ut on rent");
days =sc.nextInt();
}
void calculate()
{
if(days<=5)
charge = 500*days;
if(days> 5 && days <= 10)
charge = 400*days;
if(days> 10)
charge = 200*days;
}
void display()
{
System.out.println("Bike No \t Phone number \t\t Name \t\t No.of days \t\t Charge ");
System.out.println( bno+"\t\t "+ phno +"\t\t "+ name +"\t\t"+ days +"\t\t"+ charge);
}
void display()
{
p=wd.length();
for(i=0;i<p;i++)
{
chr=wd.charAt(i);
if(chr =='a'||chr == 'e'||chr == 'i'|chr == 'o'||chr =='u')
break;
}
st1 = wd.substring(i,p);
st2 = wd.substring(0,i);
System.out.println("The piglatin form of word :");
System.out.println(st1+st2+"ay");
}
public static void main()
{
Scanner sc = new Scanner (System.in);
String str;
System.out.println("Enter the number");
str = sc.next();
Piglatin obj = new Piglatin();
obj.input(str);
obj.display();
}
}
Write the main method to create an object of the class and call the above member methods.
// program for Movies magic
import java.util.*;
class MovieMagic
{
int year;
String title;
float rating;
Scanner in = new Scanner(System.in);
MovieMagic()
{
year = 0;
rating = 0.0f;
}
void accept ()
{
System.out.println("Enter year, title and rating");
year = in.nextInt();
title = in.next();
rating = in.nextFloat();
}
void display()
{
if(rating <= 2.0)
System.out.println(title +"\t"+"Flop");
if (rating >=2.1 && rating <=3.4)
System.out.println(title +"\t"+"Semi - Hit");
if (rating >=3.5 && rating <=4.5)
System.out.println(title +"\t"+"Hit");
if (rating >=4.6 && rating <=5.0)
System.out.println(title +"\t"+"Super - Hit");
}
public static void main(String args[])
{
MovieMagic obj = new MovieMagic();
obj.accept();
obj.display();
}
}