0% found this document useful (0 votes)
52 views23 pages

Solution of Computer Practical Records For Class X - Part 1

The document contains a series of Java programming exercises for Class X students at Holy Family School, Bhagalpur, covering various topics such as calculating remainders, income tax, areas of geometric shapes, salary allowances, number properties, and patterns. Each exercise includes a problem statement and a corresponding Java code solution. The exercises aim to enhance students' programming skills and understanding of mathematical concepts.
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)
52 views23 pages

Solution of Computer Practical Records For Class X - Part 1

The document contains a series of Java programming exercises for Class X students at Holy Family School, Bhagalpur, covering various topics such as calculating remainders, income tax, areas of geometric shapes, salary allowances, number properties, and patterns. Each exercise includes a problem statement and a corresponding Java code solution. The exercises aim to enhance students' programming skills and understanding of mathematical concepts.
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/ 23

HOLY FAMILY SCHOOL, BHAGALPUR

Computer Practical Records for Class X (2025 – 2026)

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

Write a program in java to compute the income tax to be paid by him.

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);
}
}

3. Write a menu driven program to calculate


1. Area of a Circle = 𝜋r2
2. Area of a Square = side * side
3. Area of a rectangle = length * breadth
Enter ‘c’ to calculate area of circle, ‘s’ to calculate area of square and ‘r’ to calculate area of rectangle.
// Program to display the area of circle, square, and rectangle according to user choice
import java.util.*;
class PQ3
{
public static void main()
{
Scanner sc = new Scanner (System.in);
char ch;
System.out.println("****** Main Menu ******");
System.out.println("'c' for Area of a Circle");
System.out.println("'s' for Area of a Square");
System.out.println("'r' for Area of a Rectangle");
System.out.print("Enter c,s,r for choice : ");
ch=sc.next().charAt(0);
switch(ch)
{
case 'c': double ar;int r;ar =0.0;
System.out.println("Enter the radius of Circle");
r = sc.nextInt();
ar = 3.14*r*r;
System.out.println("Area of Circle = " +ar);
break;
case 's': int ar1,s;ar1 =0;
System.out.println("Enter the side of Square");
s = sc.nextInt();
ar1 = s*s;
System.out.println("Area of Square = " +ar1);
break;
case 'r': int ar2,l,b;ar =0;
System.out.println("Enter the length and breadth of Rectangle");
l = sc.nextInt();
b = sc.nextInt();
ar2 = l*b;
System.out.println("Area of Circle = " +ar2);
break;
default : System.out.println("Invalid Choice");
}
}
}
4. A company announces revised Dearness Allowance (DA) and Special Allowance (SA) for their
employees as per the tariff given below.
Basic Dearness Allowance (DA) Special Allowance (SA)
Upto Rs. 10,000 10% 5%
Rs. 10,001 – Rs. 20,000 12% 8%
Rs. 20,001 – Rs. 30,000 15% 10%
Rs. 30.001 and above 20% 12%
Write a program to accept Basic Salary (BS) of an employee. Calculate and display gross salary.
Gross salary = basic + DA + SA
Print the information in the given format
Basic DA SA Gross Salary
XXX XXX XXX XXX

// 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

// To calculate the GCD of two numbers


import java.util.*;
class PQ6
{
public static void main()
{
Scanner sc = new Scanner(System.in);
int a ,b,i,p,gcd=0;
System.out.println ("Enter two numbers");
a= sc.nextInt();
b = sc.nextInt();
p=a*b;
for ( i= 1; i<=p; i++)
{
if (a%i == 0 && b%i==0)
gcd = i;
}
System.out.println("The GCD of two numbers ="+gcd);
}
}
7. Write a program to accept 10 different numbers. Display the greatest and the smallest number from a set
of numbers entered by the user.
//To display the greatest and the smallest numbers
import java.util.*;
class PQ7
{
public static void main()
{
Scanner sc = new Scanner(System.in);
int i,n,min =0,max=0;
System.out.println ("Enter the 1 number");
n= sc.nextInt();
max = n; min = n;
for ( i= 2; i<= 10; i++)
{
System.out.println("Enter the "+i+" number");
n =sc.nextInt();
if (n< min)
min = n;
if (n > max)
max = n;
}
System.out.println("The greatest number =" +max);
System.out.println("The smallest number =" +min);
}
}
8. Write a program in Java to display the first 15 numbers of the Fibonacci series.
0,1,1,2,3,5,8, ……..

// To display first ten numbers of the Fibonacci series


