0% found this document useful (0 votes)
43 views26 pages

Java Programming Projects for Class X

The document is a computer project report submitted by Diya Mondal, a class 10 student. It contains an acknowledgement expressing gratitude to the computer teacher for the opportunity and help with the assignment. It also lists various Java programs with their topics and page numbers. The introduction provides an overview of the Java programming language.
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

Topics covered

  • volume calculation,
  • Java performance,
  • data types,
  • control structures,
  • Java security,
  • Java documentation,
  • Java trends,
  • Java classes,
  • Java tools,
  • program structure
0% found this document useful (0 votes)
43 views26 pages

Java Programming Projects for Class X

The document is a computer project report submitted by Diya Mondal, a class 10 student. It contains an acknowledgement expressing gratitude to the computer teacher for the opportunity and help with the assignment. It also lists various Java programs with their topics and page numbers. The introduction provides an overview of the Java programming language.
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

Topics covered

  • volume calculation,
  • Java performance,
  • data types,
  • control structures,
  • Java security,
  • Java documentation,
  • Java trends,
  • Java classes,
  • Java tools,
  • program structure

Modern Public School

Computer Project
(2023-2024)

Name : Diya Mondal

Class : X Section : B
Roll No.: 19

Page | 1
Acknowledgement
I would like to express my special thanks of gratitude to my computer
teacher Sir Prantik Nandy , who gave me the golden opportunity to do
this wonderful assignment. I came to know so many new things, I am
really thankful to them. Secondly, I would like to thank my parents,
teachers and friends who helped me a lot in finishing this program
neatly, tidily and within the limited time frame.
Thank You
Diya Mondal

Page | 2
Contents
Topic Page no.
1. Write a java program to interchange two numbers in a sub method where 5-6
both input and output will be done in sub.
2. Write a program based on the criteria given below and input the name 7-9
and address of the customer and the type of purchase (L for laptop and D for
desktop PC). Compute the net amount to be paid by the customer.
Purchase amount discount on laptop discount on desktop PC
0-25000 0.0% 5.0%
25001-57000 5.0% 7.5%
57001-100000 7.5% 10.0%
More than 100000 10.0% 15.0%
3. Write a program to add the following series using the members given 10-12
below:
Ax-ax2+ax3-ax4…..upto n terms
Name of the class: Series
Member data: s:to store the sum
Member method: Series():to initialize s as 0
Void ask():to ask a,x and n
Void call():to add the series
Void display():to show the sum
4. Write a java program to check whether a given character is an uppercase 13-14
or lowercase or digit.
5. Write a java program to check whether a number is prime or not using a 15-16
method which will take input from main().
6. Write a program to convert Fahrenheit to Centigrade or Centigrade to 17-19
Fahrenheit as per user’s choice. Design two methods separately to perform
two tasks which will take value from the main().
7. Write a program to accept a number from the user and check if it is an 20-21
automorphic number or not.
8. Write a program to create overloaded methods named void 22-24
calc_volume(), that has been overloaded to perform the following functions:
Volume of Sphere
Volume of Cylinder
Volume of Cone
Write a menu driven program in java to display the above 3 menus
and execute the overloaded methods and display the volume in the
respective functions.
calc_volume(double) for sphere
calc_volume(double,double) for cylinder and
calc_volume(float,float) for cone.

Page | 3
Introduction
Java is a popular third generation programming language that can
handle any kind of software emerging in the computer background.
Java is an Object-oriented programming language. The features and
the kind of functionality and versatility java offers, has contributed, to
a large degree, to the popularity of this language.
In the early nineties, java was created by a team led by James
Gosling, for Sun Microsystems, later acquired by Oracle Corporation
that provides a system for developing application software. It was
originally designed for use on digital mobile devices, such as cell
phones. However, when java 1.0 was released in 1996, its main focus
shifted to use on the internet. It provided more interactivity with users
by giving developers a way to produce animated web pages.

Page | 4
Programs with output
1. Write a java program to interchange two numbers in a sub
method where both input and output will be done in sub.

 The Program:
import [Link].*;

public class program1

void sub()

Scanner sc= new Scanner([Link]);

[Link]("Enter two numbers for inter changing");

int x= [Link]();

int y= [Link]();

x=x+y;

y=x-y;

x=x-y;

[Link]("Numbers after inter changing");

[Link](x);

[Link](y);

public static void main()

program1 obj= new program1();

[Link]();

Page | 5
Output:

Variable description box:


Variable name Data type Purpose
sc object Object of Scanner class.
x integer To store a value from user.
y integer To store a value from user.
obj object Object of the class.

