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

Project Format (20 Programs)

Uploaded by

rudhrank.reghu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views23 pages

Project Format (20 Programs)

Uploaded by

rudhrank.reghu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 23

Hiranandani Trust School

Internal Assessment

Name: Rudhrank Reghu A


Grade: X
Roll No: 20

Academic Year 2024-25


Acknowledgement
I would like to express my sincere gratitude
to my Computer teacher, Mrs. Nirali Mehta,
for her valuable guidance, encouragement,
and continuous support throughout the
completion of this project.
I am deeply thankful for the insightful
suggestions and constant motivation, which
enabled me to complete this work
successfully within the given time.
I would also like to extend my heartfelt
thanks to my parents and friends for their
encouragement, cooperation, and assistance
during the course of this project.
Name: Rudhrank Reghu A
Index
Sr.no Name of the Program Date Sign
1 Electricity bill 04-09-2025

2 CoPrime 04-09-2025

3 Successor Product 04-09-2025

4 Pronic Number 04-09-2025

5 Pattern 04-09-2025

6 Bus Fare 04-09-2025

7 Happy Number 04-09-2025

8 Volume of cube, sphere and cuboid 04-09-2025

9 Area of geometrical figures 04-09-2025

10 String Pattern 04-09-2025

11 Choice Overload 04-09-2025

12 Triangle 04-09-2025
Q1) Calculate electricity bill by using method
// To calculate electricity bill by using method

public class Electricity double cal(int u)


double c=0.0D;
if(u<=100)
c=(u*1.25);
if(u> 100) && (u<=200))
c=((100*1.25)+(u-100)*1.50);
if(u>200)
c=((100*1.25)+(100*1.50)+(u-200)*1.80);
return (C);
public static void main(String argsll)
int prev, pres,un,cn; double amt=0.0D;
String name;
Scanner in=new Scanner(System.in);
Electricity ob=new Electricity;
System.out.println("Enter consumer's name");
name=in.nextLine();
System.out.println("Enter consumer's number");
cn=in.nextInt();
System.out.println("Enter previous reading");
prev=in.nextInt();
System.out.println ("Enter present reading");
pres=in.nextInt();
un=pres-prev;

amt=ob.cal(un);
System.out.println("ConsumerNo.\t Name\t\t Unit
Consumed\t Amount ");
System.out.println(cnt"\t\t"+name+"/t/t"+unt"\t"+amt);
}
}
Q2)
 import java.util.Scanner;
public class CoPrime
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);

System.out.print("Enter first number: ");


int a = sc.nextInt();
System.out.print("Enter second number: ");
int b = sc.nextInt();

int hcf = 1; // default

// find HCF by checking from 1 to min(a, b)


for (int i = 1; i <= Math.min(a, b); i++) {
if (a % i == 0 && b % i == 0) {
hcf = i;
}
}
if (hcf == 1) {
System.out.println("They are co-prime.");
} else {
System.out.println("They are not co-prime.");
}
}
}

Scanner sc = new Scanner(System.in);

System.out.print("Enter a number: ");


int n = sc.nextInt();

int prod = 1;
boolean foundEven = false;

Q3) SuccessorProduct
 import java.util.Scanner;

public class SuccessorProduct


{
public static void main(String args[])
{
while (n > 0) {
int digit = n % 10;
if (digit % 2 == 0) { // check even digit
prod = prod * (digit + 1); // multiply by
successor
foundEven = true;
}
n = n / 10;
}
if (foundEven) {
System.out.println("Product = " + prod);
} else {
System.out.println("No even digits.");
}
}
Q4)
 import java.util.Scanner;

public class PronicNumber


{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);

System.out.print("Enter a number: ");


int n = sc.nextInt();

boolean isPronic = false;

// check product of consecutive integers


for (int i = 1; i <= n; i++) {
if (i * (i + 1) == n) {
isPronic = true;
break;
}
}

if (isPronic) {
System.out.println(n + " is a Pronic Number.");
} else {
System.out.println(n + " is NOT a Pronic
Number.");
}
}
}
Q5)
 import java.util.*;

public class Pattern22


{
public static void main(String args[])
{
Scanner sc = new Scanner (System.in);
System.out.println("Enter number of rows");
int n = sc.nextInt();
int g = 1;
for(int i = 1;i<=n;i++)
{
for(int k = 5;k>=i;k--)
{
System.out.print(" ");
}
for(int j = 1;j<=i;j++)
{
System.out.print(g + " ");
g++;
}
System.out.println();
}
}
}

OUTPUT:-
1
23
456
7 8 9 10
11 12 13 14 15
Q6)Make a bus fare calculator with a user-controlled loop
 import java.util.Scanner;

class BusFare

public static void main(String[] args)

Scanner sc = new Scanner(System.in);

int passengers = 0;

int totalFare = 0;

char more;

do {

System.out.print("Enter distance to travel (in km): ");

int d = sc.nextInt();

if (d <= 0) {

System.out.println("Invalid distance. Try again.");

} else {

int fare;

if (d <= 5) {

fare = 80;

} else if (d <= 15) {

fare = 80 + (d - 5) * 10;

} else {

fare = 80 + 10 * 10 + (d - 15) * 8; // 80 + 100 + rest

}
System.out.println("Fare for this passenger: ₹" + fare);

passengers++;

totalFare += fare;

System.out.print("More passengers? (Y/N): ");

more = sc.next().trim().toUpperCase().charAt(0);

} while (more == 'Y');

System.out.println("\n--- Journey Summary ---");

System.out.println("Number of passengers: " + passengers);

System.out.println("Total fare collected: ₹" + totalFare);

if (passengers > 0) {

double mean = (double) totalFare / passengers;

System.out.printf("Mean fare per passenger: ₹%.2f%n", mean);

} else {

System.out.println("Mean fare per passenger: ₹0.00");

sc.close();

Q7) To find the volume of cube, sphere and cuboid using function overloading

 // To check Happy number

import java.util.*;

class Happy_Number
{

public static void main(String args[])

Scanner in = new Scanner(System.in);

int num, sum = 0, d;

System.out.println("Enter a number");

num = in.nextInt();

int m = num;

do

num = sum = 0;

do

d = m % 10;

sum = sum + d * d;

m = m / 10;

while (m > 0);

m = sum;

while (sum > 9);

if (sum == 1)

System.out.println("Happy Number");

else

System.out.println("Not a Happy Number");


}

}
Q8) Find the volume of cube, sphere and cuboid using function overloading

 // To find the volume of cube, sphere and cuboid using function