import java.util.*;
class PQ8
{
public static void main()
{
int a,b,c,i;a=0;b=1;c=0;
System.out.println ("The Fibonacci series is :");
System.out.print (a+ "," + b);
for ( i= 3; i<= 15; i++)
{
c = a+b;
System.out.print(","+c);
a=b;
b=c;
}
}
}
9. Write a program to find the sum of series, taking the values of ‘a’ and ‘n’ from the user.
𝑎 𝑎 𝑎 𝑎
Sum = 2 + 3 + 4 + ⋯ + 𝑛

// To find the sum of series


import java.util.*;
class PQ9
{
public static void main()
{
Scanner sc = new Scanner(System.in);
int a,i,n;
double s =0.0;
System.out.println ("Enter the value of a and n");
a= sc.nextInt();
n = sc.nextInt();
for ( i= 1; i<n; i++)
{
s = s+(double)a/(i+1);
}
System.out.print("Sum of the series ="+s);
}
}
10. Write a program to display first n row of given pattern
1
22
333
4444
… and so on

// To display the Pattern


import java.util.*;
class PQ10
{
public static void main()
{
Scanner sc = new Scanner(System.in);
int r,c,n;
System.out.println ("Enter the value of n");
n = sc.nextInt();
for ( r= 1; r<=n; r++)
{
for (c = 1;c<=r;c++)
{
System.out.print(r);
}
System.out.println();
}
}
}
11. Write a program to display the given pattern
@@@@@
@ @
@ @
@ @
@@@@@

// To display the Pattern


import java.util.*;
class PQ11
{
public static void main()
{
int r,c;
for ( r=1; r<=5; r++)
{
for (c = 1;c<=5;c++)
{
if (r==1 || r ==5 || c ==1 || c==5)
System.out.print('@');
else
System.out.print(' ');
}
System.out.println();
}
}
}
12. Write a menu driven class to accept a number from the user and check whether it is a Pronic Number or a
Automorphic number.
(i) Pronic Number – ( A number is a Pronic number, if the number is a product of two consecutive
number. Eg-12(3x4))
(ii) Automorphic Number – ( A natural number whose square ends in the same digits as the number
itself.
Ex- (6)2 = 36
(25)2 = 625
// Program to display the Pronic number or Automorphic number by user choice
import java.util.*;
class PQ12
{
public static void main()
{
Scanner sc = new Scanner (System.in);
int choice;
System.out.println("****** Main Menu ******");
System.out.println(" 1. Pronic Number ");
System.out.println(" 2. Automorphic Number ");
choice=sc.nextInt();
switch(choice)
{
case 1: int num, pro;
System.out.println("Enter a number");
num = sc.nextInt();
pro = (int) Math.sqrt(num);
if (pro * (pro+1) == num)
System.out.println(“ The given number is a Pronic Number”);
else
System.out.println(“ The given number is not a Pronic Number”);
break;

case 2: int num, c=0,aut;


System.out.println("Enter a number");
num = sc.nextInt();
for (i=num; i>0; i=i/10)
{
c++;
}
aut = (num*num) / (int) Math.pow(10,c);
if (aut == num)
System.out.println(“ The given number is a Automorphic Number”);
else
System.out.println(“ The given number is not a Automorphic Number”);
break;

default : System.out.println(“ INVALID CHOICE”);

}
}

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

// To display the frequency of each digit present in the number


import java.util.*;
class PQ13
{
public static void main()
{
Scanner sc = new Scanner(System.in);
int n,c,a,i,num=0;c=0;
System.out.println ("Enter the number");
n= sc.nextInt();
num =n;
for(i = 0; i<10; i++)
{
n = num;
while (n>0)
{
a =n%10;
if(a==i)
c++;
n=n/10;
}
if(c>1)
System.out.println("The frequency of "+i+ " = "+c);
c=0;
}
}
}
14. Write a program to display the sum of the series.
𝑎3 𝑎5 𝑎7
𝑆=𝑎− + − + ⋯ 𝑡𝑜 𝑛 𝑡𝑒𝑟𝑚𝑠
5 9 13

// To display the sum of the series


import java.util.*;
class PQ14
{
public static void main()
{
Scanner sc = new Scanner(System.in);
int n,p,a,c,i;c=1;p=1;
double s=0.0;
System.out.println ("Enter the value of a and n");
a = sc.nextInt();
n= sc.nextInt();
for(i = 0; i<=n; i++)
{
if (i%2==0)
s=s-Math.pow(a,p)/c;
else
s=s+Math.pow(a,p)/c;
p=p+2;
c=c+4;
}
System.out.println("sum "+s);
}
}

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");
}
}

17. Write a program to find the value of y where


