0% found this document useful (0 votes)
21 views

computer class 10 icse project

The document is a project by Anika Kariwala for ICSE Class 10 Computer Science, covering the Principles of Object Oriented Programming and Information about Java. It includes acknowledgments, a preface, detailed explanations of programming languages, and a source code example for a shopping mall program. The project aims to provide a comprehensive understanding of programming concepts and their practical applications.

Uploaded by

myabditory58
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

computer class 10 icse project

The document is a project by Anika Kariwala for ICSE Class 10 Computer Science, covering the Principles of Object Oriented Programming and Information about Java. It includes acknowledgments, a preface, detailed explanations of programming languages, and a source code example for a shopping mall program. The project aims to provide a comprehensive understanding of programming concepts and their practical applications.

Uploaded by

myabditory58
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 39

ICSE CLASS 10 COMPUTER

SCIENCE PROJECT 2024-25


By Anika Kariwala

Class: 10 Aravallis

Roll No: 6

School: Anand Niketan Satellite Campus


Index

Serial Number Topic Page Number


1. Index 1
2. Acknowledgement 2
3. Preface 3
4. Principles of Object 4-17
Oriented
Programming
5. Information About 18-29
Java
6. Source Code - The 30-34
Fashion Avenue Mall
7. Screen Outputs 35-37
8. Bibliography 38

1
Acknowledgement
First and foremost, I would like to thank my teacher, Mrs. Bhagyashree for giving
me the chance to work on this project. This project gave me the opportunity to
study and gain invaluable knowledge about the topic. I am very well-versed with
the Principles of Object Oriented Programming and Java now. I would also like to
thank my teacher for all the guidance, support and insights she gave me to put
forth my best work.

Secondly, I would like to thank my parents for providing me with the resources to
work on this project. They also helped and supported me throughout the entire
process.

Last but not least, I would like to acknowledge the authors of the textbooks and
online resources that provided the foundation of knowledge upon which this
project was built.

Thank you everyone.

2
Preface
This project covers the topics Principles of Object Oriented Programming and
Information about Java in great detail. Starting from the basics, the project
explains each and every concept with comprehensive, easy to understand
examples. After covering the theoretical concepts, the project encompasses the
source code for a program made for running a shopping mall called The Fashion
Avenue Mall with the outputs displayed. The code demonstrates how the
theoretical knowledge provided above can be applied practically in an efficient
manner.

3
Principles of Object Oriented
Programming
INTRODUCTION
Computer is an electronic device that accepts instructions in a specific language.
Hence, it is very difficult to establish communication between the user and the
computer if he/she is not aware of computer language. This is the reason why
learning computer language is very essential for working on the computer.

TYPES OF COMPUTER LANGUAGES


The computer languages are basically categorised into two levels. They are:

Computer languages

Low Level Languages

High Level Languages

1. Low Level Languages

The low level languages are the type of computer languages in which the
computer recognizes the instructions, without conversion into any other form.
They are sort of cryptic languages which are not directly understood by the users.
These type of languages were used in the early computers when only the experts
were able to code the instructions. The low level languages are further
categorised into two types:

• Machine Language

It is the form of computer language in which instructions are coded in terms of


binary digits (bits), i.e., in the form of zeroes and ones (0's and 1's). This form of
binary instructions is also called the machine code or the object code.The
computer understands the machine codes easily (ie. it does not need to be
transformed or converted into any other form). The only advantage of this
language is that the program executes faster because the machine code is
directly operated by the CPU.

Limitations of Machine language:

4
• The user needs to remember all the instruction codes.

• The error detection and correction is difficult.

• It is a machine dependent language.

(The user must be aware of the internal hardware structure of the computer for
coding instructions; and so it is known as a machine dependent language.)

• Assembly Language

A language, in which the instructions are coded in terms of mnemonics and op-
codes (or operation codes), is known as an assembly language. The mnemonics
are the abbreviated form of the instructions, used for writing a program.
Whereas, op-codes are the numeric codes of the instructions that are actually
fed to the computer for execution. The instructions in assembly language are
readable to some extent as compared to machine language. Below are some
mnemonics and op-codes, illustrated for reference:

