ACKNOWLEDGEMENT
I RONIT ROY ,would like to express my sincere gratitude to my
computer teacher, SIR RITESH KUMAR, for their valuable
guidance, encouragement, and support throughout the
completion of this computer project. Their constant
motivation and helpful suggestions enabled me to complete the
project successfully.
I AM ALSO DEEPLY THANKFUL TO OUR RESPECTED PRINCIPAL,
SISTER AMRITA, FOR PROVIDING ME WITH THE FACILITIES AND
OPPORTUNITIES THAT MADE THIS PROJECT POSSIBLE.
This project, which includes “13 programs and a gaming
program”, has helped me enhance my computer knowledge,
improve logical thinking, and develop problem-solving skills.
Finally, I would like to thank my parents and friends for their
continuous support and encouragement during the preparation
of this project.
1
INDEX
S. NO. TOPIC NAME PG. NO. REMARKS
1 INTRODUCTION 3
2 ELECTRIC BILL 4-5
GENERATOR
3 PIG LATIN 6-7
4 WORDS COUNT 8-9
5 SUMROWS 10 - 11
6 SELECTION SORT 12 - 13
7 LINEAR SEARCH 14
8 BookFair 15 - 16
9 MyDate 17 - 18
10 NUMBER GUESSING
GAME
19 - 20
11 PATTERN WITH 21 - 23
MENU
12 PRIMENUMBER 24 - 25
13 SUM SERIES 26 - 27
14 DAYS IN MONTH 28 - 29
15 ADVENTURE GAME 30 - 32
16 CONCLUSION 33
17 BIBLIOGRAPHY 34
2
INTRODUCTION
This computer project in Java, developed using
BlueJ, is designed to demonstrate the practical
application of object-oriented programming
concepts through a simple yet interactive program.
It effectively utilizes classes, objects, loops, and
conditionals to provide a clear understanding of
how these concepts work in real coding scenarios.
By working on this project, students not only
strengthen their foundation in Java programming
but also improve their logical thinking and
problem-solving skills, which are essential for
advanced learning in computer .
3
PROGRAM : 1
Define a class Electric Bill with the following specifications.
Class:ElectricBill
Instance Variables/Data Member:
String n – tostore the nameof the customer
int units – tostore the number of units consumed
double bill –tostore the amount to be paid
Member Methods:
voidaccept()–to accept the name of the customer and number of units consumed
voidcalculate()– to calculate the bill as per thefollowing tariff :
Number of units Rate per unit
First 100 units Rs.2.00
Next 200 units Rs.3.00
Above 300 units Rs.5.00
Asurcharge of 2.5% charged if the number of units consumed is above 300 units.
void print() – To print the details as follows:
Name of the customer ………
Number of units consumed ……
Bill amount ………
Write a main method to create an object of the class and call the above member methods.
SOURCE CODE:
4
GLOSSARY:
DATA TYPE VARIABLE NAME USES
string n Stores the name of the
customer.
int units Stores the number of
electricity units consumed.
double bill Stores the final calculated
bill amount, including
surcharge if applicable.
double surcharge A temporary variable used in
calculate() method to store
extra charge (2.5% of bill if
units > 300).
OUTPUT:
5
PROGRAM : 2
Write a program that encodes a word in piglatin. To translate a word into pigLatin, convert the word into
uppercase and then place the first vowel of the original word as a start of the new word along with the
remaining alphabets. The alphabets present before the vowel being shifted towards the end followed by "AY".
Sample Input: London
Sample Output: ONDONLAY
Sample Input: Olympics
Sample Output: OLYMPICSAY
SOURCE CODE:
GLOSSARY:
DATA TYPE VARIABLE NAME USES
string inputString Stores theoriginal input
string entered by the user.
6
string preVowelWord Stores the substring of the
input word that comes
before the first vowel.
string postVowelWord Stores the substring of the
input word that comes after
(or from) the first vowel.
int length Stores the length of the input
string.
int posVowel Stores the position (index) of
the first vowel found in the
input string. Initialized to -1
to indicate no vowel found
by default.
Loop counter used to iterate
int i
through each character of
the input string.
Temporarily holds the
char tmpChar character at position i of the
string during iteration.
Stores the final converted Pig
string piglatinWord Latin word.
OUTPUT:
7
PROGRAM : 3
Write a program to accept a string and display:
(i) The number of lowercase characters (ii) The number of
uppercase characters (iii) The number of special characters (iv)
The number of digits present in the string
SOURCE CODE:
GLOSSARY:
DATA TYPE VARIABLE NAME USES
int lcase Stores thecount of
lowercase characters in the
string.
int Ucase Stores the count of
uppercase characters in the
string.
8
int digits Stores the count of digits in
the string.
int special Stores the count of special
characters (non-letter, non-
digit).
char tmpChar Temporarily stores each
character of the string while
looping through it.
string string Holds the input string
entered by the user.
int length Holds the length of the input
string. Used for loop
iteration.
int i Loop counter to iterate over
the characters of the input
string.
OUTPUT:
9
PROGRAM : 4
Write a program in Java to input a two-dimensional array of size n × m (rows = n; columns = m) and perform
the following tasks: (i) Print the array in matrix form (n × m). (ii) Compute and print the sum of elements of
each row.
SOURCE CODE:
GLOSSARY:
DATA TYPE VARIABLE NAME USES
Stores the sum of elements
int sumRow
in each row.
int rows Holds the number of rows of
the 2D array (entered by
user).
10
int columns Holds the number of columns
of the 2D array (entered by
user).
int array2D 2D array to store the user-
input integers.
int i Loop control variable for
iterating over rows.
int j Loop control variable for
iterating over columns.
OUTPUT:
11
PROGRAM : 5
Create a program toshow the java implementation of the selection sort program.
SOURCE CODE:
GLOSSARY:
DATA TYPE VARIABLE NAME USES
Stores the array of integers
int list
to be sorted.
int len Holds the length (number of
elements) of the array list.
int tmp Temporarily stores a value
while swapping two elements
in the array.
int minIndex Keeps track of the index of
the smallest element in the
unsorted part of the array.
int i Loop control variable used in
both outer and inner loops to
iterate over the array.
12
int j Loop control variable for
scanning the unsorted
portion of the array to find
the minimum element.
OUTPUT:
13
PROGRAM : 6
Write a program to input number and perform a linear search to check if it exists in the array.
SOURCE CODE:
GLOSSARY:
DATA TYPE VARIABLE NAME USES
int searchNumber Stores the number entered
by the user to be searched in
the array.
int foundIndex Holds the index of the
element if found; initialized
to -1 (not found).
int list Array of integers in which the
search is performed.
int i Loop control variable used to
iterate through the array.
OUTPUT:
14
PROGRAM : 7
Define a class named BookFair with the following description: Instance
variables / Data members:
String Bname: stores the nameof the book
double price: stores the priceof the book
Member Methods:
(i) BookFair() : default constructor to initialise data members.
(ii) void Input() : to input and store the name and the price of the book.
(iii) void calculate() : to calculate the price after discount. Discount is calculated based on
the following criteria:
PRICE DISCOUNT
Less than or equal to Rs 1000 2% of price
More than Rs 1000 and less than or equal to Rs 3000 10% of price
More than Rs 3000 15% of price
Write
(iv) void display() : to display the name and price of the book after discount . a main()
method to create an object of the class and call the above member methods.
SOURCE CODE:
15
GLOSSARY:
DATA TYPE VARIABLE NAME USES
String Bname Stores the name of the book.
double price Original price of the book.
double pricediscounted Price after applying the
discount.
Scanner keyboard Used for inputting book
name and price.
double discountPercentage Stores the percentage of
discount based on price slab.
OUTPUT:
16
PROGRAM : 8
Write a class MyDate in Java with the following details:
Instance Variables/Data Members:
Day : stores the day
Month : stores the month
Year : stores the year
Constructor methods: Default constructor: initialises instance variables as day = 1, month = 1,
year = 1900 Parameterized constructor: initialises instance variables with the provided initial
values Write a main method to create an object of the class and call the above member methods.
SOURCE CODE:
17
GLOSSARY:
DATA TYPE VARIABLE NAME USES
int day,dy To store number of
days
int month,mn To store number of
months
int year,yr To store number of
years
OUTPUT:
18
PROGRAM : 9
Write a program calledNumberGuessingGame to play a number guessing game. The program shall generate
a random number between 1 and 100. The player inputs his/her guess, and the program shall response with
“Try a higher number”,“Try a lower number” or “You guessed it in n tries!” accordingly. Also display the
random number in theend.
SOURCE CODE:
GLOSSARY:
DATA TYPE VARIABLE NAME USES
int
secretNumber To store the secret
number
19
int guessNumber To accept the number
guessed by the user
int count To count the number of
attempts made by the user to
guess the secret
number
OUTPUT:
20
PROGRAM : 10
Write a program to display the following menu:
Pattern Menu
=============
1. Triangle
2. Inverted Triangle
3. Exit
Enter your choice:
Let the user select an option. For option 1 and 2, accept the number of rows to be printed using the scanner
class.
SOURCE CODE:
21
GLOSSARY:
DATA TYPE VARIABLE NAME USES
int choice Stores the user’s menu
selection (1: Triangle, 2:
Inverted Triangle, 3: Exit).
int numRows Stores the number of rows
for the selected pattern
(returned by AcceptInput()
method).
int i Loop control variable for
rows (outer loop).
int j Loop control variable for
columns (inner loop).
int rows Stores the number of rows
entered by the user inside
the AcceptInput() method.
22
OUTPUT:
23
PPROGRAM : 11
Write a java programto check whether the given number is a prime number or not. While doing so, demonstrate
the useof the break statement in Java.
SOURCE CODE:
GLOSSARY:
DATA TYPE VARIABLE NAME USES
int num A parameter in the IsPrime
method. It stores the number
to be tested for primality.
A flag variable initialized as
boolean prime true. It becomes false if a
24
divisor of num is found,
indicating that the number is
not prime.
int i Loop control variable used to
check if num is divisible by
any number from 2 to num /
2.
int number Stores the integer entered by
the user. Used in a loop to
repeatedly check if the input
is a prime number.
OUTPUT:
25
PROGRAM : 12
Write a program to calculate and print the sum of each of the following series:
(i) Sum(S) = 2 – 4 + 6 – 8 + ……… - 20
(ii) Sum(S) = x/2 + x/5 + x/8 + ……… + x/20
(Value of x to be input by the user.)
SOURCE CODE:
GLOSSARY:
DATATYPE VARIABLENAME USES
int sum (in SumSeriesOne) Used to store the sum of the
first series, which involves
26
alternating addition and
subtraction of even numbers.
int i Loop control variable used to
generate terms for both
series (even numbers or
denominators)
double sum (in SumSeriesTwo) Used to store the sum of the
second series (which involves
fractional values); double is
used for decimal precision.
double x (in SumSeriesTwo) The input value from the user,
used as the numerator in the
second series terms (x/2 + x/5
+ ...).
int x (in main) Local variable to store the
user-entered integer value,
which is passed as an
argument to SumSeriesTwo.
OUTPUT:
27
PROGRAM : 13
Write a program in Java that reads month number and the year in yyyy format and displays number of days in that month.
SOURCE CODE:
28
GLOSSARY:
DATA TYPE VARIABLE NAME USES
int month To store number of months
int year To store number of years
boolean leapYear To check whether the year
entered is a leap year or not
OUTPUT:
29
PROGRAM : 14
Adventure Game
SOURCE CODE:
30
GLOSSARY:
USES
DATA TYPE VARIABLE NAME
Scanner Reads input from the user
SC
during the game.
Int
Stores the first user choice:
Choice1
forest or river.
Stores the second user choice if
Int Choice2 the forest path is chosen (fight
wolf or run away).
Stores the second user choice if
int Choice3 the river path is chosen (take
boat or continue walking).
OUTPUT :
31
CONCLUSION
This project successfully demonstrates the implementation of a
Java-based program using object-oriented concepts and
graphical user interfaces. The program was designed to be user-
friendly, interactive, and efficient, fulfilling the requirements of
the given problem statement.
Through this project, I gained a deeper understanding of core
Java features such as classes and objects, inheritance, event
handling, loops, arrays, and GUI components. It also helped me
improve my problem-solving skills and logical thinking while
working on real-time scenarios.
Overall, the project was a valuable learning experience. It not
only enhanced my knowledge of Java programming but also
strengthened my ability to design and develop applications that
are practical, engaging, and efficient.
32
BIBLIOGRAPHY
BOOKS USED: ‘LOGIX COMPUTER APPLICATIONS’
APPS USED: ‘CHAT-GPT’
33