0% found this document useful (0 votes)
427 views44 pages

Class 9 Comp Practical File 15 Programs 21-22 (2) Vijay Sir

Uploaded by

Ansh Barman
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)
427 views44 pages

Class 9 Comp Practical File 15 Programs 21-22 (2) Vijay Sir

Uploaded by

Ansh Barman
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/ 44

Page 1 of 44

Session: 2023-24
COMPUTER
PRACTICAL FILE
SUBMITTED TO: SUBMITTED BY:
Mr. Vijay Baretha Ansh Barman
Class : IX-A
Roll No: 13
Page 2 of 44

ACKNOWLEDGEMENT

I would like to thank my Computer Application


teacher Mr. Vijay Baretha for his able guidance
and support in completing my project.

I would also like to extend my gratitude to the


Principal Rev. Fr. Alwyn Madtha for providing
me with all the facilities that were required.

Date:03-09-23 Name: Ansh Barman


Class: IX-A
Page 3 of 44

CERTIFICATE

This is to certify that “Ansh Barman”of class IX-A


of “St. Francis School, Lucknow has completed his
Computer practical file under my guidance. He has taken
proper care and shown utmostsincerity in completing his
Computer project.

I certify that this file is upto my expectations and as


per guidelines issued by submitted by ICSE.

Mr. Vijay Baretha


(Computer Teacher) Signature
Page 4 of 44

CONTENTS
No PROGRAM Page No.
To print the perimeter and area of a square using assignment
1 statement.
To convert temperature from Fahrenheit to Celsius using
2 assignment statement.
To swap two numbers using third variable using assignment
3 statement.
Toconvert minutes to hours using Input through parameters.
4
To calculate Simple Interest using Input through parameters.
5
To swap two numbers without using the third variable using input
6 through Scanner class.
To input two numbers and find larger and smaller numbers using
7 Mathematical methods input through Scanner class.
To determine if an entered number is a Buzz number or not.
8
To display the Fibonacci series between 1 and 100.
9
Menu driven program in java for calculating area of different
10 shapes and asks the user to calculate the area for that shape.
WAP to input a number and print all its factors.
11
WAP to input a number and check for prime number.
12
WAP to input two number and print its HCF (GCD).
13
WAP to input a number and for perfect number.
14
WAP to print the factorial of the number.
15
Page 5 of 44

PROGRAM 1
Write a program in java to print the perimeter and area of a
square using assignment statement.

PROGRAM
public class area_perimeter
{

public static void main(String args[])


{

int s, peri, ar; s=60;


peri = 4*s; ar = s*s;
System.out.println("Side of the square is: " +s +" cm");
System.out.println("Perimeter of the square is: " +peri +" cm");
System.out.println("Area of the square is: " +ar +" square cm");
}
}
Page 6 of 44

VARIABLE DESCRIPTION

No. Name Type Description


1 s int Input value
2. peri int To calculate and store the value of perimeter of
square
3. ar int To calculate and store the value of area of square
Page 7 of 44

OUTPUT
Page 8 of 44

PROGRAM 2
Write a program in java to convert temperature from
Fahrenheit to Celsius using assignment statement.

PROGRAM
public class Temp
{

public static void main(String[] args)


{

double fahren; fahren=75;


System.out.println("Temperature in Fahrenheit is: " + fahren +" degree Fahrenheit");
double cels =(( 5 *(fahren - 32.0)) / 9.0);
System.out.println(fahren + " degree Fahrenheit is equal to " + cels + " in Celsius");
}

}
Page 9 of 44

VARIABLE DESCRIPTION

No. Name Type Description


1 fahren double To calculate and store the value of fahrenheit
2 cels double To calculate and store the value of celsius

OUTPUT
Page 10 of 44

z PROGRAM 3
Write a program in java to swap two numbers using third variable
using assignment statement.

PROGRAM
public class Swap

public static void main(String[] args)

{
int n1 = 20, n2 = 45;
System.out.println("--Before swap--");
System.out.println("First number = " + n1);
System.out.println("Second number = " + n2); int temperature = n1;
n1 = n2;
n2 = temperature;
System.out.println("--After swap--");
System.out.println("First number = " + n1);
System.out.println("Second number = " + n2);
}
}
Page 11 of 44

VARIABLE DESCRIPTION

No. Name Data Type Description


1 n1 int Initial value of First number.
2. n2 int Initial value of Second number.
3. Temperature int Third variable used for Swapping.
Page 12 of 44

OUTPUT
Page 13 of 44

PROGRAM 4
Write a program in java to convert minutes to hours using
Input through parameters.

PROGRAM

public class Mins_to_Hrs