MNEMONICS DESCRIPTION OP - CODES

LD A Enter the value in A 3B

LD B Enter the value in B 73

ADD A, B Add the values of A and C2


B

ST C Store the sum in C 3F

HLT Stop EF

The instructions given in assembly language are not directly understood by the
computer. Hence, a translator is required to convert the instructions coded in the
assembly language to its equivalent machine code which is known as the
Assembler.

Assembly Language ➡ Assembler ➡ Machine Code

Advantages of Assembly language:

• It is easier to write the instructions as compared to machine language.

• The error detection and correction is also comparatively easier.

• The code can easily be modified.

5
Limitations of Assembly language:

• It is also a machine dependent language.

• The users need to remember all the mnemonics.

• A translator is required to convert the instructions into machine code.

2. High Level Language Languages

To overcome the disadvantages of low level languages, the experts (System


Developers) developed another category of languages, which are referred to as
the High Level Languages (HLL). These languages allow the user to write the
instructions in simple English phrases or sentences. It also uses common English
words and mathematical symbols. Thus, it makes the instructions easier to
understand in the user's native language. It allows a user to write the instructions,
even if he is not aware of the hardware architecture of the computer. The
programming style and context is comparatively easier to learn. The entire code
focuses on the specific program to be created.

BASIC, C/C++, Java and Python are some popular examples of high level
languages.

Advantages of High Level language:

• It is a machine independent language.

• The instructions can be written using English words or phrases.

• It is easier to understand and develop the program logic.

• The error detection and correction is easier.

Disadvantages of High Level language:

• It requires a translator to convert the source code (program) into machine


code.

• The machine code of high level instructions might be less efficient than the
machine code generated from assembly language instructions.

One of the major disadvantages of the high level language is that the machine
cannot understand this language directly (a machine understands only machine
language). Hence, we need to convert the instructions written in high level
language into their equivalent instructions, in machine language, so that they can
be operated upon by the CPU. The translators/ language processors used to

6
perform the mentioned task, are referred to as Compilers and Interpreters. Let us
understand the functions of these translators.

COMPILER AND INTERPRETER

A program in high level language needs to be converted into machine code


(binary code) so that the computer can understand the instructions for
processing. If the program contains any error then it must be corrected for
successful execution.

The conversion of high level language (source code) to machine language


(binary code) can be done in two ways; either by using a Compiler or an
Interpreter.

A software that accepts the whole program written in high level language and
converts it into its equivalent program in machine language, is known as the
compiler.

The program, which the compiler uses for conversion, is known as the source
program or source code. The program converted into the machine language is
known as the object program or object code.

High Level Language ➡ Compiler ➡ Machine Language

Source Program (Source Code) ➡ Translator (System Program)➡ Object


Program (Object Code)

A compiler is designed exclusively to convert a program written in a specific high


level language. This means that each high level programming language would
require a separate compiler for conversion. For example, a FORTRAN compiler is
capable of translating only a FORTRAN program. A computer system may have
more than one compiler for more than one high level language.

The software which converts the instructions written in high level languages into
their equivalent instructions in machine language, line by line or statement by
statement, is known as the Interpreter. If an error is found on any line, the
execution stops there till it is corrected. This process of correcting errors is easier
but the program takes more time to execute successfully.

An Interpreter is generally used in microcomputers. It helps the programmer find


out the errors and correct them before the control moves to the next statement.
Compilers and interpreters are basically system softwares, which are also known
as the language processors.

7
The compiler is comparatively faster than the interpreter but sometimes, it
becomes difficult to correct errors since it displays all the errors together.

High Level Language (Source Program) ➡ Interpreter (System Program) ➡


Machine Language (Object Program)

Note: A compiler is not capable of diagnosing logical errors. It can only identify
the syntax errors in the program.

COMPILER INTERPRETER

It converts the whole source program It converts the source program into
into the object program at once. the object program one line at a time.

It displays the errors for the whole It displays the errors, one line at a time
program together, after the and only after debugging that error the
compilation. control goes to the next line.

High Level Languages

Structure Oriented Object Oriented


Language Language

Procedure Oriented
Language
1. Structure Oriented Programming Language

