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

Las Ict7 Java Q3 Las 4

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

Las Ict7 Java Q3 Las 4

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

9

Schools Division of Koronadal City

JUNIOR HIGH SCHOOL


ICT 7 – Java
Learning Activity Sheet 4:
Creating Classes

QUARTER 3 WEEK 4
Learning Activity Sheet
Quarter 3 – Activity Sheet 4: Creating Classes
Unang Edisyon, 2023

Republic Act 8293, section 176 states that: No copyright shall subsist in any work of the
Government of the Philippines. However, prior approval of the government agency or
office wherein the work is created shall be necessary for exploitation of such work for
profit. Such agency or office may, among other things, impose as a condition the payment
of royalties.

Borrowed materials (i.e., songs, stories, poems, pictures, photos, brand names,
trademarks, etc.) included in this module are owned by their respective copyright holders.
Every effort has been exerted to locate and seek permission to use these materials from
their respective copyright owners. The publisher and authors do not represent nor claim
ownership over them.

Inilathala ng Kagawaran ng Edukasyon


Kalihim: Leonor Magtolis Briones
Pangalawang Kalihim: Diosdado M. San Antonio

Learning Activity Sheet Development Team

Writers: Arnold John B. De Vera, James Aldrin S. Estabillo and


Editor: Name
Reviewers: Evelyn C. Frusa PhD, Grace J. Miravalles, Rolex H. Lotilla and Arvin M.
Tejada
Illustrator: Name
Layout Artist: Name
Management Team: Crispin A. Soliven Jr, CESE - Schools Division Superintendent
Levi Butihin - Asst. Schools Division Superintendent
Prima Roullo - CID Chief
Grace J. Miravalles - EPS, EPP/TLE
Evelyn C. Frusa, PhD - Division EPS In Charge of LRMS
Bernardita M. Villano - Division ADM Coordinator
Inilimbag sa Pilipinas ng ________________________

Department of Education – Region XII – Koronadal City Division


Office Address: ____________________________________________
____________________________________________
Telefax: ____________________________________________
E-mail Address: ____________________________________________
9

The Java Program


(TLE_ICTJAVA1 1-12POAD-IIf-i-29)
Specific Objective/s

This Learning Activity Module (LAS) was designed and written with you in mind. It is
here to help you master Java Technology and the Java Programming Language. The
scope of this module permits it to be used in many different learning situations. The
language used recognizes the diverse vocabulary level of students. The lessons are
arranged to follow the standard sequence of the course. But the order in which you
read them can be changed to correspond with the textbook you are now using.
The LAS is divided into one (1) learning outcome, specifically:

• LO 8. Work with methods and encapsulation


o 8.1 Create methods with arguments and return values in
accordance with Java framework
o 8.2 Apply static keywords to methods and fields in accordance
with Java framework
o 8.4 Apply access modifiers in accordance with Java framework
After going through this Learning Activity Sheets, you are expected to:
1. Analyze patterns of programming in Java Programming Language;
2. Write simple Java Programs;
3. Compile and execute Java Programs;
4. Compile Java Programs using BlueJ;
5. Execute Java Programs using BlueJ;
6. Debug Java Programs;
7. Create methods with arguments
8. Apply static keywords to methods and fields in accordance with Java
framework; and
9. Apply access modifiers in accordance.
Directions/Instructions

In this Learning Activity Sheet, you will study about Java technology and
Java programming.

Notes to the Students

1. Study the lessons and answer religiously the activities. These will guide you on
what you will learn at the end of this Learning Activity Sheet.

2. Discover what you already know by answering the learning activities.

3. Apply what you have learned in real-life situation.


Activity

Activity 1:

Directions: Look at the sample class diagrams below. Provide the attributes
asked of the given class by providing details of each property in the box.

TV
Brand: ________________
Color:_________________
Size:__________________
Can Turn On (Yes/No):_________
Can Change Volume (Yes/No):________
Can Change Channel (Yes/No):_________

School
Name: __________________________________
Elementary or High School:______________
Estimated Population:___________________
Accepts Transferees (Yes/No):_________
Suspends classes (Yes/No):_________
Has Flag Ceremony (Yes/No):__________

List the steps, activities, and

decisions to e Establish process charted. boundaies - the


Procedure

Class

Class defines the common variable.

Example:

Sample Code:
What is a method?

A method refers to a piece of code referring to behaviors associated either with an


object or its class. A code found in a class for responding to a message. The
executable code that implements the logic of a particular message for a class. An
operation or function that is associated with an object and is allowed to manipulate
the object's data.

Creating a Method

Method Calling

How to call a method

1. Method name should match


2. Number of parameters should match
3. Type of parameters should match
Ways of calling a method

1. Calling a method through its object name


2. Calling a method within the same class
3. Calling a static method through its class name
Examples:

Passing Parameters

Passing parameters in Java is always Pass by Value!

When passing a parameter of primitive type:

• A copy of the value of the variable is passed


• The passed variable cannot be changed in the called method as the
method only possesses a copy of that variable.
When passing a parameter of reference type:

• A copy of the reference (address) of the object is passed


• The object reference cannot be changed in the called method (i.e., the
object cannot be reassigned to another object)
• The object state can be changed in the called method (i.e., attributes
can be modified)
Constructors

When you create a new instance (a new object) of a class using the new keyword,
a constructor for that class is called. Constructors are used to initialize the
instance variables (fields) of an object. Constructors are similar to methods, but
with some important differences.
The Differences

Constructor name is class name. A constructor must have the same name as the
class its in.

Default constructor.

If you don't define a constructor for a class, a default parameterless constructor is


automatically created by the compiler.

Default constructor is created only if there are no constructors.