overloading

import java.util.*;

public class Compute

double pi = 22.0 / 7.0;

void volume(float a)

double v = a * a * a;

System.out.println("The volume of a cube = " + v);

void volume(float r, float h)

double v = (4.0 / 3.0) * pi * r * r * r;

System.out.println("The volume of a sphere = " + v);

void volume(float l, float b, float h)

double v = l * b * h;

System.out.println("The volume of a cuboid = " + v);

public static void main(String args[])


{

Scanner in = new Scanner(System.in);

float a, r, l, b, h;

System.out.println("Enter the value of side of a cube, radius of sphere,


sides of a cuboid:");

a = in.nextFloat();

r = in.nextFloat();

l = in.nextFloat();

b = in.nextFloat();

h = in.nextFloat();

Compute ob = new Compute();

ob.volume(a);

ob.volume(r, h);

ob.volume(l, b, h);

}
Q9) calculate area of geometrical figures by using overloading
class Overload:
// calculate area of geometrical figures by using overloading class
Overload
public double area(double a, double b, double c) {
double ar;
double s = (a + b + c) / 2;
ar = Math.sqrt(s * (s - a) * (s - b) * (s - c));
return ar;
}

public double area(int a, int b, int height) {


double ar;
ar = 1.0 / 2 * height * (a + b);
return ar;
}

public double area(double diagonal1, double diagonal2) {


double ar;
ar = 1.0 / 2 * (diagonal1 * diagonal2);
return ar;
}
Q10)
Write a program to accept a word (say, BLUEJ) and display the pattern:
BLUEJ
BLUE
BLU
BLB
Answer:
import java.util.*;
public class StringPattern //Class declaration
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
System.out.print("Enter a word: "); //Taking input from user
String word = in.nextLine(); int len = word.length();

for (int i = len - 1; i >= 0; i--) //loop for displaying the pattern
{
for (int j = 0; j <= i; j++)
{
char ch = word.charAt(j);
System.out.print(ch);
}
System.out.println();
}
} }
Q11. Write a program in Java to store the numbers in a 4*4 matrix in a Double
Dimensional Array. Find the transpose of the matrix by using an assignment
statement. The transpose of a matrix is obtained when we change the row elements
into column and column elements into rows.
Answer:
import java.util.*;
public class Transpose //Class declaration
{
public static void main(String args[])
{

Scanner sc=new Scanner(System.in);


System.out.println("Entre number of rows "); //Taking input from user
int n1=sc.nextInt();
System.out.println("Entre number of columns"); int n2=sc.nextInt();
int arr [][] = new int[n1][n2];
for( int i=0;i<n1;i++) //Taking input of elements in matrix

{
for(int j=0;j<n2;j++)
{
System.out.println("Enter number");
arr[i][j]=sc.nextInt();
}
}
System.out.println("The numbers of matrix are:");
for( int i=0;i<n1;i++) //displaying the original matrix

{
for(int j=0;j<n2;j++)
{
System.out.print(arr[i][j]+" ");
}
System.out.println();
}
for(int i=0;i<n1;i++) //Displaying transpose of matrix
{
for(int j=0;j<n2;j++)
{
System.out.println("The numbers of transpose matrix are:");
System.out.print(arr[i][j]+" ");
}
System.out.println();
}

}}

11. Design a class to overload a function num_calc() as follows:


1. void num_calc(int mini, char ch) with one integer argument and one
character argument, computes the square of integer argument if choice ch is
's' otherwise finds its cube.
2. void num_calc (int a, int b, char ch) with two integer arguments and
one character argument. It computes the product of integer arguments if ch
is 'p' else adds the integers.
3. void num_calc (String s1, String s2) with two string arguments, which
prints whether the strings are equal or not.

Answer:
import java.util.*;
public class ChoiceOverload //Class declaration
{
void num_calc(int m, char ch)
{
if (ch == 's') //Checking the need of user for square or cube
{
int sq = m * m;
System.out.println("Square = " + sq );
} else
{
int cube = m * m * m;
System.out.println("Cube = " + cube);
}
}

void num_calc(int a, int b, char ch)


{
if (ch == 'p') //Checking if user wants product or sum
{
long prod = a * b;
System.out.println("Product = " + prod );
} else
{
long sum = a + b;
System.out.println("Sum = " + sum);
}
}

void num_calc(String s1, String s2)


{
if(s1.equals(s2)) //Checking if the strings are equal
System.out.println("Strings are equal"); else
System.out.println("Strings are not equal") } }
Q12. Triangle

Import java.io.*;

public double area(double a, double b, double c) {

double ar;

double s = (a + b + c) / 2;
ar = Math.sqrt(s * (s - a) * (s - b) * (s - c));

return ar;

public double area(int a, int b, int height) {

double ar;

ar = 1.0 / 2 * height * (a + b);

return ar;

public double area(double diagonal1, double diagonal2) {

double ar;

ar = 1.0 / 2 * (diagonal1 * diagonal2);

return ar;

You might also like