Naitik_Singh_9C_Computer-Project (1)
Naitik_Singh_9C_Computer-Project (1)
ON
“JAVA PROGRAMMING”
GRADE – 9
SESSION - (2024-2025)
Q1. Write a program to read the number n via the Scanner class and print the
Tribonacci series: 0, 0, 1, 1, 2, 4, 7, 13, 24, 44, 81 ...and so on.
Hint: The Tribonacci series is a generalization of the Fibonacci sequence
where each term is the sum of the three preceding terms.
Answer:-
/*
* @author=xyz
*/
import java.util.Scanner;
class tribonacci
int n,a,b,c,d;
n=sc.nextInt();
a=0;
b=0;
c=1;
d=a+b+c;
System.out.println(a);
System.out.println(b);
System.out.println(c);
System.out.println(d);
for(int i=1;i<n;i++)
a=b;
b=c;
c=d;
d=a+b+c;
Sample input : 3
Sample output : 0
2
4
Answer -
/*
* @author=xyz
*/
class CorrectAns
int ma,mb;
}
Sno. Name Data type Scope Purpose
1. ma int local Number of correct answers by A
2. mb int local Number of correct answers by B
Q3. The normal temperature of the human body is 98.6°F. Write a program to
convert the temperature into degree Celsius and display the output.
Hint: c / 5 = f - 32 / 9
Answer -
/*
* @author=xyz
* @purpose=fahrenheit to Celsius
*/
class Temperature
float c,f;
f=(float)98.6;
Q4. The angles of a quadrilateral are in the ratio 3:4:5:6. Write a program to
find and display all its angles. [Hint: The sum of angles of a quadrilateral =
360°]
Answer -
/*
* @author=xyz
*/
import java.util.Scanner;
class angles
{
int a,b,c,d;
float x;
a=3;
b=4;
c=5;
d=6;
x=(float)(360/(a+b+c+d));
System.out.println("angle 1 = "+(a*x));
System.out.println("angle 2 = "+(b*x));
System.out.println("angle 3 = "+(c*x));
System.out.println("angle 4 = "+(d*x));
angle 2 = 80.0
angle 3 = 100.0
angle 4 = 120.0
Q5. The time period of a Simple Pendulum is given by the formula: T = 2π√(l/g)
Answer -
/*
* @author=xyz
*/
import java.util.Scanner;
class TimePeriod
double l,g;
double t;
g=9.8;
System.out.println("enter length");
t=(2*(Math.PI))*Math.sqrt(l/g);
System.out.println("time period = "+t);
Input-10
Output- time period = 6.346975625940523
Allowance/Deduction Rate
Dearness Allowance (DA) 30% of Basic Pay
House Rent Allowance (HRA) 15% of Basic Pay
Provident Fund (PF) 12.5% of Basic Pay
Answer -
/*
* @author=xyz
*/
import java.util.Scanner;
class employee
{
int bp;
float da,hra,pf,np,gp;
bp=sc.nextInt();
da=(float)bp*30/100;
hra=(float)bp*15/100;
pf=(float)(bp*12.5/100);
gp=bp+da+hra;
np=gp-pf;
System.out.println(“Gross pay+”+gp);
Input-10000
Output- Gross pay = 14500.0
Net pay = 13250.0
Answer -
/*
* @author=xyz
*/
import java.util.Scanner;
class gst
int p;
double d,gst,amt;
d=p-(p*10/100);
gst=d*6/100;
amt=(d+gst);
Input-10000
Output- The amount to pay is 9540.0
Q8. Write a program to calculate the value of Pi with the help of the following
series: Pi = (4/1) - (4/3) + (4/5) - (4/7) + (4/9) - (4/11) + (4/13) - (4/15) ...
Hint: Use while loop with 100000 iterations.
/*
* @author=xyz
*/
import java.util.*;
class pi
for(int j=0;j<i;j++)
if (j%2==0)
pi=pi+(4/d);
else
pi=pi-(4/d);
d=d+2;
System.out.println(pi);
}
Output - 3.1415826535897198
Q9. Mr. Lokesh invests certain sum at 5% per annum compound interest for
three years. Write a program in Java to calculate:
(a) the interest for the first year
(b) the interest for the second year
(c) the amount after three years.
Take sum as an input from the user.
Sample Input: Principal = ₹5000, Rate =10%, Time = 3 yrs
Sample Output: Interest for the first year: ₹500
Interest for the second year: ₹550
Interest for the third year: ₹605
Answer -
/*
* @author=xyz
*/
import java.util.Scanner;
class intrest
{
public static void main()
int t;
double p,r,amt,i1,i2,i3;
p=obj.nextDouble();
r=obj.nextDouble();
t=obj.nextInt();
amt=p;
i1=(p*r)/100;
amt=amt+i1;
i2=(amt*r)/100;
amt=amt+i2;
i3=(amt*r)/100;
amt=amt+i3;
Answer -
/*
* @author=xyz
*/
class shares
int s=(ad*100)/(nv*dp);
Q11.A certain amount is invested at the rate of 10% per annum for 3 years.
Find the difference between Compound Interest (CI) and Simple Interest (SI).
Write a program to take amount as an input.
Hint: SI = (P * R * T) /100
A = P * (1(R/100))T
CI = A - P
/*
* @author=xyz
*/
import java.util.*;
class IntrestDifference
double p,SI,a,CI,diff,t,r;
t=3;//time
r=10;//rate of intrest
a=p*Math.pow((1+(r/100)),t);//Finding amount
}
Sno. Name Data Type Scope Purpose
1. p double local Principle amount
2. SI double local Calculate Simple interest
3. a double local amount
4. CI double local Claculate Compound interest
5. diff double local Difference between CI and SI
6. t double local Time
7. r double local Rate of interest
Input- 1000
Q12.A shopkeeper sells two calculators for the same price. He earns 20%
profit on one and suffers a loss of 20% on the other. Write a program to find
his total cost price of the calculators by taking selling price as input.
Hint: CP = (SP / (1 + (profit / 100))) (when profit)
CP = (SP / (1 - (loss / 100))) (when loss)
/*
* @ author-xyz
*/
class CostPrice {
double sp,CPpro,CPloss,tCP;
Scanner sc = new Scanner(System.in);
sp= sc.nextDouble();
CPpro=sp/(1+(pp/100));
CPloss=sp/(1-(lp/100));
/*
* @author-xyz
*/
class NumberEvaluation
double num=sc.nextDouble();
Answer-
/*
* @author-xyz
*/
import java.util.Scanner;
class Radius {
Q15.Write a program to input three numbers and check whether they are
equal or not. If they are unequal numbers then display the greatest among
them otherwise, display the message 'All the numbers are equal'.
Sample Input: 34, 87, 61
Sample Output: Greatest number: 87
Sample Input: 81, 81, 81
Sample Output: All the numbers are equal.
Answer -
/*
* @author=xyz
* @purpose=caompare 3 numbers
*/
import java.util.*;
class compare
int num1,num2,num3;
num2=sc.nextInt();
num3=sc.nextInt();
if ((num1==num2)&&(num2==num3))
else if((num1>num2)&&(num1>num3))
else if((num1<num2)&&(num1>num3))
else if((num1>num2)&&(num1<num3))
}
}
/*
* @author-xyz
*/
import java.util.Scanner;
class MathProgram
System.out.print("Enter. ");
int ch=sc.nextInt();
switch (ch)
case 1:
int a=0,b=1;
System.out.print(a+""+b+"");
System.out.print(a+""+b+"");
b=a+b;
a=b-a;
System.out.println();
break;
case 2:
int sum=0;
while(num!=0)
sum=sum+(num%10);
num/=10;
System.out.println("Sum = "+sum);
break;
default:
System.out.println("Invalid");
Answer-
/*
* @author-xyz
*/
class diamondPattern
int n = 5;
System.out.print(" ");
}
for ( int j = 1 ;j<=(2*i-1);j++)
System.out.print("*");
System.out.println();
System.out.print(" ");
System.out.print("*");
System.out.println();
}
Sno. Name Data type Scope Purpose
1. i int local For loop
2. j int local For loop
Q18.An Electricity Board charges for electricity per month from their
consumers according to the units consumed. The tariff is given below:
Answer-
/*
* @author-xyz
*/
import java.util.Scanner;
class Bill
String name=sc.nextLine();
int u=sc.nextInt();
double m=0;
if (m<=200)
m=u*3.80;
m= (200*3.80)+((u-200)*4.40);
else if ((u<=400)&&(u>300))
m=(200*3.80)+(100*4.40)+((m-300)*5.10);
}
else if(u>400)
m=(200*3.80)+(100*4.40)+(100*5.10)+((u-400)*5.80);
Answer-
/*
* @author-xyz
*/
import java.util.Scanner;
class TriPattern
if (c==1) {
System.out.print(i+"");
System.out.println();
else if (c==2){
System.out.print(i+"");
System.out.println();
else
{
System.out.println("Invalid choice");
Answer-
/*
*@author-xyz
*/
import java.util.Scanner;
class TwistedPrime {
int i;
if (num <= 1) {
return;
if (number % i == 0)
}
}
// Reverse number
int r= 0;
while (Rnum != 0)
r = r* 10 + Rnum % 10;
Rnum =Rnum/10;
if (reversed <= 1)
return;
if (reversed % i == 0)
{
System.out.println(number + " is prime, but " + reversed + " is not
prime.");
return;
Conclusion –
My project experience with BlueJ provided insight into programming
and software development. The interface and educational nature of
BlueJ made it a perfect environment to learn and experiment in. Its
simplicity made it easy to navigate, and the visual representation of
classes and objects helped me grasp object-oriented programming
concepts very effectively. I was able to create and manipulate
objects directly, reinforcing my understanding of class interactions.