{

public static void main(int totalMins)


{

int hrs, mins; hrs = totalMins/60;


mins = totalMins%60;

System.out.println("Entered minutes: " + totalMins);


System.out.println("There are " + hrs + " hours and " + mins
+ " minutes in " + totalMins + " minutes");
}

}
Page 14 of 44

VARIABLE DESCRIPTION

No. Name Type Description


1 totalMins int Input value of total number of minutes by the user.
2. hrs int To calculate and store the value in hours
3. mins int To calculate and store the value in minutes

OUTPUT
Page 15 of 44

PROGRAM 5
Write a program in java to calculate Simple Interest using
Input through parameters.

PROGRAM

public class Simple_Int


{
public static void main (int p,int r,int t)
{

float SI;
System.out.println("Principal is \u20B9 " + p);
System.out.println("Rate of Interest is = " + r + "% per annum");
System.out.println("Time is = " + t + " years");
SI=((p*r*t)/100);

System.out.println("Simple Interest is \u20B9 " + SI);


}
}
Page 16 of 44

VARIABLE DESCRIPTION

No. Name Type Description


1 p int Input value of Principal in Rs
2. r int Input value of Rate of Interest
3. t int Input value of Time in Years
4. SI float To calculate and store the value in si

OUTPUT
Page 17 of 44
Page 18 of 44

PROGRAM 6
Write a program in java to swap two numbers without using
the third variable using input through Scanner class.

PROGRAM

import java.util.Scanner;
public class Swap_without_third_variable
{

public static void main(String args [ ])


{

Scanner obj = new Scanner(System.in);


System.out.println("Enter the value of First number: ");
int firstno = obj.nextInt();
System.out.println("Enter the value of Second number: ");
int secondno = obj.nextInt();
System.out.println("Before Swapping the numbers: "+"First number is
“ + firstno +" and "+"Second number is "+secondno);
firstno = firstno + secondno; secondno = firstno - secondno; firstno =
firstno - secondno;
System.out.println("After swapping the numbers: "+"First number is "+firstno
+" and "+"Second number is " +secondno);
obj.close();

}
}
Page 19 of 44

VARIABLE DESCRIPTION

No. Name Data Description


Type
1 firstno int Input value of First number.
2. secondno int Input value of Second number.
Page 20 of 44

OUTPUT
Page 21 of 44

PROGRAM 7
Write a program in java to input two numbers and find
larger and smaller numbers using Mathematical methods
input through Scanner class.