Structure Oriented language uses a modular approach to improve the clarity,


quality and the development time of the programming steps. It uses various
logical structures like the structure of selective control flow, structure of looping
block, structure of subroutines or functions etc. ALGOL and PASCAL are
examples of structure oriented programming languages.

2. Procedure Oriented Programming Language

The procedure oriented approach allows the users to develop their logic by using
a number of functions that would enhance the program's productivity.

8
Conventional programming using high level languages such as BASIC, COBOL,
FORTRAN and C are commonly known as Procedure Oriented Programming
(POP) languages.

Here, a sample flow diagram is illustrated to depict the procedural programming


approach:

Procedure Oriented Programming (POP) basically consists of a list of instructions


for the computer to follow and these are organized into groups, known as
functions. We normally use a flow chart to organize these actions and represent
the flow of control from one function to another. In Procedure Oriented
Programming, most of the functions share global data and this data moves more
openly around the system from one function to the other.

When we deal with a program containing many functions, important data items
are globally used by all the functions, however, a function may contain its own
local data to deal with logical situations. The organisation of data and its function
in POP can be illustrated as:

9
In this system, the global data are loosely attached to the functions. They keep
floating throughout the program. In order to make any change in the function, you
may need to reschedule the associated data values.

This may affect the normal sequencing of the program logic.

(In Procedure Oriented Programming System, the emphasis is on Functions


rather than Data Items.)

Characteristics of Procedure Oriented Programming

• Emphasis is on functions (logical steps).

• Functions share global data.

• Data values can keep floating from one function to another.

• It uses top down approach of programming.

Limitations of Procedure Oriented Programming (POP)

• As data values are global to all the functions, you may require to make
necessary changes in all the functions, in case of any change in the data values.

• It is not suitable to solve complex problems in real situations.

3. OBJECT ORIENTED PROGRAMMING (OOP)

Procedure Oriented Programming basically consists of an organised group of


instructions known as function. Normally, flow charts are used to organise the
instructions and guide the movement of control from one function to another.
Most of the functions share global data that flows freely throughout the program
without any restriction.

10
In contrast to Procedure Oriented Programming, Object Oriented Programming
(OOP) is an approach to standardise the programs by creating partitioned
memory areas for both the data and the functions. It does not allow data to flow
freely from one function to another. In this system, the complete problem is
decomposed into a number of entities called the objects. Each object includes a
set of data items and related functions. The data values of an object are
applicable only within the functions associated with that object. The resident data
can never be handled by the external functions.

In this way, the data are protected and secure from being troubled by external
sources. This feature allows object oriented approach to be a powerful tool in
programming. The organisation of data and functions in Object Oriented
Programming (OOP) can be illustrated as:

The different Object Oriented Programming languages commonly being used are
C++, Java, Python, Smalltalk, Ruby, Eiffel, etc.

(An Object Oriented Programming (OOP) is a modular approach, which allows


the data to be applied within a stipulated program area. It also provides the
reusability feature to develop productive logic, which means to give more
emphasis on data.)

Features of Object Oriented Programming (OOP)

Some of the features of Object Oriented Programming are listed below:

• It gives importance to the data items rather than the functions.

11
• It makes the complete program/problem simpler by dividing it into a number of
objects.

• The objects can be used as a bridge to have data flow from one function to
another.

• The concept of data hiding enhances the security in programs.

• It is highly beneficial to solve complex problems.

Differences between Procedural Oriented Programming (POP) and Object


Oriented Programming (OOP)

Now, you have learnt that both are programming processes where OOP stands
for 'Object Oriented Programming' and POP stands for 'Procedure Oriented
Programming. They are different types of high-level programming languages with
different approaches. Some of the differences between them are mentioned as
under:

Procedural Oriented Programming Object Oriented Programming

The emphasis is put on the function The emphasis is put on the data rather
rather than the data. than the functions.

It allows data to flow freely throughout The data is restricted, to be used in a


the program. specific program area.

It follows top-down programming It follows bottom-top programming


approach. approach.

KEYWORDS RELATED TO OBJECT ORIENTED PROGRAMMING