Page | 6
2. Write a program based on the criteria given below and input the
name and address of the customer and the type of purchase (L for
laptop and D for desktop PC). Compute the net amount to be paid by
the customer.
Purchase amount discount on laptop discount on desktop PC
0-25000 0.0% 5.0%
25001-57000 5.0% 7.5%
57001-100000 7.5% 10.0%
More than 100000 10.0% 15.0%

 The Program:
import [Link].*;

public class program2

public static void main()

Scanner sc= new Scanner([Link]);

[Link]("Enter the name");

String name= [Link]();

[Link]("Enter the address");

String add= [Link]();

[Link]("Enter the type of purchase");

char type= [Link]().charAt(0);

double dis,net,pur;

switch(type)

case 'L':

[Link]("Enter the purchase amount of your laptop");

pur= [Link]();

if(pur<=25000)

dis= pur*0/100;

else if(pur>25000 && pur<=57000)

Page | 7
dis= pur*5/100;

else if(pur>57000 && pur<=100000)

dis= pur*7.5/100;

else

dis= pur*10/100;

net= (pur-dis);

[Link]("Net amount payable= "+net);

break;

case 'D':

[Link]("Enter the purchase amount of your desktop PC");

pur= [Link]();

if(pur<=25000)

dis= pur*5/100;

else if(pur>25000 && pur<=57000)

dis= pur*7.5/100;

else if(pur>57000 && pur<=100000)

dis= pur*10/100;

else

dis= pur*15/100;

net= (pur-dis);

[Link]("Net amount payable= "+net);

break;

default:

[Link]("Wrong type of purchase");

Page | 8
Output:

Variable description box:


Variable name Data type Purpose
sc object Object of scanner class.
name,add String Stores data from the user.
type character Stores data from the user.
dis,net,pur double To calculate and store value.

Page | 9
3. Write a program to add the following series using the members given
below:
Ax-ax2+ax3-ax4…..upto n terms
Name of the class: Series
Member data: s:to store the sum
Member method: Series():to initialize s as 0
Void ask():to ask a,x and n
Void call():to add the series
Void display():to show the sum

 The Program:
import [Link].*;
public class Series
{
Scanner sc= new Scanner([Link]);
double a;
double x;
double n;
double s;
void series()
{
s=0;
}
void ask()
{
[Link]("Enter the value of a");
a= [Link]();
[Link]("Enter the value of x");
x= [Link]();
[Link]("Enter the value of n");
n= [Link]();

Page | 10
}
void call()
{
for(int i=1; i<=n; i++)
{
if(i%2==0)
s= s-(a*[Link](x,i));
else
s= s+(a*[Link](x,i));
}
}
void display()
{
[Link]("Sum of the series= "+s);
}
public static void main()
{
Series obj= new Series();
[Link]();
[Link]();
[Link]();
[Link]();
}
}

Page | 11
Output:

Variable description box:


Variable name Data type Purpose
sc object Object of Scanner class.
a,x,n double To calculate and store a
value from the user.
s double To calculate and store
the value of the series.
obj object Object of the class.

Page | 12
4. Write a java program to check whether a given character is an
uppercase or lowercase or digit.

 The Program:
import [Link].*;

public class program4

public static void main()

Scanner sc= new Scanner([Link]);

[Link]("Enter a character");

char n= [Link]().charAt(0);

if([Link](n))

[Link]("The character is uppercase");

else if([Link](n))

[Link]("The character is lowercase");

else if([Link](n))

[Link]("The character is a digit");

else

[Link]("The character is not lowercase,uppercase or a digit");

Page | 13
Output:

Variable description box:


Variable name Data type Purpose
sc object Object of Scanner class.
n character To store data from the
user.

Page | 14
5. Write a java program to check whether a number is prime or not
using a method which will take input from main().

 The Program:

import [Link].*;
public class program5
{
static boolean prime(int x)
{
int c=0;
for(int i=1; i<=x; i++)
{
if(x%i==0)
c= c+1;
}
if(c==2)
return true;
else
return false;
}
public static void main()
{
Scanner ss= new Scanner([Link]);
[Link]("Enter a number");
int n= [Link]();
boolean z= prime(n);
if(z==true)
[Link](n+" is a prime number");

Page | 15
else
[Link](n+" is not a prime number");
}
}

Output:

Variable description box:


Variable name Data type Purpose
x integer To perform tasks in method
prime().
c,i integer To calculate and store a
value.
ss object Object of the Scanner class.
n integer To store a value from the
user.
z boolean To perform some tasks.