PROGRAM
import java.util.Scanner;
public class Max_Min
{
public static void main(String args[ ])
{
Scanner obj = new Scanner(System.in);
System.out.println("Enter the value of first number: ");
double firstno = obj.nextDouble( );
System.out.println("Enter the value of second number: ");
double secondno = obj.nextDouble( );
System.out.println("Larger number is : " + Math.max(firstno,
secondno));
System.out.println("Smaller number is : " + Math.min(firstno,
secondno));
obj.close( );
}
Page 22 of 44

VARIABLE DESCRIPTION

No. Name Data Description


Type
1 firstnum double Input value of First number.
2. secondnum double Input value of Second number.
Page 23 of 44

OUTPUT
Page 24 of 44

PROGRAM 8
Write a program in java to determine if an entered number
is a Buzz number or not.

PROGRAM
import java.util.Scanner;
public class Buzz_Num
{
public static void main(String args[ ])
{
Scanner obj = new Scanner(System.in);
System.out.println("Enter a number: ");
int number = obj.nextInt( );
if ((number %10==7) || (number % 7==0))
System.out.println(number + " is a Buzz
number");else
System.out.println(number + " is not a Buzz
number");obj.close( );

}
}
Page 25 of 44

VARIABLE DESCRIPTION

No. Name Data Description


Type
1 number int Input value of number to be checked.
Page 26 of 44

OUTPUT
Page 27 of 44

PROGRAM 9
Write a program in java to display the Fibonacci series
between 1 and 100.

PROGRAM
public class Fibonacci
{
public static void main(String args [])
{
int no1 = 0, no2= 1, sum= 0; System.out.print("Fibonacci
series between 1 and 100 is: "); System.out.print(no1 + " ");
System.out.print(no2 + " ");
sum = no1 + no2;
while (sum <= 100)

{
System.out.print(sum + " ");
no1=no2;
no2=sum;
sum = no1 + no2;
}
}
}
Page 28 of 44

VARIABLE DESCRIPTION

No. Name Data Description


Type
1 no1 int First value of number for starting series
2 no2 int Second value of number for starting series
3 sum int Adding values of preceding numbers
Page 29 of 44

OUTPUT
Page 30 of 44

PROGRAM 10
Write a Menu driven program in java for calculating area of
different shapes and asks the user to calculate the area for
that shape.

PROGRAM

import java.util.Scanner;

// the name of our class its public

public class MenuDriven

{
public static void main (String[] args)

float a,b,ar = 0;
Page 31 of 44

char choice;
//Declare input as scanner
Scanner input = new Scanner(System.in);
//Take inputs
System.out.println("Enter c for circle.");
System.out.println("Enter s for square.");
System.out.println("Enter r for rectangle.");
System.out.println("Enter t for triangle.");
String s = input.next();
choice = s.charAt(0);
//add a switch statement
switch(choice)
{
case 'c':
System.out.println("Enter radius:");
a = input.nextFloat();
ar = 3.14f*a*a;
break;
case 's':
System.out.println("Enter side:");
a = input.nextFloat();
ar = a*a;
break;
case 'r':
Page 32 of 44

System.out.println("Enter length and breadth:");

a = input.nextFloat();
b = input.nextFloat();ar =
a*b;
break; case 't':
System.out.println("Enter base and height:");a
=input.nextFloat();
b =input.nextFloat();ar =
0.5f*a*b; break;
default:
System.out.println("Error");
}
System.out.println("Area = "+ar);
}
}
}
Page 33 of 44

VARIABLE DESCRIPTION

No. Name Data Description


Type
1 a float Input value length for rectangle /side
forsquare/radius for circle/ base for
triangle
2 b float Input value breadth for rectangle/height
fortriangle
3 ar float To calculate and store the value of area
4. char choice Reading the choice of user based on area of
shape to be calculated

OUTPUT
Page 34 of 44
Page 35 of 44

PROGRAM 11
WAP to input a number and print all its factors.

import java.util.*;
class All_factors
{
public static void main(String agrs[] )
{
Scanner sc= new Scanner (System.in);
int n,m;
System.out.println("Enter the number ");
m=sc.nextInt();
for(n=1;n<=m;n++)
{
if(m%n==0)
System.out.println(n)
;
}
}
}
Page 36 of 44

Output :

Variable description table

Name Type Purpose


m Int To input the value
from the user.
n Int Loop index variable
Page 37 of 44

PROGRAM 12
WAP to input a number and check for prime number.

import java.util.*;
class
prime_number
{
public static void main(String agrs[] )
{
Scanner sc= new Scanner (System.in);
int n,m,o=0;
System.out.println("Enter the number ");
m=sc.nextInt();
for(n=1;n<=m;n++)
{
if(m%n==
0)o++;
}
if(o==2)
System.out.println("prime number");
else
System.out.println(" not a prime number");
}
}
Page 38 of 44

Output :

Variable description table

Name Type Purpose


m Int To input the value
from the user.
n Int Loop index variable

o Int Counter variable


Page 39 of 44

PROGRAM 13
WAP to input two number and print its HCF (GCD).
import java.util.*;
class GCD
{
public static void main(String agrs[] )
{
Scanner sc= new Scanner (System.in);
int n,m,l,min,hcf=0;
System.out.println("Enter the two number ");
m=sc.nextInt();
l=sc.nextInt();
min=Math.min(m,l);
for(n=1;n<=min;n++)
{
if(m%n==0 &&
l%n==0)hcf=n;
}
System.out.println("HCF="+hcf);
}
}
Page 40 of 44

Output :

Variable description table

Name Type Purpose


m Int To input the value
from the user.
l Int To input the value
from the user.
n Int Loop index variable

hcf Int To store HCF


Page 41 of 44

PROGRAM 14
WAP to input a number and for perfect number.
Eg: n=6 it is a perfect number

import java.util.*;
class perfectnum
{
public static void main(String agrs[] )
{
Scanner sc= new Scanner (System.in);
int x,y,z=0;
System.out.println("Enter the number ");
y=sc.nextInt();
for(x=1;x<y;x++)
{
if(y%x==0
)z=z+x;
}
if(z==y)
System.out.println("perfect number");
else
System.out.println(" not a perfect number");
}
}
Page 42 of 44

Output :

Variable description table

Name Type Purpose


y Int To input the value
from the user.
x Int Loop index variable

z Int To store sum of the


factors
Page 43 of 44

PROGRAM 15
WAP to print the factorial of the number.
Eg : 5!=120

import java.util.*;
class
factorial_of_num
{
public static void main(String agrs[] )
{
Scanner sc= new Scanner (System.in);
int n,m,fact=1;
System.out.println("Enter the number ");
m=sc.nextInt();
for(n=1;n<=m;n++)
{
fact=fact*n;
}

System.out.println("The factorial of the number is="+fact);


}
}
Page 44 of 44

Output :

Variable description table

Name Type Purpose


m Int To input the value
from the user.
n Int Loop index variable

fact Int To store factorial of


the number

You might also like