• Object: It is a unique entity, which contains data and functions (characteristics


and behaviour) together in an Object Oriented Programming (OOP) Language.

• Real World Object: The objects that we experience or use in our day to day life.
Each real world object contains characteristics and behaviour. The characteristics
basically comprises the parts of its body or specifications whereas behaviour
refers to the purpose of its use or its function.

• Software Objects: A software object may be defined as an object that is created


while writing a Java program. When we compare a software object with the real

12
world object then the characteristics and behaviours of real world objects are
referred to as the data members and member methods (functions) of the
software objects, respectively.

• Class: The class is a template or blueprint for similar type of objects.

Each object of a class possesses some attributes and common behaviour as


defined within the class. Thus, a class is also referred to as a blueprint or
prototype of an object.

BASIC PRINCIPLES OF OBJECT ORIENTED PROGRAMMING (OOP)

The Object Oriented Programming (OOP) has the following basic principles:

• Data Abstraction • Inheritance • Polymorphism • Encapsulation

Data Abstraction

In real life situations, you might have noticed that we do not require to know the
details of the technologies to operate any system.

For example, a digital camera is used to capture a photograph. It simply provides


a number of buttons and switches to control the operations needed to take the
photograph. In fact, these buttons make the working so easy that anybody could
operate the camera, even though he/she may not be aware of the technology.

Have you ever thought of how the camera manages to take photographs or what
mechanism is followed in the internal part of the camera?

You may not be able to answer such questions because you are unaware of
technology used inside the camera. So, you may say that we use only the
essential features of the camera to take a photograph without knowing the
internal mechanism.

('Data Abstraction' is an act of representing the essential features without


knowing the background details. It is always relative to the purpose or the user.)

13
It may be noted that the abstraction of an object depends upon the area of
applications.

Inheritance

You might have studied the term 'Heredity' in biology, which means the
transmission of genetically based characteristics from parents to the offspring.

We inherit thousands of characteristics (inheritable features) from our parents


who in turn, had inherited those from their parents, and so on.

Similarly, a class acquires some properties from another class. This is possible by
deriving a new class from the existing class. The new class will have the
combined features of both the classes. The class that gets inherited to another
class is known as the Base class or the Super class. The class that inherits from a
Base class is known as the Derived class or the Sub-class or Target.

Let us take an example of a class 'Animal' which can be broadly classified into
'Carnivores' (flesh eating animals) and 'Herbivores' (plants eating animals). So,
you will find that some of the characteristics or properties of the class. 'Animal'
will be inherited by the classes Carnivores and Herbivores.

During inheritance, the elements of the base class are shared by the derived
class. As a result, it may happen that the elements performing a specific task in
the base class can be used to perform another task in the derived class. This
feature is called Reusability.

(The term Inheritance means to link and share some common properties of one
class with the other class. This can be done by extending a class into another
class and using thus using both it.)

Polymorphism

You know that a single word can have many meanings.Similarly, an operation may
show an entirely different behaviour for a different set of data and environment.

Let us take an example of the English word 'duck'. The word 'duck' defines a water
bird with a broad bill, short legs and webbed feet whereas, the same word 'duck'
in a cricket match means a batsman who got out with no score. With the
reference to the above examples, you can notice that the same word'duck' is
used for two different purposes. Similarly, you can find many such examples in
real life situations also. With reference to Object Oriented Programming, if the
function name is Volume(), then you can calculate the volume of different

14
geometrical solid figures viz. a cube, a cuboid, a sphere, a cylinder by using
different parameters, as shown below:

Volume( )

Volume(side) Volume(radius)
Object:Cube Object:Circle

Volume(length, breadth,
height)
Object:Cuboid

Polymorphism is one of the Object Oriented Programming (OOP) principles that


allows the user to use a function for multiple purposes. It is implemented by using
function overloading. Thus, function overloading is a technique to use a number
of functions, with the same name, having different parameters. In the illustration
shown above, three functions are defined with the same name 'volume'. Hence,
they are overloaded. The execution of these functions will depend upon the data
types and number of parameters.

(The term 'Polymorphism' is defined as the process of using a function/method


for more than one purpose.)

Encapsulation

Encapsulation is another feature of the Object Oriented Programming which