6. Write a program to convert Fahrenheit to Centigrade or Centigrade


to Fahrenheit as per user’s choice. Design two methods separately to
perform two tasks which will take value from the main().

Page | 16
 The Program:

import [Link].*;
public class program6
{
static double f_to_c(double f)
{
double c= ((f-32)*5)/9;
return c;
}
static double c_to_f(double c)
{
double f= (c*9/5)+32;
return f;
}
public static void main()
{
Scanner sc= new Scanner([Link]);
[Link]("Enter 1 to convert temperature from Fahrenheit to Centrigrade
scale");
[Link]("Enter 2 to convert temperature from Centrigrade to Fahrenheit
scale");
int choice = [Link]();
double f;
double c;
switch(choice)
{
case 1:
[Link]("Enter the temperature in Fahrenheit scale");

Page | 17
f= [Link]();
c= f_to_c(f);
[Link]("The temperature in Centrigrade scale= "+c);
break;
case 2:
[Link]("Enter the temperature in Centrigrade scale");
c= [Link]();
f= c_to_f(c);
[Link]("The temperature in Fahrenheit scale= "+f);
break;
default:
[Link]("Wrong choice");
}
}
}

Output:

Variable description box:


Variable name Data type Purpose
f,c double To store a data from the
user. To perform certain

Page | 18
tasks and calculations in
c_to_f() , f_to_c() and
main() methods.
sc object Object of the Scanner
class.
choice integer To store a data from the
user.

7. Write a program to accept a number from the user and check if it is


an automorphic number or not.

 The Program:

Page | 19
import [Link].*;

public class program7

static boolean Auto(int n)

int sq= n*n;

while(n>0)

if(n%10 != sq%10)

return false;

n=n/10;

sq=sq/10;

return true;

public static void main()

Scanner sc= new Scanner([Link]);

[Link]("Enter the number");

int n= [Link]();

[Link](Auto(n)?"Automorphic number":"Not Automorphic number");

Output:

Page | 20
Variable description box:
Variable name Data type Purpose
n integer To store a value from the
user. To calculate and
perform tasks in Auto()
and main() methods.
sq integer To calculate and store a
value.
sc object Object of the Scanner
class.

8. Write a program to create overloaded methods named void


calc_volume(), that has been overloaded to perform the following
functions:

Page | 21
Volume of Sphere
Volume of Cylinder
Volume of Cone
Write a menu driven program in java to display the above 3 menus
and execute the overloaded methods and display the volume in the
respective functions.
calc_volume(double) for sphere
calc_volume(double,double) for cylinder and
calc_volume(float,float) for cone.

 The Program:
import [Link].*;
public class program8
{
double vol;
double pi= 3.14159265359;
void calc_volume(double r)
{
vol= (4*pi*[Link](r,3))/3;
[Link]("Volume of the sphere= "+vol);
}
void calc_volume(double r, double h)
{
vol= pi*[Link](r,2)*h;
[Link]("Volume of the cylinder= "+vol);
}
void calc_volume(float r, float h)
{
vol= pi*[Link](r,2)*(h/3);
[Link]("Volume of the cone= "+vol);
}

Page | 22
public static void main()
{
Scanner sc= new Scanner([Link]);
program8 obj= new program8();
[Link]("Enter 1 to compute the volume of a sphere");
[Link]("Enter 2 to compute the volume of a cylinder");
[Link]("Enter 3 to compute the volume of a cone");
int choice= [Link]();
switch(choice)
{
case 1:
[Link]("Enter the radius of the sphere");
double r= [Link]();
obj.calc_volume(r);
break;
case 2:
[Link]("Enter the radius of the cylinder");
double r1=[Link]();
[Link]("Enter the height of the cylinder");
double h= [Link]();
obj.calc_volume(r1,h);
break;
case 3:
[Link]("Enter the radius of the cone");
float r2= [Link]();
[Link]("Enter the height of the cone");
float h2=[Link]();
obj.calc_volume(r2,h2);
break;

Page | 23
default:
[Link]("Wrong choice");
break;
}
}
}

Output:

Variable description box:


Variable name Data type Purpose
vol,r,h,r1 double To store a value from the
user. To calculate and
perform different tasks.
pi double To store the value of pi.
r,h,r2,h2 float To store a value from the
user. To calculate and
perform different tasks.
sc object Object of Scanner class.
obj object Object of the class.
choice integer To store a value from the
user.

Conclusion

Page | 24
Java is an object-oriented programming language. It is a general-
purpose programming language, mainly designed to run developed
java code on all platforms. With technology now a part of our daily
lives, we take it for granted that we can be connected to, and access
applications and content anywhere, anytime. Because of java, we
create digital devices which are smarter, more functional and far more
entertaining. Over the years, java has evolved as a successful
language for use, both on and off the internet. Till now, java is an
extremely popular language with millions of programmers worldwide.

Bibliography

Page | 25
Help from internet, websites and books have been used in the
completion of this program file:
Help from internet:
• [Link]
Following books has been used to have an idea about the program:
• Frank Computer Applications for ICSE (class IX)
• Frank Computer Applications for ICSE (class X)
And help from teachers, parents and friends has also been taken to
finalize the program.

Page | 26

Common questions

Powered by AI

Overloaded methods in Java allow multiple methods to have the same name with different parameter lists. This promotes code reusability by allowing a single method name to perform different but related functionalities, such as computing volumes of different shapes (sphere, cylinder, cone) with varying parameters. It provides flexibility because new methods can be added with little impact on existing code, making the code easier to maintain and extend. The readability of the code also improves when similar operations are grouped under a coherent method name .

Java's portability is achieved through the Java Virtual Machine (JVM), which allows Java code to run on any device equipped with the JVM, irrespective of the underlying hardware. This write-once, run-anywhere capability significantly broadens the scope of application deployment, providing a consistent environment across multiple platforms. This portability is a major factor in Java's widespread adoption, as it simplifies the distribution and compatibility challenges faced by developers, contributing to the language's enduring popularity .

The Scanner object in Java simplifies user input processing by providing a straightforward interface for reading data such as strings, integers, and other primitive types directly from different sources like user input. Its use in various Java programs, such as for collecting numerical inputs or strings in examples like volume calculation and purchasing programs, demonstrates its versatility. The ability to prompt for and immediately read inputs within methods enhances interactivity and makes for a seamless user experience .

The Java method for checking prime numbers uses the logic of counting the number of divisors a number has. The method iteratively checks each number up to the input number, incrementing a counter if divisible. A prime number should have exactly two divisors: 1 and itself. This logic is computationally simple and effective for small numbers, though it could be optimized for larger numbers using advanced methods like checking up to the square root of the number or employing probabilistic tests for primality .

Initially, Java was designed for use on digital mobile devices, focusing on providing robust, portable, and dynamic solutions. Its later application on the internet shifted Java's focus, emphasizing enhanced interactivity and animated web pages. This transition introduced applets and web-based applications, illustrating Java's adaptability and expanding its utility beyond limited mobile functionalities to broader interactive web applications .

Java is an object-oriented programming language that includes features like classes, objects, inheritance, encapsulation, and polymorphism. These features enhance software development by providing modularity, where a program can be composed of multiple interacting objects; reusability, through inheritance, allowing new classes to borrow existing code; and maintainability, as encapsulation limits direct access to object data, reducing dependencies. These principles ensure that software is more manageable, scalable, and adaptable .

Java enhanced interactivity through applets and interactive capability, pivotal in pioneering internet-based applications. By enabling dynamic web pages and functions, Java transformed user experience from static content to interactive interfaces, contributing to its widespread use. The ability to embed complex logic and graphics in web pages via Java served as a forerunner for later technologies, making it a preferred choice for early internet applications that required rich client interactions .

Calculating whether a number is automorphic involves comparing the number with the last digits of its square. The current method approaches this by performing modulo and division repeatedly, which is not optimal for very large numbers due to time complexity. Optimization could involve only examining digits up to the number's length, reducing computational overhead. Alternatively, leveraging number properties or patterns specific to automorphic numbers can further enhance efficiency. Proper input size handling also ensures that operations remain feasible without resource exhaustion .

Designing a temperature conversion program requires ensuring clarity and ease of use. Two separate methods for each conversion provide a clear modular structure, enhancing maintainability. Input validation is essential to avoid errors and handle incorrect input gracefully. User-friendly prompts improve user interaction. Furthermore, using meaningful variable names and comments can enhance code readability. The choice to return conversion results rather than print them directly within methods promotes reusability of the methods in other contexts .

Java's hierarchical structure, through classes and subclasses, supports encapsulation and modularity, vital for creating versatile function series like the series addition example. By organizing code into a class with clear member methods for initialization, input gathering, calculation, and display, Java leverages encapsulation to keep data within a managed scope. Hierarchical design facilitates method addition and modification without altering existing code structures. This characteristic helps in extending functionalities and debugging, improving overall program efficiency and maintainability .

You might also like