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

Hiranandani Trust School Internal Assessment

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)
6 views23 pages

Hiranandani Trust School Internal Assessment

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

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
[Link] 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([Link]);
Electricity ob=new Electricity;
[Link]("Enter consumer's name");
name=[Link]();
[Link]("Enter consumer's number");
cn=[Link]();
[Link]("Enter previous reading");
prev=[Link]();
[Link] ("Enter present reading");
pres=[Link]();
un=pres-prev;

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

[Link]("Enter first number: ");


int a = [Link]();
[Link]("Enter second number: ");
int b = [Link]();

int hcf = 1; // default

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


for (int i = 1; i <= [Link](a, b); i++) {
if (a % i == 0 && b % i == 0) {
hcf = i;
}
}
if (hcf == 1) {
[Link]("They are co-prime.");
} else {
[Link]("They are not co-prime.");
}
}
}

Scanner sc = new Scanner([Link]);

[Link]("Enter a number: ");


int n = [Link]();

int prod = 1;
boolean foundEven = false;

Q3) SuccessorProduct
 import [Link];

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) {
[Link]("Product = " + prod);
} else {
[Link]("No even digits.");
}
}
Q4)
 import [Link];

public class PronicNumber


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

[Link]("Enter a number: ");


int n = [Link]();

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) {
[Link](n + " is a Pronic Number.");
} else {
[Link](n + " is NOT a Pronic
Number.");
}
}
}
Q5)
 import [Link].*;

public class Pattern22


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

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 [Link];

class BusFare

public static void main(String[] args)

Scanner sc = new Scanner([Link]);

int passengers = 0;

int totalFare = 0;

char more;