restricts the free flow of data from one object to another. The data and functions
are wrapped together in an object such that the data can only be accessed in the
associated functions.

Thus, we can say that the data is kept hidden and cannot be accessed directly
outside the object, although it is available in the same program. The following
illustration of Encapsulation depicts how the data and functions are inter-linked:

15
With reference to the above context, it could be inferred that the state and
behaviour are encapsulated in an Object Oriented Programming to prevent their
isolation from each other.

(The system of wrapping data and functions into a single unit is known as
Encapsulation.)

Thus, encapsulation is helpful in Object Oriented Programming in the following


ways:

(a) The source code of an object could be maintained independently.

(b) The object maintains the privacy of the data members. However, the changes
that take place in the methods do not affect the other object.

Benefits of Object Oriented Programming

There are many reasons for preferring Object Oriented Programming over
Procedure Oriented Programming. Some of them are mentioned below:

• The reusability of the program code is enhanced.

• The software quality and performance are improved.

• Modularity is achieved.

• Data abstraction makes the software easier to handle.

• Software for complex tasks can easily be developed.

Limitations of Object Oriented Programming

16
Even though, OOP languages are preferred in solving problems ranging from
simple to complex, there are some limitations of Object Oriented Programming,
which are mentioned as under:

• Object Oriented Programming languages require intensive testing processes.

• Solving problems is more time consuming as compared to Procedure Oriented


Programming.

17
Information About Java
INTRODUCTION
Java is an object oriented programming language developed primarily by James
Gosling and his colleagues at Sun Micro Systems. The language was initially
called Oak (named after the Oak trees outside Gosling's office).

In 1991, the Sun Micro Systems (Broomfield, Colorado, USA) developea a


complete language named Java, as a part of research work to develop software
for consumer electronics. It was developed as a full fledged programming
language in which one can accomplish the same sort of tasks and solve similar
problems in other programming languages such as BASIC, C++, etc. The
platform's independence JAVA is one of the most significant advantages that
JAVA has over other languages. It has the capability of moving easily from one
computer system to another.

JAVA, being an object oriented programming language, has adopted many


features of C++. Originally, JAVA was designed to execute applets (the programs
executed by using web browser). But gradually, the language gained wide
acceptance as a programming language, replacing C or C++.

James A. Gosling, (born on May 19, 1955, near Calgary, Alberta, Canada) is a
famous software developer. In 1977, he completed his graduation as a B.Sc. in
Computer Science from the University of Calgary. In 1981, he was honoured a
Ph.D in Computer Science from Carnegie Mellon University. He developed many
compilers and mail systems. Since 1984, he has been associated with Sun Micro
Systems and developed Java programming language in 1991.

He was also selected to the United States National Academy of Engineering for
this achievement. In 2007, he was appointed an Officer of the "Order of Canada",
which is Canada's highest civilian honour.

BASIC FEATURES OF JAVA

Java possesses the following features:

• Java is an object oriented programming language.

• Java programs are both compiled as well as interpreted.

• It can access data from a local system as well as from the Internet.

18
Java program is written within a class. The variables and functions are declared
which are defined within the class.

• Java programs can create Applets (the programs executed inside the Java
based web browser) and Applications (the programs developed by the users) like
any other programming language.

• Unlike C++, Java doesn't require any preprocessor #) or inclusion of header


files for creating a Java application program.

• Java is case sensitive. The upper case and lower case letters are distinguished
by the language.

JAVA COMPILER AND INTERPRETER

You know that compiler and interpreter are used in various computer languages.

Each computer language uses either the compiler or interpreter to convert


source code into object code. Java language treats compiler and interpreter in
different ways.

Java compiler is a software that converts the source code into an intermediate
binary form called the byte code. The byte code is a common binary form of the
program and works irrespective of the machine on which it is to be executed.

Further, Java interpreter accepts the byte code and converts it into machine
code suitable to the specific platform.

JAVA INTERPRETER AS VIRTUAL MACHINE

Java interpreter converts byte code into machine code. It is also known as Java
Virtual Machine TVM). It not only converts the byte codes received from a Java
source code but also converts the byte codes of other non-Java environment.

