Board Proj
Board Proj
APPLICATION
PROJECT
1
ACKNOWLDEDGEMEM
NT
2
Index
Sno. Topic Page no.
name
3
INTRODUCTION
TO JAVA
Overview
Java is a class-based object-oriented simple programming
language. Though we can not consider it to be fully object-
oriented as it supports primitive datatypes. It is a general-
purpose, high-level programming language that helps
programmers and developers to write a code once and run it
anywhere. Java is considered both
a compiled and interpreted language. It is because Java
source code is first compiled to bytecode which is then
interpreted by Java Virtual Machine. Java Virtual Machine
interprets the bytecode and converts it to platform specific
machine code. Hence, Java is also called a platform-
independent programming language.
4
Why Java Programming Language is Called
JAVA?
Java is the name of a beautiful island in Indonesia. It is also
said that the first coffee was named right here after java
coffee. The name was chosen by James Gosling during the
daytime when he was enjoying a cup of coffee near his office.
Java was initially called by the name: OAK.
1) Object-Oriented
2) Portable
3) Simple
4) Secure
5) Robust
6) Platform Independent
7) Architecture neutral
5
PROGRAM
S
Question 1
Write a program to input a three digit number. Use a method
int Armstrong(int n) to accept the number. The method
returns 1, if the number is Armstrong, otherwise zero(0).
It is an Armstrong Number.
ANS:-
import java.util.Scanner;
public class ArmstrongNumber
{
public static void main(String[] args) {
int n,arm=0,rem,c;
Scanner in=new Scanner(System.in);
System.out.println("Enter any Number");
n=in.nextInt();
c=n;
while (n> 0) {
rem= n % 10;
arm = (rem*rem*rem)+arm;
n=n/= 10;
}
if (c==arm)
System.out.println("Armstrong Number");
else
System.out.println("Not Armstrong Number");
6
}
Output
Enter Number: 153
153 is an Armstrong number
Enter Number: 747
747 is not an Armstrong number
VARIABLE DESCRIPTION
Variable Dataype Descripti
on
n int To store the value
of the user input.
arm int To store and
compute the value
of Armstrong
number.
rem int To store the
remainder value.
Question 2
7
Write a class with the name Perimeter using method
overloading that computes the perimeter of a square, a
rectangle and a circle.
Formula: Perimeter of a square = 4 * s
Perimeter of a rectangle = 2 * (l + b)
Perimeter of a circle = 2 * (22/7) * r
Ans:-
import java.util.Scanner;
8
double r = in.nextDouble();
System.out.println("Perimeter of circle = " +
obj.perimeter(2, 3.14159, r));
}
}
Output
Enter side of square: 3
Perimeter of square = 12.0
Enter length of rectangle: 10
Enter breadth of rectangle: 7
Perimeter of rectangle = 34.0
Enter radius of circle: 6
Perimeter of circle = 37.699079999999995
VARIABLE DESCRIPTION
Variable Dataype Descripti
on
p double To store and compute
perimeters.
r double To store the value of
radius of circle.
9
Question 3
int prv, pre to store the previous and present meter readings
Member
Purpose
functions
Displays the name of the consumer, calls made, amount and total
void
display()
amount to be paid
Write a program to compute the monthly bill to be paid according to the given
conditions and display the output as per the given format.
10
Calls made Rate
However, every consumer has to pay ₹180 per month as monthly rent for availing the
service.
Output:
Ans:-
import java.util.Scanner;
public class Telephone
{
private int prv;
private int pre;
private int call;
private String name;private double amt;
private double total;
public void input() {
Scanner in = new Scanner(System.in);
System.out.print("Enter Customer Name: ");
name = in.nextLine();
System.out.print("Enter previous reading: ");
prv = in.nextInt();
System.out.print("Enter present reading: ");
pre = in.nextInt();
}
public void cal() {
call = pre - prv;
if (call <= 100)
amt = 0;
11
else if (call <= 200)
amt = (call - 100) * 0.9;
else if (call <= 400)
amt = (100 * 0.9) + (call - 200) * 0.8;
else
amt = (100 * 0.9) + (200 * 0.8) + ((call - 400) * 0.7);
Output
12
VARIABLE DESCRIPTION
Variab Datay Description
le pe
prv int to store the previous
and present meter
readings
pre int to store the previous
and present meter
readings
call int To store the call made.
Question 4
Bank charges interest for the vehicle loan as given below:
Up to 5 years 15%
13
Number of years Rate of interest
Ans:-
import java.util.Scanner;
14
public void getdata() {
Scanner in = new Scanner(System.in);
System.out.print("Enter principal: ");
principal = in.nextInt();
System.out.print("Enter time: ");
time = in.nextInt();
}
Output
Enter principal: 4000
Enter time: 11
Interest = 4400.0
Amount Payable = 8400.0
15
VARIABLE DESCRIPTION
Variab Datay Description
le pe
p int
to store the principal
amount.
r float
To calculate the rate of
interest.
Question 5
Define a class Bill that calculates the telephone bill of a
consumer with the following description:
16
Data
Purpose
Members
Member
Purpose
Methods
17
Units consumed Rate
Ans:-
import java.util.Scanner;
public Bill() {
bno = 0;
name = "";
call = 0;
amt = 0.0;
}
18
charge = 60 + ((call - 100) * 0.8);
else if (call <= 300)
charge = 60 + 80 + ((call - 200) * 1.2);
else
charge = 60 + 80 + 120 + ((call - 300) * 1.5);
Output
Enter Name: Aditya
Enter Bill Number: 40302010
Enter Calls: 23
Bill No: 40302010
Name: Aditya
Calls: 23
Amount Payable: 138.8
19
VARIABLE DESCRIPTION
Variab Datay Description
le pe
bno int
to store the bill number.
Question 6
Write a program by using a class with the following
specifications:
20
Member functions:
Ans:-
import java.util.Scanner;
Output
Enter the number: 5
Factorial of 5 = 120
21
VARIABLE DESCRIPTION
Variab Datay Description
le pe
n int
To store the value of
user input.
Question 7
A bank announces new rates for Term Deposit Schemes for their
customers and Senior Citizens as given below:
Rate of
Rate of
Interest
Term Interest
(Senior
(General)
Citizen)
Up to 1
7.5% 8.0%
year
22
Rate of
Rate of
Interest
Term Interest
(Senior
(General)
Citizen)
Up to 2
8.5% 9.0%
years
Up to 3
9.5% 10.0%
years
More
than 3 10.0% 11.0%
years
The 'senior citizen' rates are applicable to the customers whose age is 60
years or more. Write a program to accept the sum (p) in term deposit
scheme, age of the customer and the term. The program displays the
information in the following format:
Ans:-
import java.util.Scanner;
23
double si = 0.0;
Output
Enter sum: 20000
Enter age: 19
Enter term: 3
Amount Deposited: 20000.0
Term: 3.0
Age: 19
Interest Earned: 5700.0
Amount Paid: 25700.0
24
VARIABLE DESCRIPTION
Variab Datay Description
le pe
sum double
To store the value of
sum.
Question 8
Write a program using switch case to find the volume of a
cube, a sphere and a cuboid.
For an incorrect choice, an appropriate error message
should be displayed.
1. Volume of a cube = s * s *s
2. Volume of a sphere = (4/3) * π * r * r * r (π = (22/7))
3. Volume of a cuboid = l*b*h
Ans:-
import java.util.Scanner;
25
{
public static void main(String args[]) {
switch(choice) {
case 1:
System.out.print("Enter side of cube: ");
double cs = in.nextDouble();
double cv = Math.pow(cs, 3);
System.out.println("Volume of cube = " + cv);
break;
case 2:
System.out.print("Enter radius of sphere: ");
double r = in.nextDouble();
double sa = (4 / 3.0) * (22 / 7.0) *
Math.pow(r, 3);
System.out.println("Volume of sphere = " +
sa);
break;
case 3:
System.out.print("Enter length of cuboid: ");
double l = in.nextDouble();
System.out.print("Enter breadth of cuboid:
");
double b = in.nextDouble();
System.out.print("Enter height of cuboid: ");
double h = in.nextDouble();
double vol = l * b * h;
System.out.println("Volume of cuboid = " +
vol);
break;
default:
System.out.println("Wrong choice! Please
select from 1 or 2 or 3.");
}
}
}
Output
26
1. Volume of Cube
2. Volume of Sphere
3. Volume of Cuboid
Enter your choice: 1
Enter side of cube:
33
Volume of cube = 35937.0
VARIABLE DESCRIPTION
Variable Dataype Descripti
on
cs double To store the value of
sides of cube.
cv double To calculate and print
the volume of cube.
27
Question 9
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.
Write a program to accept a two-digit number. Add the sum of its digits to the
product of its digits. If the value is equal to the number input, then display the
message "Special two—digit number" otherwise, display the message "Not a
special two-digit number".
Ans:-
import java.util.Scanner;
while (num != 0) {
int digit = num % 10;
num /= 10;
digitSum += digit;
digitProduct *= digit;
count++;
}
if (count != 2)
System.out.println("Invalid input, please enter a 2-
digitnumber");
else if ((digitSum + digitProduct) == orgNum)
System.out.println("Special 2-digit number");
else
System.out.println("Not a special 2-digit
number");}
}
Output
Enter a 2 digit number: 59
28
Special 2-digit number
Enter a 2 digit number: 85
Not a Special 2-digit number
Enter a 2 digit number: 4
Invalid input, please enter a 2-digit number
Enter a 2 digit number: 512
Invalid input, please enter a 2-digit number
VARIABLE DESCRIPTION
Variable Dataype Descripti
on
orgNum int To store the value of 2
digit number.
digitSum int To store and calculate
the sum of digits.
digitProduct int To store and calculate
the product of digits.
digit double To store the value of
digitProduct.
num int To store and compute
the value of orgNum.
Question 10
Write a menu driven program to perform the following tasks:
29
(b) Write a program to display all Sunny numbers in the range from 1 to n.
[Hint: A number is said to be sunny number if square root of (n+1) is an integer.]
For example,
3, 8, 15, 24, 35,......................are sunny numbers.
Ans:-
import java.util.Scanner;
switch (ch) {
case 1:
int a = 1, b = 1, c = 2;
case 2:
System.out.print("Enter n: ");
int n = in.nextInt();
default:
30
System.out.println("Incorrect choice");
break;
}
}
}
Output
Output(i)
1. Tribonacci numbers
2. Sunny numbers
Enter your choice: 1
1 1 2 4 7 13 24 44 81 149 274 504 927 1705 3136 5768 10609 19513
35890 66012
Output(ii)
1. Tribonacci numbers
2. Sunny numbers
Enter your choice: 2
Enter n: 50
3 8 15 24 35 48
VARIABLE DESCRIPTION
Variable Dataype Descripti
on
ch int To accept user’s
choice
a int To calculate the value
of Tribonacci number.
b int To calculate the value
of Tribonacci number.
c int To calculate the value
of Tribonacci number.
term int To store the sum of
a,b and c
n int To store the value of
number of days.
sqRoot double To calculate square
root and store its
value.
temp double To store the value of
temperature.
31
Question 11
15 14 13 12 11
10 9 8 7
6 5 4
3 2
1
Ans:-
public class Pattern
{
public void displayPattern() {
int a = 15;
for (int i = 5; i > 0; i--) {
for (int j = 1; j <= i; j++) {
System.out.print(a-- + "\t");
}
System.out.println();
}
}
}
Output
15 14 13 12 11
10 9 8 7
6 5 4
3 2
1
VARIABLE DESCRIPTION
Variable Dataype Description
a int To store the total
number of character.
i int Loop variable
j int Loop variable
32
Question 12
Write the programs to display the following pattern:
1 2 3 4 5
2 2 3 4 5
3 3 3 4 5
4 4 4 4 5
5 5 5 5 5
Ans:-
public class Patterns
{
public void displayPattern() {
for (int i = 1; i <= 5; i++) {
System.out.println();
}
}
}
Output
12 3 4 5
2 2 3 4 5
3 3 3 4 5
33
4 4 4 4 5
5 5 5 5 5
VARIABLE DESCRIPTION
Variable Dataype Description
k int Loop variable
i int Loop variable
j int Loop variable
Question 13
Write the programs to display the following pattern:
*
* #
* #*
* #*#
* #*#*
Ans:-
public class Pattern_s
{
public void displayPattern() {
for (int i = 1; i <= 5; i++) {
for (int j = 1; j <= i; j++) {
if (j % 2 == 0)
System.out.print("# ");
else
System.out.print("* ");
}
System.out.println();
}
}
}
34
Output
*
* #
* #*
* #*#
* #*#*
VARIABLE DESCRIPTION
Variable Dataype Description
i int Outer Loop variable
j int Inner Loop variable
Question 14
Write a program to store 20 numbers in a Single
Dimensional Array (SDA). Now, display only those numbers
that are perfect squares. n[0] n[1] n[2] n[3] n[4] n[5] ...
n[16] n[17] n[18] n[19] 12 45 49 78 64 77 ... 81 99 45 33
Sample Output: 49, 64, 81
Ans:-
import java.util.Scanner;
35
for (int j = 0; j < arr.length / 2 - i - 1; j++)
{
if (arr[j] > arr[j + 1]) {
int t = arr[j + 1];
arr[j + 1] = arr[j];
arr[j] = t;
}
}
}
System.out.println("\nSorted Array:");
for (int i = 0; i < arr.length; i++) {
System.out.print(arr[i] + " ");
}
}
}
Output
Enter 20 numbers:
1
2
3
4
5
6
7
6
5
4
69
420
540
32
36
20203
3024
2024
32
43
3
Sorted Array:
1 2 3 4 4 5 5 6 6 7 20203 3024 2024 540 420 69 43 32 32 3
VARIABLE DESCRIPTION
Variable Dataype Description
i int To accept and store the
value 20 integers, in
iterative constructs and
single dimensional array
j int To be used in iterative
constructs , conditional
statements and single
dimensional array
Question 15
If arrays M and M + N are as shown below, write a program
in Java to find the array N.
M = {{-1, 0, 2}, M + N = {{-6, 9, 4},
{-3, -1, 6}, {4, 5, 0},
{4, 3, -1}} {1, -2, -3}}
Ans:-
public class SubtractDDA
{
public static void main(String args[]) {
int arrM[][] = {
{-1, 0, 2},
{-3, -1, 6},
{4, 3, -1}
};
int arrSum[][] = {
{-6, 9, 4},
{4, 5, 0},
37
{1, -2, -3}
};
System.out.println("Array N:");
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
System.out.print(arrN[i][j]);
System.out.print(' ');
}
System.out.println();
}
}
}
Output
Array N:
-5 9 2
7 6 -6
-3 -5 -2
VARIABLE DESCRIPTION
Variable Dataype Description
38
Question 16
Write a program to input a sentence. Find and display the
following:
(i) Number of words present in the sentence
(ii) Number of letters present in the sentence
Assume that the sentence has neither include any digit nor a
special character.
Ans:-
import java.util.Scanner;
wCount++;
Output
Enter a sentence:
Happy New Year
No. of letters = 1No. of letters = 12
39
VARIABLE DESCRIPTION
Variable Dataype Description
Question 17
Write a program in Java to store 10 words in a Single
Dimensional Array. Display only those words which are
Palindrome.
Sample Input: MADAM, TEACHER, SCHOOL, ABBA, .........
Sample Output: MADAM
ABBA
..........
..........Enter a word : BLUEJ
Sample Output:
BLUEJ
BLUE
BLU
BL
B
Ans:-
import java.util.Scanner;
40
for (int i = 0; i < words.length; i++) {
words[i] = in.nextLine();
}
System.out.println("\nPalindrome Words:");
if (isPalin)
System.out.println(words[i]);
}
}
}
Output
Enter 10 words:
MADAM
TEACHER
SCHOOL
ABBA
ENGLISH
HINDI
GEOGRAPHY
MATHEMATICS
COMPUTER
LAPTOP
Palindrome Words:
41
MADAM
ABBA
VARIABLE DESCRIPTION
Variable Dataype Description
Question 18
Write a program to accept the year of graduation from school as an integer value from
the user. Using the binary search technique on the sorted array of integers given
below, output the message "Record exists" if the value input is located in the array. If
not, output the message "Record does not exist". Sample Input: n[0] n[1] n[2] n[3] n[4]
n[5] n[6] n[7] n[8] n[9] 1982 1987 1993 1996 1999 2003 2006 2007 2009 2010
Ans:-
import java.util.Scanner;
42
}
}
if (idx == -1)
System.out.println("Record does not exist");
else
System.out.println("Record exists");
}
}
Output
Enter graduation year to search: 2000
Record does not exist
VARIABLE DESCRIPTION
Variable Dataype Description
Question 19
Write a java program to arrange 20 numbers in descending order using selection sort
Ans:-
import java.util.Scanner;
public class bubble_sort
{
public static void main(String[] args)
{
int n, temp;
Scanner s = new Scanner(System.in);
System.out.print("Enter no. of elements you want in array:");
n = s.nextInt();
43
int a[] = new int[n];
System.out.println("Enter all the elements:");
for (int i = 0; i < n; i++)
{
a[i]=s.nextInt();
}
for (int i = 0; i<n; i++)
{
for(int j=1+1; j<n; j++)
{
if (a[i] < a[j])
{
temp= a[i];
a[i]=a[j];
a[j] = temp;
}
}
}
System.out.print("Descending Order:");
for (int i = 0; i < n - 1; i++)
{
System.out.print(a[i] + ",");
}
System.out.print(a[n - 1]);
}
}
Output
Enter no. of elements you want in array:5
Enter all the elements:
23
12
34
45
54
Descending Order:54,45,12,23,34
VARIABLE DESCRIPTION
Variable Dataype Description
44
Question 20
Write a program to accept a list of 20 integers. Sort the first 10 numbers in ascending
order and next the 10 numbers in descending order by using 'Bubble Sort' technique.
Finally, print the complete list of integer
Ans:-
import java.util.Scanner;
Output
45
Enter 20 numbers:
1
2
3
4
5
6
7
6
5
4
69
420
540
32
20203
3024
2024
32
43
3
Sorted Array:
1 2 3 4 4 5 5 6 6 7 20203 3024 2024 540 420 69 43 32 32 3
VARIABLE DESCRIPTION
Variable Dataype Description
i int To accept and store the
value 20 integers, in
iterative constructs and
single dimensional array
j int To be used in iterative
constructs , conditional
statements and single
dimensional array
46
Bibliograph
y
https://www.knowledgeboat.com/
https://byjus.com/
https://www.javatpoint.com/
https://www.geeksforgeeks.org/
47
Conclusion
Java is an object-oriented programming
language. It is a general-purpose
programming language, mainly
designed to run developed Java code on
all platforms that support Java without
recompilation. As we all know, Java is
one of the most popular and indemand
programming languages to learn and it
was one of the first languages to
standardise high-level threading
utilities. Java project is a must for
aspiring developers. This project helps
developers develop real-world projects
to hone their skills and materialise their
theoretical knowledge into practical
experience. Java has significant
48
advantages both as a commercial
language and as a teaching language.
Java project provides rigorous compile-
time error checking typically associated
with Pascal, allowing instructors to
introduce students to GUI programming,
networking, threads, and other
important concepts used in modern-day
software. Overall, the Java project gives
a complete design for the extended
language.
49