If you define any constructor for your class, no default constructor is automatically
created.

A constructor doesn’t have a return type.

There is no return statement in the body of the constructor.

this(...) - Calls another constructor in same class. Often a constructor with few
parameters will call a constructor with more parameters, giving default values for
the missing parameters. Use this to call other constructors in the same class.

super(...). Use super to call a constructor in a parent class. Calling the constructor
for the superclass must be the first statement in the body of a constructor. If you
are satisfied with the default constructor in the superclass, there is no need to
make a call to it because it will be supplied automatically.

Unlike methods, constructors are not considered members of a class.

A constructor is called automatically when a new instance of an object is created.

Syntax:

public ClassName (parameter-list) {

statements...

Defining Inheritance

Inheritance is the ability to derive new classes from existing ones. A derived class
("subclass") inherits the instance variables and methods of the base class
("superclass"), and may add new instance variables and methods.

Inheritance defines a hierarchical relationship among classes wherein one class


shares the attributes and methods defined in one or more classes.

Inheritance is a relationship among classes in which one class shares the structure
and behavior of another. A subclass inherits from a superclass.

Relationships of Inheritance

“is-a” relationship

a subclass can be used wherever a superclass can be used


implemented in Java by extending a class

“has-a” relationship

Rules of Inheritance

• A class can only inherit from one class (known as single inheritance).
• A subclass is guaranteed to do everything the superclass can do.
• A subclass inherits members from its superclass and can modify or
add to its behavior and properties.
• A subclass can define members of the same name in the superclass,
thus hiding the superclass members.
• Inheritance is transitive (i.e., class A inherits from class B, including
what B inherited from class C).
• All classes inherit from the Object class - the highest in the
inheritance hierarchy.
• private members, hidden members, and constructors are not inherited
by subclasses.
? Questions
Activity 2:

Directions: Read and analyze each statement. Write check (/) if the statement is
correct and (x) if otherwise.

_________1. A class defines common variables.

_________2. An object refers to a piece of code referring to behaviors associated


either with an object or its class..

_________3. A constructor must have the same name as the class its in.

_________4. If you define a constructor for a class, a default parameterless


constructor is automatically created by the compiler.

_________5. There is return statement in the body of the constructor.

_________6. Passing parameters in Java is always pass by value.

_________7. When passing a parameter of reference type, A copy of the reference


(address) of the object is passed.

_________8. Inheritance is the ability to derive new classes from existing ones.

_________9. A superclass inherits from a subclass.

_________10. Inheritance is transitive.


Activity 3

Directions: Analyze the given code below and answer the questions in each item.

_________________________ 1. What does this program do?


_________________________ 2. What are the two pieces of information the
user needs to provide?
_________________________ 3. What is the data type of the variables length
and width?
_________________________ 4. What is the purpose of the
calculateRectangleArea method?
_________________________ 5. What does scanner.nextInt() do?
_________________________ 6. What is the formula to calculate the area of a
rectangle?
_________________________ 7. How is the user input obtained in this
program?
_________________________ 8. What will be the output if the user enters
length as 5 and width as 8?
_________________________ 9. What happens if the user enters non-integer
values for length and width?
_________________________ 10. How can you modify the program to handle
non-integer inputs gracefully?
Activity 4.

Directions: Write a Java Program that will ask the size of the sides of the square
and two separate methods that will compute the area and perimeter of the square.
Use the given in Activity 3 as your reference. Write your code in the box below.
Rubrics for scoring
Criteria Details Points
Code Clarity Code is well-formatted and 3
and readable.
Readability
Meaningful variable and method 2
names.
Proper indentation and consistent 2
use of whitespace.
Functionality Program achieves its intended 4
and Logic purpose (e.g., calculates area, solves
a problem).
Correct usage of variables and data 2
types.
Proper implementation of loops, 3
conditions, and methods.
User Program prompts user for required 1
Interaction input.
and Input
Handles user input errors gracefully 1
Handling
(e.g., non-integer inputs).
Output and Output is clear, well-formatted, and 2
Presentation understandable.
TOTAL 15
Closure

What I have learned in this activity?

1. I have learned that_________________________________________________________


__________________________________________________________________________________
__________________________________________________________________________________
__________________________________________________________________________________
__________________________________________________________________________________
__________________________________________________________________________________
__________________________________________________________________________________

2. I need to know more about_________________________________________________


__________________________________________________________________________________
__________________________________________________________________________________
__________________________________________________________________________________
__________________________________________________________________________________
__________________________________________________________________________________
__________________________________________________________________________________
References

RAMILO, R. V., & PASCO, D. M. (n.d.). COMPUTER HARDWARE SERVICING. K TO


12 - TECHNOLOGY AND LIVELIHOOD EDUCATION.
Blanco, E. (2017, September 12). CSS NC II learning Module. Retrieved June 03,
2020, from https://www.slideshare.net/edmundblanco/css-nc-ii-learningmodule
K to 12 Basic Education Curriculum Technology Livelihood Education Learning
module -Computer hardware servicing
https://kupdf.net/download/common-tools-and-equipment-for-computersystem-
servicing_5a2f023ce2b6f5f679a8c411_pdf
Department of Education, Soccsksargen Region. TLE CSS Quarter 1 Module 5:
Preparing and Interpreting Technical Drawing.
De Jesus Jr. J., et al. (2012). Programming and Databases 2 nd Edition. TechFactors
Inc.
Para sa mga katanungan o puna, sumulat o tumawag sa:

Department of Education – Koronadal City Division

-------------------------------------
-------------------------------------
-------------------------------------

Telefax: -------------------------

Email Address: ------------------------------------


PAHATID – LIHAM

You might also like