Though, Java interpreter is a software but due to its nature of conversion of byte
codes from multiple source codes, it is referred to as a virtual machine.

JAVA LIBRARIES IN JDK 1.3

Java package is a collection of various classes. Each class contains different


functions. In case you want to use a specific function of a class within your
program, then the package containing the function needs to be included in your
program. A package can be included in the program by using a keyword

'import'. The syntax of importing a package is as listed below:

19
• import java.io.*;

• import java.util.*;

The packages javaio and java. util' include the classes related to 1/0 and utility
functions respectively. The asterisk *) sign denotes that all the classes of the
concerning package will be made available for use in your program.

Note: 'java.lang' is the default package of Java programming (JDK), i.e., it will
automatically be imported in any Java program to avail its classes and functions.

However, if a specific class is to be used in the program then the specific class
name must be used in place of *).

For example, import java.util.Scanner;

Now, your program can use only the functions of the scanner class of the util
package. Other classes of the package will be ignored.

Some of the packages of Java Development Kit are listed below:

java.lang To support classes containing


String/Character, Math, Integer,
Thread, etc.

java.io To support classes to deal with input &


output statements.

java.applet To support classes to generate applet


- specific environment.

java.net To support classes for network related


operations and dealing with URL
(Uniform Resource Locator.)

20
java.awt To support abstract window tool kit
and managing GUI (Graphic User
Intertace.)

java.txt For localising text elements such as


dates, times and currency, etc.

java.math To support mathematical functions


such as square roots (integer &
decimal both.

JAVA RESERVED WORDS

Java reserved words or the keywords are the words which carry special meaning
to the system compiler. These words are basically used for writing a Java
statement. Such words cannot be used for naming a variable in the program.

Some of the reserved words or keywords are listed as below:

case switch else break static

do const throws float char

try int double void goto

for while new Import boolean

long if byte package private

catch short public class default

DIFFERENT TYPES OF JAVA PROGRAMMING

Basically, there are two different platforms for writing Java programs. They are:

• Java Application

• Java Applet

21
Java Application (Stand Alone System)

Java application is a Java program, developed by the users, that run, stand alone
in a client or server. Java instructions are interpreted with the help of Java Virtual
Machine (VM) and are allowed to run in their native environments like other
languages. Java applications have complete access to all the resources in the
computer as a development technology for 'Stand Alone' (desktop application).

Java Applets (Internet Applets)

An applet is a program written in the Java programming language that can be


included in an HTML page, in the same way an image is included in a page.

When you use a Java technology-enabled browser to view a page that contains
an applet, the applet's code is transferred to your system and executed by the
browser's Java Virtual Machine (IVM). Java applets were introduced in the first
version of the Java language in 1995.

Basic Structure in Java Programming

The basic format of writing a program in Java is entirely different from the other
languages. So, it is essential to know the following points while writing a Java
Program:

• Comments in a program: The comment statement is a non executable


statement in Java. It is included for the sake of the users to understand what
action is going to be taken in a program or statement.

• Declaration of class: It contains the word, access specifier (i.e., public). It also
defines the keyword 'class' which is followed by a meaningful class name.

For example, if you are writing a program to find the sum of two numbers, then it
could be written as public class Sum. Conventionally, the class name starts with
an uppercase letters.

• Declaration of main function: The main() function encloses the programming


statements within the opening and closing curly braces ( }. The main) function is
further enclosed within / under class heading.

• The termination of each statement must be indicated with a semi-colon.

• The closing of curly braces indicates the closing of a block of statements,


function and class.

Note: 1. The class name must not be a Java reserved word.

22
2. As far as possible, the class name should be meaningful and relevant to the
program.

OUTPUT STATEMENT IN JAVA PROGRAMMING

The statement which is used to get the output of the program or to display
messages on the screen, is given as:

System.out.println;

Syntax: <Output statement> <message or message with a variable> For example,


System.out.printIn("Welcome to Java Programming");

Output: Welcome to Java Programming

The message needs to be written within double quotes (" ") enclosed within
braces. If you want to display a message along with a variable then it could be
written as:

System.out.println("The sum of two numbers is" + p);