do {

[Link]("Enter distance to travel (in km): ");

int d = [Link]();

if (d <= 0) {

[Link]("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

}
[Link]("Fare for this passenger: ₹" + fare);

passengers++;

totalFare += fare;

[Link]("More passengers? (Y/N): ");

more = [Link]().trim().toUpperCase().charAt(0);

} while (more == 'Y');

[Link]("\n--- Journey Summary ---");

[Link]("Number of passengers: " + passengers);

[Link]("Total fare collected: ₹" + totalFare);

if (passengers > 0) {

double mean = (double) totalFare / passengers;

[Link]("Mean fare per passenger: ₹%.2f%n", mean);

} else {

[Link]("Mean fare per passenger: ₹0.00");

[Link]();

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

 // To check Happy number

import [Link].*;

class Happy_Number
{

public static void main(String args[])

Scanner in = new Scanner([Link]);

int num, sum = 0, d;

[Link]("Enter a number");

num = [Link]();

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)

[Link]("Happy Number");

else

[Link]("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 [Link].*;

public class Compute

double pi = 22.0 / 7.0;

void volume(float a)

double v = a * a * a;

[Link]("The volume of a cube = " + v);

void volume(float r, float h)

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

[Link]("The volume of a sphere = " + v);

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

double v = l * b * h;

[Link]("The volume of a cuboid = " + v);

public static void main(String args[])


{

Scanner in = new Scanner([Link]);

float a, r, l, b, h;

[Link]("Enter the value of side of a cube, radius of sphere,


sides of a cuboid:");

a = [Link]();

r = [Link]();

l = [Link]();

b = [Link]();

h = [Link]();

Compute ob = new Compute();

[Link](a);

[Link](r, h);

[Link](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 = [Link](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 [Link].*;
public class StringPattern //Class declaration
{
public static void main(String args[])
{
Scanner in = new Scanner([Link]);
[Link]("Enter a word: "); //Taking input from user
String word = [Link](); int len = [Link]();

for (int i = len - 1; i >= 0; i--) //loop for displaying the pattern
{
for (int j = 0; j <= i; j++)
{
char ch = [Link](j);
[Link](ch);
}
[Link]();
}
} }
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 [Link].*;
public class Transpose //Class declaration
{
public static void main(String args[])
{

Scanner sc=new Scanner([Link]);


[Link]("Entre number of rows "); //Taking input from user
int n1=[Link]();
[Link]("Entre number of columns"); int n2=[Link]();
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++)
{
[Link]("Enter number");
arr[i][j]=[Link]();
}
}
[Link]("The numbers of matrix are:");
for( int i=0;i<n1;i++) //displaying the original matrix

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

}}

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 [Link].*;
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;
[Link]("Square = " + sq );
} else
{
int cube = m * m * m;
[Link]("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;
[Link]("Product = " + prod );
} else
{
long sum = a + b;
[Link]("Sum = " + sum);
}
}

void num_calc(String s1, String s2)


{
if([Link](s2)) //Checking if the strings are equal
[Link]("Strings are equal"); else
[Link]("Strings are not equal") } }
Q12. Triangle

Import [Link].*;

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

double ar;

double s = (a + b + c) / 2;
ar = [Link](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;

Common questions

Powered by AI

The Class ChoiceOverload uses character-based user decisions to dynamically alter calculations, such as deciding between computing squares or cubes, products or sums, and assessing string equality. This character-based choice allows the same method name to serve multiple purposes, enhancing user interaction and decision-making flexibility. It fosters flexibility in program design by allowing user-driven logic paths that handle a variety of computations flexibly without necessitating multiple distinct method calls or classes, thereby encapsulating multiple operations within streamlined control structures.

When calculating the area using method overloading, it's crucial to define methods that reflect the specific geometric characteristics and formulae for each shape. For triangles, the Heron's formula is implemented requiring three side lengths. For trapezoids, one method uses base lengths and height with appropriate coefficients, while for quadrilaterals like rhombuses or kites, the method uses diagonals for calculation. By overloading based on parameter signature—distinguishing each shape's parameters—the program effectively manages diverse geometric calculations under a unified method name streamlining function invocation based on context.

The electricity bill calculation method categorizes unit consumption into three tiers: (1) For 0 to 100 units, the charge is calculated at ₹1.25 per unit; (2) For units between 101 and 200, in addition to the first 100 units charged at ₹1.25 per unit, the additional units are charged at ₹1.50 per unit; (3) For units above 200, the additional units beyond 200 are charged at ₹1.80 per unit. This tiered pricing model helps determine the total bill based on the units consumed and provides a progressive charge on electricity usage.

The Pronic number program verifies if a number is Pronic by checking if the number can be expressed as the product of two consecutive integers. This is done by iterating through integers from 1 up to the number itself, and for each integer i, it calculates the product i * (i + 1) and checks if it matches the given number. The logic involves consecutive integers because a Pronic number is defined as the product of two consecutive integers, which means it fits the definition only if such a pair is found for the input number.

Function overloading allows the program to define multiple versions of the 'volume' method, each differing in parameter types and quantities to calculate volumes of a cube, sphere, and cuboid. For a cube, the function takes one float for the side. For a sphere, it takes a float for radius and height erroneously but is intended for proper radius and computes differently. For a cuboid, it takes three floats for length, breadth, and height. This method is beneficial in coding because it allows the concise organization of functions under one common name that distinguishes based on input parameters, encourages code reuse, and enhances readability and maintainability.

The pattern display program begins by printing the entire word, then repetitively reduces the number of characters displayed by one from the end in each subsequent line. By iterating backward through the word's length and using a nested loop to print characters up to the remaining length, the program constructs a pyramid-like pattern. This successive decrement ensures a descending character row alignment, which creates a symmetric stepwise visual effect. This mechanism efficiently visualizes strings in diminishing layers, emphasizing patterns through character manipulation.

The Transpose class reads a 4x4 matrix and processes it by iterating through its elements, swapping the row and column indices. It effectively creates a new matrix where the original matrix's rows become the new matrix's columns. This rearrangement is significant in linear algebra for operations such as transforming coordinate systems, solving systems of equations, and simplifying matrix expressions in theoretical and applied mathematics. The transposing operation enhances understanding and manipulation of data arrangement within matrices.

The logic for calculating bus fare operates on a tiered pricing strategy, which charges a base fare of ₹80 for distances up to 5 km. For distances greater than 5 km but not exceeding 15 km, an additional charge of ₹10 per km applies to the distance between 5 and 15 km. For distances over 15 km, a further fee of ₹8 per km is added for each kilometer beyond 15. This tiered strategy exemplifies effective pricing that increases with distance, mimicking utility-based and consumption-based strategies, helping manage capacity and revenue based on usage intensity and service level demand.

The Successor Product program computes a product by iterating through the digits of an input number and identifying the even digits. For each even digit, the program computes the successor (the next integer) and multiplies it to an accumulating product variable. If there are no even digits in the number, the program outputs 'No even digits.' The use of the successor ensures that each even digit contributes a factor that is one greater than it would have been.

The program identifies Happy Numbers by repetitively transforming a number through a process of summing the squares of its digits until the result is a single-digit number. This iterative process tests if the resulting number equals 1, which classifies the original number as a Happy Number. If the process results in any other number, it is deemed not a Happy Number. This classification depends on digit manipulation because it breaks down the number to its digit constituents to evaluate over repeated iterations.

You might also like