You are on page 1of 10

Adaptive Community for the Continuity of Education and Student Services National

Teachers College

Name: Grade and Section:


Teacher/s:

LET’S FOCUS!

In the next two weeks, you will better understand the concept and application of Java
programming. Through the lessons and activities here, you are expected to:
1. Identify and convert decimal numbers to octal numbers and vice versa; and
2. Write code that declares, and implements Java Method Parameters.

LET’S PREPARE!

By the end of this lesson, you are expected to create a program that will display your skill in
using Java Method Parameters and converting decimal to octal numbers. Pay attention to the following
reminders and criteria.
DIRECTIONS CRITERIA
Use the provided space at the end of this 21 - 30 points
module for writing your code. The program satisfies the specification completely
The program should produce an output that and correctly, with understandable code; and
contains the following information: concise, well - formatted comments. 11 - 20
Last Name points
First Name Some parts of the specification are not
Middle Name implemented; codes are difficult to follow in one
Theprogrammustusea variable appropriate for reading; and partial or poorly formatted
each information. comments.
Write a comment that will explain the use of 1 - 10 points
each variable. The program does not satisfy specification with
incomprehensive code, and wordy, badly
formatted comments.

LET’S EXPERIENCE!
The following work will schedule will help you in your study for two weeks:

WEEK DATE TASKS


3 January 18 - 22, 2021 Tasks 1 & 2, Reading 1
4 January 25 - 29, 2021 Task 3 & 4, Reading 2

1
Sharpen Your Life Cluster
Grade 10, Third Quarter, Module 2, SY 2020-2021
TASK 1: FIND THAT REMAINDER

Name: Grade and Section:


DIRECTIONS: Find the remainder for each division problem below. Write the whole number quotient at
the third column and the remainder at the fourth
column.
No. Division Problem Quotient Remainder

1 418 / 8 52 2

2 220 / 8 27 4

3 232 / 8 29 0

4 144 / 8 18 0

5 254 / 8 31 6

6 367 / 8 45 7

7 474 / 8 59 2

8 683 / 8 85 3

9 298 / 8 37 2

10 603 / 8 75 3
READING 1: OCTAL NUMBERS

The octal numeral system, or oct for short, is the base-8 number system, and uses the digits 0 to
7. Octal numerals can be made from binary numerals by grouping consecutive binary digits into groups of
three (starting from the right). For example, the binary representation for decimal 74 is 1001010. Two
zeroes can be added at the left: (00)1 001 010, corresponding to the octal digits 1 1 2, yielding the octal
representation
112.
● In the decimal system each decimal place is a power of ten. For example: 7410 = 7 x 101 +
4 x 100
● In the octal system each place is a power of eight. For example: 1128 = 1 x 82
+ 1 x 81 + 2 x 80
1128 = (1 x 64) + (1 x 8) + (2 x 1)
1128 = 64 + 8 + 2
1128 = 7410
● By performing the calculation above in the familiar decimal system, we see why 112 in octal is
equal to 64+8+2 = 74 in decimal.

To convert integer decimals to octal, divide the original number by the largest possible power of
8 and divide the remainders by successively smaller powers of 8 until the power is 1. The octal
representation is formed by the quotients, written in the order generated by the algorithm. For example, to
convert 12510 to octal:
125 = 82 × 1 + 61
61 = 81 × 7 + 5
5 = 80 × 5 + 0
Therefore, 12510 = 1758.

Another example:
900 = 83 × 1 + 388
388 = 82 × 6 + 4
4 = 81 × 0 + 4
4 = 80 × 4 + 0
Therefore, 90010 = 16048.
TASK 2: KNOW THE VALUE!

Name: Grade and Section:


Below is a set of numbers to be converted from decimal to octal and vice versa.
DIRECTIONS: Write on the space provided the correct converted value for each item.

No. Decimal Octal

1 34410
5308

2 6148
39610

3 71510
13138

4 7018
44910

5 40910
6318

6 6528
42610

7 19910
3078

8 1448
10010

9 42310
528

10 4368
28610
READING 2: JAVA METHOD PARAMETERS

Parameters and Arguments

● Information can be passed to methods as