(Here, p is the variable, which contains the result of the execution.)

Output: The sum of two numbers is 45.

Note: When a message is to be displayed along with a variable, they must be


separated with '†' (plus) sign.

JAVA PROGRAMMING WITH BLUEJ

Blue] is a free Java environment from Monash University, Australia. It is a window


based platform for Java Development Kit 0DK). JDK 1.5 or 1.6 version needs to be
installed before installing Blue]. We can also get more information about Blue]
through the website www.bluej.monash.edu. Blue] can be downloaded from the
website www.bluej.org, free of cost.

Features of BlueJ

Some of the features of Blue] are given below:

• The compilation as well as the execution of the program is comparatively easier


than JDK 1.5 or 1.6 platform.

• It is a window-based platform where the user can perform the tasks more
conveniently (by selecting and clicking the mouse button).

23
• When you declare a class, it produces a sample program for the user to give a
brief idea of programming.

• Debugging can also be done easily as it indicates the errors at the bottom pane
of the same window.

• It also supports the syntax of the program which is written on JDK 1.5 or 1.6

(DOS based) platform.

HOW TO START BLUEJ

• Double click the Blue] icon available on the desktop to start Java.

• The first Blue] window appears on the screen as shown.

The screen shows 'Project' as the first menu item. Project is like a folder or
directory. A project may contain a number of Blue] classes as program files.

• Click 'Project' and select 'New Project'.

• Enter the project name (say, Sample) and finally click on the ‘OK’ button.

24
The Project with the name 'Sample' will appear on Blue] window.

Now, click 'New Class' and enter the class name in the text box.

• Finally, click OK to create the class icon.

Thus, a class with the given name (For example Welcome) will be created, i.e., a
program file in which your program will be saved, on the hard disk is created.

25
On double clicking the class icon, 'Welcome', a sample program is displayed.

This program is only provides assistance to the user.

• Select the complete program either by dragging the mouse or by using 'Ctrl +
A' key.

• Delete the sample program by pressing DEL or BACKSPACE key.

• Type your program on the blank screen.

26
• After completing the program, click on 'Compile' button.

If your program is error free, a message will appear on the screen at the bottom
pane as 'Class compiled - no syntax errors'. It means, your program is ready to
execute in the computer.

27
Description of different lines of the Program

Line Number Description

1 It is a comment line.

2 Description of the class (public class Welcome). Here, public


keyword is optional. A class is public by default.

3 Starting of the class block with opening brace [.

4 Header declaration of the main class. Program execution starts


with this line.

5
Starting of main function block with opening curly brace {.

6 -10 These are the executable output statements which display the
messages enclosed in brackets on the screen.

11 End of the main function with closing curly brace ).

12 End of class block with closing curly brace }.

28
EXECUTION OF JAVA PROGRAM

When the class is compiled and shows a message 'no syntax error', it means that
the program is error-free and is ready for execution. Close the window and follow
the steps given below:

• Select the class icon (Welcome) and click the right button of the mouse. A drop
down menu will appear.

• Select and click the option 'void main (String args I I).

A 'Method Call' dialog box will appear on the screen. Click Ok.

Now, the result will be displayed on the screen.

MODIFICATION IN JAVA PROGRAM

In case, you want to edit the program, double click the class icon. The program
will appear on the screen. Make the necessary changes and recompile your
program. If no syntax error is displayed on the screen, it means, your program is
error-free. Close the class window and proceed for execution.

29
Source Code - The Fashion
Avenue Shopping Mall
import java.util.Scanner;

class Project

public static void main(String[] args)

Scanner ob = new Scanner(System.in);

