Lunes, Nobyembre 26, 2018

Methods - Activities 1-3


1.       Input two numbers.  Get the sum, difference, product, and quotient of these numbers.  Display the results afterwards.

Methods:            main – input
                                sum
                                difference
                                product
                                quotient
                                output

2.       Given:  At = 1/2bh
                Ac = πr2  (π=3.1416)
                Ar = lw
                As = s2

Input two numbers, n1 and n2.
Let:        n1 = b, r, l, s
                n2 = h, w

Methods:            main – input
                                triangle
                                circle
                                rectangle
                                square
                                output

Example: input => n1=5, n2=3
                output => Area of Triangle is 7.5
                                 Area of Circle is 78.54
                                 Area of Rectangle is 15
                                 Area of Square is 25



3.       Input:    Employee Name
                Rate Per Day
                Number of Days Worked

Where: Gross Pay = Rate Per Day * Number of Days Worked
                SSS = 10% of Gross Pay
                Tax = 15% of Gross Pay
                Total Deduction = SSS + Tax
                Net Pay = Gross Pay – Total Deduction

Methods:            main – input
                                gross pay
                                sss
                                tax
                                total deduction
                                net pay
                                output

            Example: input => Name = Ana
                                            Rate Per Day = 500
                                            Number of Days Worked = 10
                            output => Gross Pay is 5000
                                               SSS is 500
                                            Tax is 750
                                            Total Deduction is 1250
                                            Net Pay is 3750
                                 


Method

Method - is a collection of statements that are grouped together to perform an operation.


Syntax: modifier returnType nameOfMethod (Parameter List)
             {  //body
             }

modifier - defines the access type of the method
returnType - may return a value.  A method in Java returns only 1 value.
nameOfMethod - name of a method
Parameter List - contains the type, order, and number of parameters
body - any valid Java statement
signature of a method - is composed of the method name and parameter list


Types of methods
1. Standard library methods - are built-in methods that are ready to use
2. User-defined methods - are created in order to perform user requirements.


Activity #17 - One-Dimensional Array

Place all codes under the method main. 1. Input 5 numbers and satisfy the ff:     a) sum of all input numbers     b) count of odd and ev...