Module 1 ITE4 Computer Programming 2 1.20 Ortiz Rolly
Module 1 ITE4 Computer Programming 2 1.20 Ortiz Rolly
Course Module
2020
ITE 4 – Computer Programming 2
VISION
A provide of relevant and quality education to a
society where citizens are competent, skilled,
dignified and community- oriented.
MISSION
An academic institution providing technological,
professional, research and extension programs to
form principled men and women of competencies
and skills responsive to local and global
development needs.
QUALITY POLICY
Northwest Samar State University commits to
provide quality outcomes-based education,
research, extension and production through
continual improvement of all its programs, thereby
producing world class professionals.
CORE VALUES
Resilience. Integrity. Service. Excellence.
Somehow the comprehensive acitivities on this module Computer Programing 2 is a big help
to the learners because of it’s different issues and topic presented and discussed.
This module is designed for students’ who wishes to learn advance computer programming
using java language and will view as their foundation of learning program specialization.
We are not too late for this technology; there still hope for one of us,
instead rise and go for the modern technologies…
Rationale
This module contains comprehensive exercises in java programming
which guide them to learn how to create programs, understand problem, test
and debug specific activities and assignments.
Course Description: The course covers the use of general purpose programming language to
solve problem. The emphasis is to train students to design, implement, test, and
debug programs intended to solve computing problems using advance
programming.
This course teaches the students on to how to develop new computer
programs using array, string, structure, pointers, heap, stacks, memory,
polymorphism and inheritance.
At the end of the course, each students are required to design a program
that maybe implemented as a solution to a given problem with the topics array,
string, structure, pointers, heap, stacks, memory, polymorphism and
inheritance. Also submit all activities (i.e. laboratory/hands-on exercises,
classroom activities, and performance activities).
Course Outcomes:
At the end of the course, your students must be able to:
• Create, declare, determine, implement, test and debug a program, using array,
string, structure, pointers, heap, stacks, memory, polymorphism and inheritance.
• Assess and recommend revisions to another program’s code.
Course Content:
As explained above, ITE 4 introduces students the concept, theories, principles and
practice, discusses the functions to come up interventions addressing problems.
The table below shows the outline of the topics to be discussed in the lecture per week
vis-à-vis the course outcomes. It is designed based on the course syllabus approved by the
college Dean in the College of Computing and Information Sciences.
Course Requirements:
As evidence of attaining the course outcomes, the student has to do and submit
the following:
• Design a program that maybe implemented as a solution to a given problem.
Student must design and implement appropriate solution by applying their
knowledge of: fundamental of programming, user-defined methods which is
recursive and parameter passing mechanisms. (Individual project).
• Submission of all activities (i.e. laboratory/hands-on exercises, classroom activities,
and performance activities) in the form of hardcopy and softcopy. (individual
project)
Grading Criteria:
Requirement/Assessment Task Percentage
Major Course Output 50%
Major Exams 30%
Class Standing 20%
TOTAL 100%
Course Materials:
§ Rubrics
§ Course policies
References:
Books:
Deitel & Deitel. JAVA™ For Programmers Second Edition. 2012.
Malik D.S. Java Programming From Problem Analysis to Program Design 5th 2012
Baile, Duane A. Java Structure. Data Structures in Java for the Principled
Programmer. 7th Edition. 2007
Anderson & Franceschi. Java Illuminated (An Active Learning Approach) Vol 1.
Bronson, Gary J. Java Programming Principles and Practices for Scientists and
Engineers. Cengage Learning, 2013.
Internet Resources:
www.javaprogramming.com/tutorial/java-tutorial/html
www.iu.hio.no/-mark/JavaTutorial/Java-Tutorial/html
https://www.onlinegdb.com/
Module 1
Module Title: Advance Computer Programming Using Java Language.
Module Description: This module contains the continuation of the content of programming 1
in the previous semester. The students are expected of basic knowledge in computer
programming using java language. This module helps them to learn new topics like
Class, Object, Method, string, liner structure, Abstraction, Polymorphism, Inheritance,
and Encapsulation.
• Class;
• Method;
• Objects;
• Constructor
• Abstraction
• Polymorphism
• inheritance; and
• Encapsulation
Module Guide:
The learner are advice to read the lessons and suggested lessons to equip more
knowledge about the topic. It teaches the students on how to properly use new topics in java
programming. The student must also read, analyse, and carefully understand its program
sample in order to create their own program.
It is also good to read, practice and participate the lessons, activities and exercises in
order to understand the complicated problems. The activities must be solve and submit in order
to pass the basic requirements.
Module Outcomes:
It teaches the students how to implement, test and debug a program, based on a given
specification that uses each of the following: array, string, structure, pointers, heap, stacks,
memory, polymorphism and inheritance. .
Assess and recommend revisions to another program’s code regarding documentation
and program style standards that contribute to readability and maintainability of software.
Module Requirements:
At the end of this module, the students will come up with the following
• Create computer program using java language with new topics.
• Declare and create the string, polymorphism and inheritance.
Learning Plan
Lesson No: 1
Sample Problem1. Create a program without using a Class and method asking the user to
input 1.Summer 2.Spring and 3.Fall using IF then Statement:
(Please turn to Page 6)
Filename: Exer1.java
Problem2. Create a program using a Class and Method to asking the user to input 1.Summer
2.Spring and 3.Fall using IF then Statement:
(Please turn to Page 6)
Filename: Exer1-1.java
Class: A class is a user defined blueprint or prototype from which objects are created.
It represents the set of properties or methods that are common to all objects of
one type. In general, class declarations can include these components, in order:
o Modifiers: A class can be public or has default access (Refer this for details).
o class keyword: class keyword is used to create a class.
o Class name: The name should begin with an initial letter (capitalized by
convention).
o Superclass(if any): The name of the class’s parent (superclass), if any, preceded
by the keyword extends. A class can only extend (subclass) one parent.
o Interfaces(if any): A comma-separated list of interfaces implemented by the
class, if any, preceded by the keyword implements. A class can implement more
than one interface.
o Body: The class body surrounded by braces, { }.
void hungry()
{
Where:
A class can contain any of the following variable types.
Local variables − Variables defined inside methods, constructors or blocks are called
local variables. The variable will be declared and initialized within the method
and the variable will be destroyed when the method has completed.
Instance variables − Instance variables are variables within a class but outside any
method. These variables are initialized when the class is instantiated. Instance
variables can be accessed from inside any method, constructor or blocks of that
particular class.
Class variables − Class variables are variables declared within a class, outside any
method, with the static keyword.
Where:
• modifier − It defines the access type of the method and it is optional to use.
• returnType − Method may return a value.
• nameOfMethod − This is the method name. The method signature consists of the method
name and the parameter list.
• Parameter List − The list of parameters, it is the type, order, and number of parameters of
a method. These are optional, method may contain zero parameters.
• method body − The method body defines what the method does with the statements.
Sample Problem1. Create a program without using a Class and method asking the user to
input for 1.Summer 2.Spring and 3.Fall using IF then Statement:
Filename: Exer1.java
Sample Problem2. Create a program using a Class and method asking the user to input
1.Summer 2.Spring and 3.Fall using IF then Statement:
Filename: Exer1-1.java
Object instantiate
as a class
Calling method &
passing parameter
Class name
Class variable
Method with
parameter
Both program has the same output. Whats the difference between the two program? Which
one is better over the other? What makes it better?
Creating an Object:
As mentioned previously, a class provides the blueprints for objects. So
basically, an object is created from a class. In Java, the new keyword is used to create
new objects.
Sample Problem 3. Create a program Class and object where a class is a Dog and the object
is the puppy who has the properties of a name and the method or the behavior
of barking.
Filename: Exer3.java
Method Puppybark
Output:
Let’s Read:
What is an Object?
An entity that has state and behavior is known as an object e.g., chair, bike,
marker, pen, table, car, etc. It can be physical or logical.
An object has three characteristics:
Sample Problem 4 Let's take an example of developing a pet management system, specially meant
for dogs. You will need various information about the dogs like different breeds of the dogs, the age,
size, etc.
Some of the differences you might have listed out maybe breed, age, size, color, etc. If you think for a
minute, these differences are also some common characteristics shared by these dogs. These characteristics
(breed, age, size, color) can form a data members for your object.
Next, list out the common behaviors of these dogs like sleep, sit, eat, etc. So these will be the actions of
our software objects.
• Class - Dogs
• Data members or objects- size, age, color, breed, etc.
• Methods- eat, sleep, sit and run.
Now, for different values of data members (breed size, age, and color) in Java class, you will get different
dog objects.
Output:
This is kind of dog has a typical color of: Black
This dog breed size is: Large
This dog age is: 5 years
Every time an object is created using the new() keyword, at least one constructor is
called.
No argument Constructors:
As the name specifies the no argument constructors of Java does not accept any
parameters instead, using these constructors the instance variables of a method will be
initialized with fixed values for all objects.
Filename: Exer4.java
Parameterized Constructors:
Most often, you will need a constructor that accepts one or more parameters. Parameters
are added to a constructor in the same way that they are added to a method, just declare
them inside the parentheses after the constructor's name.
Filename: Exer5.java
Parameterized Constructors:
Most often, you will need a constructor that accepts one or more parameters.
Constuctor can make your source code smaller.
Filename: Exer6.java
Output:
This dog is a Maltese, Large in size with 5 years of age and color Black
This dog is a Matese, Small in size with 2 years of age and color White
This dog is a Chowchow, Medium in size with 3 years of age and color Brown
Sample Problem 7 Shape is the abstract class, and its implementation is provided by the
Rectangle and Circle classes with the method draw.
Mostly, we don't know about the implementation class (which is hidden to the
end user), and an object of the implementation class is provided by the factory
method.
Output:
drawing circle
In this example data abstraction is the process of hiding certain details and
showing only essential information to the user. In this example the method draw show
the simple operation to the user. Disregarding the process of where the it is an abstract
class of shape where it was an extension of class circle with a method draw.
Polymorphism in Java:
Polymorphism means "many forms", and it occurs when we have many classes
that are related to each other by inheritance. The most common use of
polymorphism in OOP occurs when a parent class reference is used to refer to
a child class object.
Filename: Exer8.java
Additional reference: https://www.w3schools.com/java/java_polymorphism.asp
Output:
The idea behind inheritance in Java is that you can create new classes that are
built upon existing classes. When you inherit from an existing class, you can
reuse methods and fields of the parent class. Moreover, you can add new
methods and fields in your current class also.
Filename: Exer9.java
Output:
Encapsulation in Java:
Encapsulation refers to wrapping up of data under a single unit. It is the
mechanism that binds code and the data it manipulates. Another way to think
about encapsulation is, it is a protective shield that prevents the data from being
accessed by the code outside this shield. In this, the variables or data of a class
is hidden from any other class and can be accessed only through any member
function of own class in which they are declared.
Now, let’s take the example of a medical capsule, where the drug is always safe
inside the capsule. Similarly, through encapsulation, the methods and variables
of a class are well hidden and safe.
Benefits of Encapsulation:
• Data Hiding: Here, a user will have no idea about the inner implementation of the
class. Even user will not be aware of how the class is storing values in the variables.
He/she will only be aware that we are passing the values to a setter method and
variables are getting initialized with that value.
• Increased Flexibility: Here, we can make the variables of the class as read-only or
write-only depending on our requirement. In case you wish to make the variables
as read-only then we have to omit the setter methods like setName(), setAge() etc.
or if we wish to make the variables as write-only then we have to omit the get
methods like getName(), getAge() etc. from the above program.
• Reusability: It also improves the re-usability and easy to change with new
requirements.
Sample Problem 10. Create a program Class and object where a Class is a Animal, with a
method of dogBarking. With in the method instead of typical passing of
variable on parameter, we use the set and get commands.
Filename: Exer10.java
Let’s Read:
The set method takes a parameter (newName) and assigns it to the name variable.
The this keyword is used to refer to the current object.
However, as the name variable in this example the String declared “dogbark” is
declared as private, we cannot access it from outside this class:
Real life application of this Encapsulation is by declaring private on the string dogbark on the method Class
Animal. This is to limit access of the animal properties from the outside classes since it was set to private.To set
the value using parameter is calling the set and get command.
Let’s Do This:
Problem 1. Write a java programming language that uses constructor and methods in the TV
class as defined public so they can be accessed from other classes.
Note:
The channel and volume level are not changed if the TV is not on. Before either of
these is changed, its current value is checked to ensure that it is within the correct
range. Listing 4 gives a program that uses the TV class to create two objects.
Filename: TVClass1.java
References/Sources:
Savitch, Walter. JAVA (An Introduction to Computer Science and Programming) 3rd
edition, 2004.
Let’s Rate
Computer Lab Activity Rubric
Title: ____________________________
Exemplary Acceptable Developing Beginning No Output
Criteria Score
4 3 2 1 0
The code works to The code
The application typical input, but sometimes fail or The code often fails,
meets all the fails to minor typical input. even for typical Program that does
Program requirements special cases; the Many parts of the input. Most not run and or
____
Correctness specified in the major requirements program indicated implemented
project are met, though implementation restrictions were incorrectly
specification. some minor ones violate indicated violated.
are not. restriction
Answers to
questions are
Correct Failure to explain
correct, Answers to
Effective Answers to understanding of the and justify workings
reasonable and questions are
Communicatio questions are problem, but was of code submitted
effective of the correct, but some ____
n / Concept correct, but cannot unable to explain will automatically
code. The justifications
Understanding justify solution. workings of code merit 0 for this
justifications provided are weak.
provided. course output.
provided are
sound.
The program
conforms to a
Not all functions /
coding standard Minor code
programs features Minimal internal No internal
that promotes formatting does not
Readability have proper documentation and documentation and ____
code readability. exhibit consistency
internal code readability code is not readable
Internal in coding standard.
documentation
documentation is
comprehensive.
Total----> ____
Let’s Reflect: (What was your suggestion for the improvement of learning plan - 2?
Let’s Chat:
• Submission of Let’s Get Started, Let’s Do this, and Module Post test will
be through Application by sending or attaching through documents or
application.
o Solutions must be presented always by picture, text or
authenticated documents.
• Participation in the Facebook and Messenger Group Chat or Video is
encourage to address lectures, question and clarification on the said topic.
LESSON OBJECTIVES
Pls follow seriously the sample exercise cause they are designed to
be self explanatory for you to get the thought and experience the
foundation of programming.