System.out.println("\fWELCOME TO THE FASHION AVENUE MALL - YOUR


ULTIMATE DESTINATION FOR FASHION, STYLE, AND ELEGANCE!");

System.out.println("Discover the latest trends and redefine your wardrobe


with us...");

double bill = 0.0;

int round = 1;

while (round == 1)

System.out.println("WHAT WOULD YOU LIKE TO BUY TODAY?");

System.out.println("1. SHIRTS");

System.out.println("2. T-SHIRTS");

System.out.println("3. PANTS");

int categoryChoice = ob.nextInt();

switch (categoryChoice)

case 1:

30
bill += buyClothing("SHIRTS", ob);

break;

case 2:

bill += buyClothing("T-SHIRTS", ob);

break;

case 3:

bill += buyClothing("PANTS", ob);

break;

default:

System.out.println("Oops! It seems you've entered an invalid choice.


Please select a valid option from the list.");

System.out.println("ENTER 1 IF YOU WANT TO CONTINUE SHOPPING,


ELSE ENTER 0");

round = ob.nextInt();

System.out.println("YOUR TOTAL BILL AMOUNT IS: Rs." + bill);

System.out.println("THANK YOU FOR CHOOSING OUR MALL FOR YOUR


SHOPPING NEEDS. LOOK FORWARD TO SEEING YOU AGAIN!");

private static double buyClothing(String clothingType, Scanner scanner)

System.out.println("SELECT YOUR FAVOURITE BRAND:");

System.out.println("1. JACK & JONES");

System.out.println("2. UNITED COLOURS OF BENETTON");

31
System.out.println("3. LEE");

System.out.println("4. TOMMY HILFIGER");

System.out.println("5. ALLEN SOLLY");

System.out.println("6. NONE");

int brandChoice = scanner.nextInt();

double price = 0.0;

switch (brandChoice)

case 1:

price = selectColorAndPrice(clothingType, "JACK & JONES", scanner);

break;

case 2:

price = selectColorAndPrice(clothingType, "UNITED COLOURS OF


BENETTON", scanner);

break;

case 3:

price = selectColorAndPrice(clothingType, "LEE", scanner);

break;

case 4:

price = selectColorAndPrice(clothingType, "TOMMY HILFIGER",


scanner);

break;

case 5:

price = selectColorAndPrice(clothingType, "ALLEN SOLLY", scanner);

break;

32
case 6:

System.out.println("No purchase made. Enjoy your day!");

break;

default:

System.out.println("Oops! It seems you've entered an invalid choice.


Please select a brand from the options provided.");

return price;

private static double selectColorAndPrice(String clothingType, String brand,


Scanner scanner)

double price = 0.0;

System.out.println("SELECT YOUR FAVOURITE COLOUR FOR " +


clothingType + " FROM " + brand + ":");

System.out.println("1. BLACK - Rs.1500");

System.out.println("2. WHITE - Rs.1500");

System.out.println("3. BLUE - Rs.1500");

System.out.println("4. GREY - Rs.1500");

int colorChoice = scanner.nextInt();

switch (colorChoice) // Assuming all colours have the same price for
simplicity

case 1:

price = 1500.0;

33
break;

case 2:

price = 1500.0;

break;

case 3:

price = 1500.0;

break;

case 4:

price = 1500.0;

break;

default:

System.out.println("Oops! It seems you've entered an invalid choice.


Please select a colour from the options provided.");

if (price > 0)

System.out.println("HOW MANY PIECES WOULD YOU LIKE TO


PURCHASE?");

int quantity = scanner.nextInt();

price *= quantity;

return price;

34
Screen Outputs
1. The program will first display this on the screen and you are to choose
which item you would like to purchase.

2. After choosing the item, you may pick your favourite brand out of the 5
options provided or you may press 6 and then 0 to exit the program if you
don’t want to make a purchase.

3. After picking your favourite brand, you may choose your favourite colour.

35
4. After choosing your favourite colour, you may enter how many pieces you
would like to purchase.

5. After deciding how many pieces to purchase, you can either end your
shopping spree by entering 0 or continue shopping by entering 1.

36
6. When you decide to end your shopping spree, your bill will be displayed
and the program will get terminated.

7. If you continue shopping, the whole process with all of the options will be
repeated.

37
Bibliography
1. ICSE UNDERSTANDING COMPUTER APPLICATIONS with BlueJ
- Class IX Textbook
2. https://www.theknowledgeacademy.com/blog/principles-of-
object-oriented-programming/
3. https://www.javatpoint.com/what-is-object-oriented-
programming
4. https://www.w3schools.com/java/java_intro.asp
5. https://www.geeksforgeeks.org/introduction-to-java/

38

You might also like