computer class 10 icse project
computer class 10 icse project
Class: 10 Aravallis
Roll No: 6
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.
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.
Computer 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
4
• The user needs to remember all the instruction codes.
(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:
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.
5
Limitations of Assembly language:
BASIC, C/C++, Java and Python are some popular examples of high level
languages.
• 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.
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.
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.
7
The compiler is comparatively faster than the interpreter but sometimes, it
becomes difficult to correct errors since it displays all the errors together.
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.
Procedure Oriented
Language
1. Structure 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.
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.
• 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.
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.
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.
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:
The emphasis is put on the function The emphasis is put on the data rather
rather than the data. than the functions.
• 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.
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.
The Object Oriented Programming (OOP) has the following basic principles:
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.
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.
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.
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
Encapsulation
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.)
(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.
There are many reasons for preferring Object Oriented Programming over
Procedure Oriented Programming. Some of them are mentioned below:
• Modularity is achieved.
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:
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).
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.
• 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.
• Java is case sensitive. The upper case and lower case letters are distinguished
by the language.
You know that compiler and interpreter are used in various computer languages.
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 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.
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 *).
Now, your program can use only the functions of the scanner class of the util
package. Other classes of the package will be ignored.
20
java.awt To support abstract window tool kit
and managing GUI (Graphic User
Intertace.)
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.
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).
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.
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:
• 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.
22
2. As far as possible, the class name should be meaningful and relevant to the
program.
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;
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:
Features of BlueJ
• 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
• Double click the Blue] icon available on the desktop to start Java.
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.
• 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.
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.
• Select the complete program either by dragging the mouse or by using 'Ctrl +
A' key.
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
1 It is a comment 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.
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.
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
int round = 1;
while (round == 1)
System.out.println("1. SHIRTS");
System.out.println("2. T-SHIRTS");
System.out.println("3. PANTS");
switch (categoryChoice)
case 1:
30
bill += buyClothing("SHIRTS", ob);
break;
case 2:
break;
case 3:
break;
default:
round = ob.nextInt();
31
System.out.println("3. LEE");
System.out.println("6. NONE");
switch (brandChoice)
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
break;
32
case 6:
break;
default:
return price;
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:
if (price > 0)
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