parameters. Parameters act as variables inside
the method.
● Parameters are specified after the method name, publicinside
class Main {
the parentheses. You can add as many
static void myMethod(String fname)
parameters as you want, just separate them with a comma.
● When a parameter is passed to the method, it { System.out.println(fname + " Refsnes");
is called an argument. So, from the example }
above: fname is a parameter, while Liam,
Jenny and Anja are arguments. public static void main(String[] args)
● The following example has a method that takes a String called fname as parameter. When the method is
{ myMethod("Liam");
called, we pass along a first name, which is used inside the method to printmyMethod("Anja");
myMethod("Jenny"); the full name:
}
Multiple Parameters
}
public class Main {
// Liam
static voidRefsnes
myMethod(String fname, int age) {
// Jenny Refsnes
● You can have as many parameters as you System.out.println(fname + " is " + age);
like: // Anja Refsnes
}
● Note that when you are working with
multiple parameters, the method call must public static void main(String[] args)
have the same number of arguments as { myMethod("Liam", 5);
there are parameters, and the arguments myMethod("Jenny", 8);
must be passed in the same order. myMethod("Anja", 31);
}
}
Return Values

● The void keyword, used in the examples above, indicates


public that the
class Main { method should not return a value.
If you want the method to return a value, you static
can use
int amyMethod(int
primitive datax)type (such as int, char, etc.)
instead of void, and use the return keyword inside the method:
{ return 5 + x;
}

public static void main(String[] args)


{ System.out.println(myMethod(3));
● This example returns the sum of a }
method's two parameters: }
// Outputs 8 (5 + 3)

public class Main {


static int myMethod(int x, int y)
{ return x + y;
}

● You can also store the result in a variable public static void main(String[] args)
(recommended, as it is easier to read and { System.out.println(myMethod(5, 3));
maintain): }
}
// Outputs 8 (5 + 3)

public class Main {


static int myMethod(int x, int y)
{ return x + y;
}

public static void main(String[] args) { int z


= myMethod(5, 3); System.out.println(z);
}
}
// Outputs 8 (5 + 3)
A Method with If...Else

public class Main {

// Create a checkAge() method with an integer


variable called age
static void checkAge(int age) {

// If age is less than 18, print "access denied"


if (age < 18) { System.out.println("Access
denied -
You are not old enough!");

// If age is greater than, or equal to, 18, print


● It is common to use if...else "access granted"
statements inside methods:
} else {
System.out.println("Access granted - You
are old enough!");
}

public static void main(String[] args)


{ checkAge(20); // Call the checkAge
method and pass along an age of 20
}
}

// Outputs "Access granted - You are old enough!"


TASK 3: KNOW YOUR METHOD!

Name: Grade and Section:


DIRECTIONS: A table is provided below with a code. In the third column, write the proper syntax
to be used in the code based on the requirement on the
second column.

No. Requirement Code

static void SubMethod() { System.out.println("I just


got executed!");
Insert the missing part to call }
1 SubMethod from main two times. public static void main(String[] args) {
SubMethod ( );
SubMethod ( );
}

static void SubMethod() { System.out.println("I just


got executed!");
Insert the missing part to call }
2 SubMethod from main.
public static void main(String[] args) {
SubMethod ( );

}
static int myMethod(int x) {
Insert the missing part to print the
number 8 in main, by using a return 5 + x;
3 specific keyword inside }
myMethod: public static void main (String[] args)
{ System.out.println(myMethod(3));
}

static void myMethod(String fname) {


System.out.println( fname + " Doe");
Add a gname parameter of type }
4 String to myMethod, and output
"John Doe".
public static void main(String[] args)
{ myMethod("John");
}
TASK 4: MAKE IT HAPPEN!

Name: Grade and Section:


DIRECTIONS: Review the instructions and standards on the first page to give you adequate guidance.
Use the next space to write your own version of this
java program.

//program to input int and string value


import java.util.Scanner;

public class GetIpAddress


{
public static void main(String args[]) throws Exception
{
String lastname, firstname, middlename, birthdate, gender;
int age;

Scanner SC=new Scanner(System.in);

System.out.print("Enter Last Name: ");


lastname= SC.nextLine();

System.out.print("Enter First Name: ");


firstname= SC.nextLine();

System.out.print("Enter Middle Name: ");


middlename= SC.nextLine();

System.out.println("Last Name: " + lastname);


System.out.println("First Name: " + firstname);
System.out.println("Middle Name: " + middlename);

}
}
This is the input of the program:
Input

Enter Last Name:


Enter First Name:
Enter Middle Name:
This is the output for the program:

Output

Last Name:
First Name:
Middle Name:

You might also like