𝑛!
𝑦=
r! ∗ (n − r)!
// To display the given equation
import java.util.*;
class PQ17
{
public static long fact(int n)
{// function to return factorial value
int i;long f=1;
for(i=1;i<=n;i++)
{
f=f*i;
}
return f;
}
// main function to invoke the factorial
public static void main()
{
Scanner sc = new Scanner(System.in);
int n,r,d;long f1,f2,f3;double y=0.0;
System.out.println ("Enter the value of n and r");
n= sc.nextInt();
r= sc.nextInt();
d=n-r;
f1 = fact(n);
f2 = fact(r);
f3 = fact(d);
y= (double)f1/(f2*f3);
System.out.println("y ="+y);
}
}

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);
}
}
}

21. Design a class to overload a function polygon() as follows.


(i) void polygon ( int n, char ch) : with only integer and one character type argument to draw a filled
square of side n using the character stored in ch.
(ii) void polygon (int a, int y) : with two integer arguments that draws a filled rectangle of length x
and breadthy, using the symbol ‘@’.
(iii) void polygon () : with no argument that draws a filled triangle shown below
Example
(i) Input value of n = 2, ch = ‘o’ Output oo
oo
(ii) Input value of x = 2, y = 5 Output @@@@@
@@@@@
(iii) Output: *
**
***

// program for overloading


class PQ21
{
void polygon(int n, char ch)
{
int r,c;
for (r=1;r<=n;r++)
{
for(c=1;c<=n;c++)
{
System.out.print(ch);
}
System.out.println();
}
}
void polygon(int x,int y)
{
int r,c;
for (r=1;r<=x;r++)
{
for(c=1;c<=y;c++)
{
System.out.print('@');
}
System.out.println();
}
}
void polygon()
{
int r,c;
for (r=1;r<=5;r++)
{
for(c=1;c<=r;c++)
{
System.out.print('*');
}
System.out.println();
}
}
}

22. Design a class to overload a function series ()as follows :


(i) double series (double n) with one double argument and returns the sum of the series.
1 1 1 1 1
𝑆𝑢𝑚 = + + + +⋯
1 2 3 4 n
(ii) double series (double a, double n ) with two double arguments and returns the sum of the series.

1 4 7 10
𝑆𝑢𝑚 = + + + +⋯ , to n terms
𝑎2 𝑎5 a8 a11

// program for overloading


class PQ22
{
double series(double n)
{
int i;double s=0.0;
for (i=1;i<=n;i++)
{
s=s+1.0/i;
}
return s;
}

double series(double a, double n)


{
int i,x;x=1;
double s =0.0;
for (i=1;i<=n;i++)
{
s=s+(double)x/Math.pow(a,(x+1));
x=x+3;
}
return s;
}
}

23. Write a class program with the following specifications:


Class name : Rectangle
Data members / Instance variables: int length, int breadth , int area, int perimeter, double diag
Member functions:
void inputdata() : to accept and breadth of the rectangle.
void calculate(): to find area, perimeter and diagonal of the rectangle
void outputdata() : to print the results.
Write a main method to create object of a class and call the above member method.
// Program based on class as a user defined
import java.util.*;
class PQ23
{
int len,bre,area,peri;
double diag;
void accept()
{
Scanner sc = new Scanner (System.in);
System.out.println("Enter the length and breadth");
len = sc.nextInt();
bre = sc.nextInt();
}
void calculate()
{
area= len*bre;
peri=2*(len+bre);
diag=Math.sqrt(len*len + bre*bre);
}
void output()
{
System.out.println("Area of the Rectangle"+area);
System.out.println("Perimeter of the Rectangle"+peri);
System.out.println("Diagonal of the Rectangle"+diag);
}
public static void main()
{
PQ23 obj = new PQ23();
obj.accept();
obj.calculate();
obj.output();
}
}

24. Define a class Salary described as below :


Data Members : Name , Address, Phone, Subject Specialization, Monthly salary, Income Tax
Member methods : (i) To accept the details of a teacher including , the monthly salary
(ii) To display the details of the teacher.
(iii) To compute the annual Income tax as 5% of the annual salary above Rs.
1,75,000.
Write a main method to create object of a class and call the above member method.
import java.util.*;
class PQ24
{
String name,Add,S_Sp;
double m_sal,IT;
long T_no;
void accept()
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter the Name , Address, Subject Specification, Monthly Salary, Phone
number");
name = sc.nextLine();
Add = sc.nextLine();
S_Sp = sc.nextLine();
m_sal=sc.nextDouble();
T_no = sc.nextLong();
}
void display()
{
System.out.println("Name : "+name);
System.out.println("Address : "+Add);
System.out.println("Subject Specification: "+S_Sp);
System.out.println("Monthly Salary : "+m_sal);
System.out.println("Phone Number : "+T_no);
System.out.println("Income Tax to pay = "+IT);
}
void calculate()
{
double AS = m_sal*12;
if(AS >175000)
IT = 5.0/100*(AS- 175000);
else
IT = 0.0;
}
public static void main()
{
PQ24 obj = new PQ24();
obj.accept();
obj.calculate();
obj.display();
}
}

