Uploaded by koustav

final

advertisement
St Pauls Academy
Name:- KOUSTAV SARKAR
Class:- IX
Section:-E
Subject:- COMPUTER
Session:- 2023-2024
Introduction
Welcome to the forefront of technological
innovation with our cutting-edge computer project,
an endeavor poised to redefine the landscape of
computing. This ambitious project represents a
fusion of vision and expertise, aimed at pushing the
boundaries of what is possible in the digital realm.
At its core, this project is a testament to our
commitment to harnessing the power of
computational intelligence for the betterment of
society. With a focus on innovation, efficiency, and
user-centric design, we aspire to create a paradigm
shift in the way we interact with and utilize
computing resources.
Collaboration lies at the heart of our endeavor,
bringing together a diverse team of experts across
disciplines to tackle complex problems. Together, let
us pioneer the next chapter in the evolution of
computing.
Write a program in java to input any number and check it is prime or not.
class prime_1
{
public void disp (int n)
{
int c=0;
for (int i=1;i<=n;i++)
{
if (n%i==0)
c++;
}
if (c==2)
System.out.println (n+" is a PRIME NUMBER ");
else
System.out.println (n+" is a Composite Number");
}
}
Input :- 7
Name
Data type
Function
n
int
To take input from user
c
int
As a counter
i
int
As a loop variable
Write a program in java to input any number and print it in reverse order.
class REVERSE_2
{
public void res (int n)
{
int rev=0;int a=n;
while (n>0)
{
int r=n%10;
rev=rev*10+r;
n=n/10;
}
System.out.println("Reverse Order of " +a+" is = "+rev);
}
}
Input:-129
VARIABLE
DATA TYPE
DESCRIPTION
rev
int
To store the rev number
a
int
For storing the value of the
input number.
r
int
To store its last digit.
Write a program in java to input any number and check it is prime
palindrome of not.
class primepalindrome_3
{
public void disp (int n)
{
if(prime(n)&& palndrome(n))
System.out.println(n+" is a Prime-Palindrome Number");
else
System.out.println(n+" is not a Prime-Palindrome Number");
}
boolean prime (int n)
{
boolean f=false;int c=0;
for (int i=1;i<=n;i++)
{
if(n%i==0)
c++;
}
if (c==2)
f=true;
return f;
}
boolean palndrome (int n)
{
int rev=0;boolean p=false;int a=n;
while (a>0)
{
int r=a%10;
rev=rev*10+r;
a=a/10;
}
if (rev==n)
p=true;
return p;
}
}
Input:-11
VARIABLE
DATA TYPE
DESCRIPTION
F
Boolean
For returning true or false
C
int
As a counter
I
int
For running the loop.
rev
int
To store the reverse value
of n.
A
int
To store n
R
int
To cut digits
p
boolean
For returning the value.
Write a program in java to input any limit and print all the twin primes upto
that limit. Example (3,5), (5,7), (11,13)….]
class Twinprime
{
public void disp (int n)
{
long j=0;
for (int i=1;i<=n;i++)
{
j=i+2;
if (prime (i) && prime (j))
System.out.print (i+","+j+" ");
}
}
boolean prime (int i)
{
int c=0;boolean f=false;
for (int k=1;k<=i;k++)
{
if(i%k==0)
c++;
}
if (c==2)
f=true;
return f;
}
boolean prime (long j)
{
int c=0;boolean p=false;
for (int k=1;k<=j;k++)
{
if (j%k==0)
c++;
}
if (c==2)
p=true;
return p;
}}
Name
Data type
Function
n
Int
To take input from user
j
Long
To generate second
number
i
Int
Used as a counter
c
int
Used as a counter
k
Int
As a loop no
f
Int
To return true or false
Input:-15
Write a program to input any number and check it Krishnamurthy number
or not
class krishnamurti
{
static void main (int a)
{
int h=a;int u=0;
while (a>0)
{
int e=a%10;
a/=10;int y=1;
for (int i=1;i<=e;i++)
{
y*=i;
}
u=u+y;
}
if (u==h)
System.out.println ("krishna murti");
else
System.out.println ("not Krishnamurti");
}
}
Sample input :145
Name
Data type
Description
a
int
To take input from user
h
Int
To store value of a
u
Int
To form a number
e
Int
To cut digit
y
Int
For factorial
i
int
As a loop variable
Write a program in java to find the sum of the following series depending
on user choice 1 or 2.
a. S=1/4+1/8+1/12… up to n terms.
b. S=1/1! +2/2! +3/3! ... Up to n terms.
Where! Stands for factorial of the number and factorial value of a number
is the product of all the integer from 1 to that number e.g. 5! =1*2*3*4*5.
Use switch statement
class idk
{
static void main (int a,int n)
{
switch(a)
{
case 1:
double s=0;
for (double i=1;i<=n;i++)
{
s=s+(1/(4*i));
} System.out.println(s);
break;
case 2:
double y=1,j=0;
for (double i=1;i<=n;i++)
{
y=y*i;
j=j+(i/y);
}
System.out.println(j);
break;
}
}
}
Input:- a=1;n=3;
Name
Type
Description
a
int
To take users choice
n
int
To take input from
users
s
double
To store sum
i
double
Used as a loop
variable
y
double
For factorial
j
double
To store sum
Write a program in java to calculate the sum of all the prime number
between the ranges of 1 to 100.
class primepalin
{
void main ()
{
int s=0;
for (int i=1;i<=100;i++)
{
if (prime(i)==true)
s+=i;
}
System.out.println(s);
}
boolean prime(int a)
{
int c=0;
for (int i=1;i<=a;i++)
{
if (a%i==0)
c++;
}
if(c==2)
return true;
else
return false;
}
}
Name
Type
Description
s
int
To store sum
i
int
As a loop variable
a
int
To accept value
c
int
As a counter
Write a program in java to calculate and print the sum of odd number and
the sum of even numbers for the first n natural numbers.
class natural
{
static void main (int n)
{
int u=0,k=0;
for (int i=1;i<=n;i++)
{
if (i%2==0)
k=k+i;
else
u=u+i;
}
System.out.println ("Sum of all even=" +k+"Sum of all odd="+u);
}
}
Input:-33
Name
Data type
Description
n
int
To take input from user
u
Int
To store odd no sum
k
Int
To store even no sum
i
Int
As a loop variable
A dress showroom has announced the following discounts on the purchase
of items, based on the total cost of the items purchased:
Total Cost
Discounts (in percentage)
Less than 2000
5%
2001 to 5000
25%
5001 to 10000
35%
Above 10000
50%
Write a program in java to input total cost and to compute and display the
amount to be paid by the customer after availing discounts.
class percentage
{
static void main (int a)
{
if (a<=2000)
System.out.println ("the paid amount is ="+(a-a/100*5));
else if (a>2000 && a<=5000)
System.out.println ("the paid amount is ="+(a-a/100*25));
else if (a>5000 && a<=10000)
System.out.println ("the paid amount is ="+(a-a/100*35));
else
System.out.println ("the paid amount is ="+(a-a/100*50));
}
}
Input :- 16000
Output:-
Name
a
Data type
Int
Function
To take input from user
Write a menu driven program to find the sum of the following series
depending on the user’s choice.
1. S=1/2+1/4+1/6…. Up to n terms.
2. S=x2 /2!+x5 /5!+x8 /8!... up to n terms.
import java.util.*;
class series_10
{
public void disp ()
{
Scanner sc =new Scanner (System.in);
double s=0.0;int n=0;int ch;
System.out.println ("1:1/2+1/4+1/6+1/8... nth term");
System.out.println ("2:x^2/2!+x^5/5!+x^8/8!...nth term");
System.out.println ("Enter your choice :");
ch =sc.nextInt();
System.out.println ("Enter the value of 'n' : " );
n=sc.nextInt();
switch (ch)
{
case 1:
for (int i=2;i<=n;i+=2)
{
s=s+1/i;
}
System.out.println ("Sum of series = "+s);
break;
case 2:
int x;
System.out.println ("Enter the value of 'x' : ");
x=sc.nextInt();
for (int i=2;i<=n;i+=3)
{
int f=1;
for (int j=1;j<=i;j++)
{
f=f*j;
}
s=s+Math.pow( x,i)/f;
}
System.out.println ("Sum of series = "+s);
break;
default:System.out.println ("Wrong Choice");
}
}}
VARIABLE
DATA TYPE
DESCRIPTION
S
double
To calculate the sum of the
series.
n
int
A limit for the series;
ch
int
To take choice from the user.
f
int
To calculate and store the
factorial.
j
Int
As a loop variable
i
int
As a loop variable
Write a menu driven program using the overloaded function ‘area’ to either
calculate the area of a circle or the area of a rectangle or the area of a
square depending on the user’s choice.
import java.util.*;
class area_11
{
public void disp ()
{
Scanner sc=new Scanner (System.in);
int ch;
System.out.println ("Available Choices -");
System.out.println ("1.Area of Rectangle");
System.out.println ("2.Area of Square");
System.out.println ("3.Area of Circle");
System.out.println ("Enter your choice : ");
ch=sc.nextInt();
switch(ch)
{
case 1:int l=0;int b=0;
System.out.println ("Enter the Length of the Rectangle : ");
l=sc.nextInt();
System.out.println ("Enter the Breadth of the Rectangle : ");
b=sc.nextInt();
Area ( l , b);
break;
case 2:int s=0;
System.out.println ("Enter the Side of the Square : ");
s=sc.nextInt();
Area (s);
Break;
case 3:double r=0.0;
System.out.println ("Enter the Radius of Circle : ");
r=sc.nextInt() ; Area (r);
break;
default:System.out.println ("Wrong choice");
}
}
void Area (int l,int b)
{
double ar=l*b;
System.out.println ("Area of Rectangle = "+ar);
}
void Area (int s)
{
double ar=s*s;
System.out.println ("Area of Square = "+ar);
}
void Area(double r)
{
double ar=3.14*r*r;
System.out.println ("Area of Circle = "+ar);
}}
VARIABLE
DATA TYPE
DESCRIPTION
ch
int
To take the choice from the
user.
l
int
To take the length of the
rectangle.
b
int
To take the breadth of the
rectangle.
s
int
To take the side of the square.
r
double
To take input the radius of the
circle.
ar
double
To calculate the area of the
given shapes.
Write a program in java to accept a number and find the minimum prime
digit of the number
class minprime_12
{
public void disp (int n)
{
int sm=9;int a=n;
while (n>0)
{
int r=n%10;
if (r==2)
sm=Math.min(sm,r);
else
if (r==3)
sm=Math.min(sm,r);
else
if (r==5)
sm=Math.min(sm,r);
else
if (r==7)
sm=Math.min(sm,r);
n=n/10;
}
System.out.println ("Minnimum Prime digit of Number "+a+" is =
"+sm); }}
VARIABLE
DATA TYPE
DESCRIPTION
a
int
To copy the value of n.
sm
int
To find the smallest prime digit.
r
int
To cut the last digit of the
number.
Write a program in java to accept a number and print it in ascending order
of the digits.
class ascending_13
{
public void disp (int n)
{
int a=n;
for (int i=1;i<=9;i++)
{
a=n;
while (a>0)
{
int r=a%10;
a=a/10;
if (r==i)
System.out.print (r+" ");
}}}}
Variable
DATA TYPE
DESCRIPTION
a
int
To copy the value of n.
i
Int
To run the loop.
r
int
To cut the last digit of n.
Define a class called with the following specifications:
Class name: Eshop
Member variables
String name: name of the item purchased
double price: Price of the item purchased
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.
import java.util.*;
class Eshop_14
{
String name=" ";
double price=0.0;
double disc=0.0;
double amt=0.0;
void accept ()
{
Scanner sc = new Scanner(System.in);
System.out.println ("Enter the name of the item purchased : ");
name =sc.nextLine();
System.out.println ("Enter the Cost of the item purchased : ");
price=sc.nextDouble();
}
void calculate ()
{
if (price <1000)
amt=price -disc;
else
if (price >=1000 && price <=25000)
{ disc=price*0.05;
amt=price-disc;
}
else
if (price >25000 && price <=57000)
{
disc=price*0.075;
amt=price-disc;
}
else
if (price >57000 && price<=100000)
{
disc=price*0.10;
amt =price-disc;
}
else
if (price >100000)
{
disc=price*0.15;
amt=price-disc;
}
}
void display ()
{
System.out.println ("Discount got on purchase = "+disc);
System.out.println ("Final amount after Discount = "+amt);
}
void main (String [] args)
{
Eshop_14 obj=new Eshop_14();
obj.accept();
obj.calculate();
obj.display();
}
}
VARIABLE
DATA TYPE
DESCRIPTION
name
string
To store the name of the item
purchase.
price
double
To store the price of the item.
Disc
double
To calculate the discount on
purchase.
amt
double
To calculate the final amount after
discount
Write a program in java to input number of days for school library and
calculate the fine amount as pre the given condition
No of days.
First 10 days
Next 15 days
Next 5 days
Above 30 days
Fine (Rupees)
Nil
2.50/day
3.80/day
4.50/day
import java.util.*;
class library_15
{
public void disp ()
{
Scanner sc= new Scanner (System.in);
int days=0;double fine=0.0;
System.out.println("Enter the Number Of days : ");
days=sc.nextInt();
if (days <10)
System.out.println ("NO FINE NEEDED " );
else
if (days >10 && days <=25)
{
fine=days*2.5;
}
else
if (days >25 && days <=30)
{
fine=days*3.8;
}
else
if (days >30)
{
fine=days*6.5;
} System.out.println ("FINE = rs "+fine); }}
VARIABLE
DATA TYPE
DESCRIPTION
DAYS
int
To take input the number of
days .
fine
double
To calculate the fine .
Write a program in java to input any unit consumed by an electricity
customer and calculate the billing amount as per following condition:Unit
First 50
Next 100
Next 150
Above 300
price/ unit (rupees)
2.20/unit
3.30/ unit
5.50/ unit
6.50/ unit
import java.util.*;
class Electricitybill_16
{
void main ()
{
Scanner sc =new Scanner (System.in);
double price=0.0;int unit=0;
System.out.println ("Enter the Unit of electricity consumed : ");
unit=sc.nextInt();
if (unit <=50)
price=unit*2.2;
else
if(unit >50 && unit<=150)
price=unit*3.3;
else
if (unit >150 && unit <=300)
price =unit*5.5;
else
if (unit >300)
price=unit*6.5;
System.out.println ("Totap Price for Elictic consumptiom = rs "+price);
}
VARIABLE
DATA TYPE
DESCRIPTION
price
double
To calculate the price of unit
consumption.
unit
int
To store the unit of electricity
consumed.
Define a class to accept a 3 digit number and check whether it is a duck
number or not.
Note: A number is a duck number if it has zero in it
Example1: Input: 2083 Output: Invalid
Example 2: Input: 103 Output: Duck number
class Duck_17
{
public void disp (int n)
{
int a=n;
while (n>0)
{
int r=n%10;
if (r==0)
{
System.out.println (a+" is a Duck Number");
break;
}
n=n/10;
}
}
VARIABLE
DATA TYPE
DESCRIPTION
r
int
To perform the modulus operator
on n.
a
int
To srore the value of n.
An automorphic number is the number which is contained in the last digit(s)
of its square. Write a program to input a number and check whether the
number is an automorphic or not.
class Automorphic_18
{
public void disp (int n)
{
int a=n;int nd=0;double rmd=0;
while(a>0)
{
int r=a%10;
nd++;
a=a/10;
}
rmd=n%Math.pow(10,nd-1);
if (rmd*rmd==n)
System.out.println (n+" is a Automorphic Number");
else
System.out.println (n+" is not a Automorphic Number ");
}}
VARIABLE
DATA TYPE
DESCRIPTION
a
int
To store the value of n.
nd
int
To count the number of digits.
rmd
double
To store and calculate the
reminder.
r
int
To perform the modulus operator
on a.
Write a program to input any number through constructor and check it is
Armstrong number or not
class Amstrong_19
{
public void disp (int n)
{
Amstrong (n);
}
void Amstrong (int n)
{
int s=0;int cb=0;int a=n;
while (a>0)
{
int r=a%10;
cb=r*r*r;
s=s+cb;
a/=10;
}
if (s==n)
System.out.println (n+" is a Amstrong Number");
else
System.out.println (n+" is not a Amstrong Number");
}}
VARIABLE
DATA TYPE
DESCRIPTION
s
int
To calculate the sum of cubes of
digit.
cb
int
To calculate the cubes of the
digits.
a
int
To copy the value of n.
r
Int
To calculate the modulus
operator on n.
A special two digit number is such that when the sum of its digits is added
to the product of its digits the result is equal to the original two digit number.
class special_20
{
public void disp (int n)
{
int s,sd=0;int a=n;int pd=1;
while (a>0)
{
int r=a%10;
sd+=r;
pd*=r;
a/=10;
}
s=pd+sd;
if(n==s)
System.out.println (n+" is a Special Number ");
else
System.out.println (n+" is not a Special Number ");
}
}
VARIABLE
DATA TYPE
DESRIPTION
s
int
To calculate the sum of the
multiplication and addition of
the digits
sd
int
To add the digits.
pd
int
To multiply the digits.
r
int
To cut the last digit of n.
Write a program to input a number and check and print whether it is a
Pronic number or not. Pronic number is the number which is the product of
two consecutive integers.
class pronic_21
{
public void disp (int n)
{
int i=1;
while (i<=n)
{
if (i*(i+1)==n)
System.out.println (n+" is a Pronic Number ");
i++; } } }
VARIABLE
DATA TYPE
DESCRIPTION
I
int
For running the loop.
n
Int
To take input from user
Write a program to input a number and find the smallest digit
class smallest_22
{
public void disp (int n)
{
int sm=9;int a=n;
while(n>0)
{
int r=n%10;
sm=Math.min(sm,r);
n=n/10;
}
System.out.println ("Smallest Digit “+a+” = "+sm);
}
}
VARIABLE
DATA TYPE
DESCRIPTION
A
INT
To copy the value of n .
sm
int
To store the smallest digit
r
int
To cut the last digit of n.
Using switch statement, write a menu driven program:
a) To check and display whether a number input by the user is composite
number or not. ( A number is said to be composite if it has one or more
factors excluding one and the number itself. Example 4,6,8,9..
b) To find the smallest digit of an integer that is input. Sample input: 6524
Sample output: Smallest digit is 2. For an incorrect choice, an appropriate
error message should be displayed
import java.util.*;
class menudrvn_23
{
public void disp ()
{
Scanner sc =new Scanner (System.in);
int ch=0;
System.out.println ("1.Weather a Number is Composite or nor : ");
System.out.println ("2.The Smallest digit of a Number : ");
ch=sc.nextInt();
switch (ch)
{
case 1:int n=0;int c=0;
System.out.println ("Enter a Number : ");
n=sc.nextInt();
for (int i=1;i<=n;i++)
{
if (n%i==0)
c++;
}
if (c!=2)
System.out.println (n+" is a Composite Number");
else
System.out.println (n+" is a Prime Number");
break;
case 2:int sm=9;
System.out.println ("Enter the number : ");
n=sc.nextInt();
int a=n;
while (n>0)
{
int r=n%10;
sm=Math.min(sm,r);
n/=10;
}
System.out.println ("Smallest digit of "+ a+" is = "+sm
break;
default :System.out.println ("Wrong Choice");
}
}}
);
VARIABLE
DATA TYPE
DESCRIPTION
a
int
To copy the value of n.
rev
int
To calculate the reverse
value of n.
r
int
To cut the last digit of n.
Write a program to input any number through Scanner class and check
whether it is palindrome or not.
import java.util.*;
class palndrome
{
public void disp ()
{
Scanner sc =new Scanner (System.in);
int rev=0;
System.out.println ("Enter a Number : ");
int n=sc.nextInt();
int a=n;
while (a>0)
{
int r=a%10;
rev=rev*10+r;
a=a/10;
}
if (rev==n)
System.out.println (n+" is a PALINDROME NUMBER");
else
System.out.println (n+" is not a PALINDROME NUMBER");
}}
VARIABLE
DATA TYPE
DESCRIPTION
a
int
To copy the value of n.
rev
int
To calculate the reverse value
of n.
r
int
To cut the last digit of n.
Define a class to overload the method display as follows: void display(): To
print the following format using nested loop
1
12
123
1234
12345
void display(int n): To print the square root of each digit of the given
number
class method_25
{
void display ()
{
for (int i=1;i<=5;i++)
{
for (int j=1;j<=i;j++)
{
System.out.print (j);
}
System.out.println();
}
}
void display (int n)
{
double sq=0.0;
while (n>0)
{
int r=n%10;
sq=Math.sqrt(r);
System.out.println (sq);
n=n/10;}}
VARIABLE
DATA TYPE
DESCRIPTION
i
int
For running the loop.
j
int
For running the loop.
sq
double
To find and store the square root
of digit.
r
int
To cut the digits of the number.
Conclusion
In conclusion, our computer project embodies a
vision for a future where innovation and user-centric
design harmoniously coexist. Through collaborative
efforts and a commitment to pushing technological
boundaries, we have crafted a transformative
computing experience. As we reach the culmination
of this endeavor, we anticipate a ripple effect in the
technological landscape. With a focus on efficiency,
accessibility, and cutting-edge solutions, our project
not only addresses present challenges but also sets a
trajectory for continued advancements. Together, we
usher in a new era of computing, where possibilities
are limitless, and the digital realm becomes a
seamless extension of human potential.
Download