25. Define a class employee having the following description :


Data members int pan to store personal account number
String name to store name
double taxincome to store annual taxable income
double tax to store tax that is calculated
Member functions:
void input () : Store the pan number, name, taxable income
void cal() : Calculate tax of an employee
void display () : Output details of an employee
Write a program to compute the tax according to the given conditions and display the output as per given
format.
Total Annual taxable Income Tax Rate

Up to Rs. 1,00,000 No tax

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

Output : Pan Number Name Tax-Income Tax


---------------- -------- --------------- -----
import java.util.*;
class PQ25
{
String name;
double ti,t;
int pan;
void accept()
{
Scanner sc = new Scanner (System.in);
System.out.println("Enter the Name ,Tax Income and Pan Number");
name = sc.nextLine();
ti=sc.nextDouble();
pan = sc.nextInt();
}
void calculate()
{
if(ti <=100000)
t = 0.0;
if(ti>100000 && ti <= 150000)
t = 10.0/100*(ti-1000000);
if(ti>150000 && ti <= 250000)
t = 5000 + 20.0/100 *(ti - 150000);
if (ti >250000 )
t = 25000+ 30.0/100*(ti - 250000);
}

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);
}

public static void main()


{
PQ25 obj = new PQ25();
obj.accept();
obj.calculate();
obj.display();
}
}
26. Define a class Library having the following description :
Data members : String name : to store name of the book
int price : to store the printed price of the book
int day : to enter the number of days for which fine is to be paid
double fine : to store the fine to be paid
Write a program to compute the fine according to the given conditions and display the fine to be paid
Days Fine

First seven days 25 paise per day

Eight to fifteen days 40 paise per day

Sixteen to thirty days 60 paise per day


More than thirty days 80 paise per day

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);
}

public static void main()


{
PQ26 obj = new PQ26();
obj.accept();
obj.calculate();
obj.display();
}
}
27. Define a class called ‘Mobike’ with the following specifications:
Instant variables/ data members :
int bno : To store the bike number
int phno : To store the phone number of the customer
String name : To store name of the customer
int days : To store the number of days the bike is taken out 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 :
For first five days : Rs. 500 per day
For 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:
Bike No Phone No. Name No. of days Charge
xxxxxx xxxxxxxxx xxxxx xxxxxxxxx xxxxxx

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);
}

public static void main()


{
Mobike obj = new Mobike();
obj.input();
obj.calculate();
obj.display();
}
}

28. Write a class program with the following specifications:


Class name : Prime
Data members/Instant variables : int n
Member Methods :
Prime () : default constructor to initialize n
void input (int x) : to assign n with x
void display() : to check whether the number is prime or not
//To check whether the number is prime or not
import java.util.*;
class Prime
{
int n;
Prime()
{
n=0;
}
void input(int x)
{
n=x;
}
void display()
{
int i,c=0;
for(i=1;i<=n;i++)
{
if (n%i==0)
c=c+1;
}
if (c==2)
System.out.println(n+" is a prime number");
else
System.out.println(n+ "is not a prime number");
}
public static void main()
{
Scanner sc = new Scanner (System.in);
int num;
System.out.println("Enter the number");
num = sc.nextInt();
Prime obj = new Prime();
obj.input(num);
obj.display();
}
}
29. Write a class program with the following specifications:
Class name : Piglatin
Data Members/ Instant variables : String wd
Member Methods :
Piglatin() : constructor to initialize the String wd
void input(String wd) : to accept a word.
void display () : Convert the word in Piglatin form and display it.
Sample word : trouble
Piglatin form : oubletray

//To display a word in Piglatin


import java.util.*;
class Piglatin
{
int i,p;
String wd,st1,st2;
char chr;
Piglatin()
{
wd = " ";
}
void input(String word)
{
wd = word;
wd = wd.toLowerCase();
}

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();
}
}

30. Define a class named movieMagic with the following description :


Instant variables/ data members :
int year : to store the year of release of the movie
String title : to store the title of the movie.
float rating : to store the popularity rating of the movie
(minimum rating = 0.0 and maximum rating = 5.0)
Member method :
(i) movieMagic() : Default constructor to initialize numeric data members to 0 and the String data
members to “ ”
(ii) void accept () : to input and store year, title and rating.
(iii) Void display () : to display the title of the movie and a message based on the rating as per
the table below.

Rating Message to be displayed


0.0 to 2.0 Flop
2.1 to 3.4 Semi - Hit
3.5 to 4.5 Hit
4.6 to 5.0 Super Hit

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();
}
}

You might also like