142 Subatur How to play ( • contains the first line of statements that must be executed • contains the last line of statements that must be executed • can exist without other subsystems. computer. • a mandatory subroutine named main(). The main() subroutine is a special kind of subroutine. This is so because: computer. The software body contains computer code. The body of the method starts with an opening brace symbol "{" and ends with a closing brace symbol "}". A computer statement is a line of computer code that ends with a semicolon symbol ";". All computer statements must be contained in a subroutine. Computer statements are computer algorithms that have been translated into programming languages such as Java. These statements will be executed by the computer from the initial line to the final line in top-down order. The main() subroutine has a syntax similar to the general subroutine syntax but with a unique head design: Return data type Subroutines will usually return results after the subroutine body has finished processing data. way "()" used. If the container accepts a parameter, then the data type and name of the parameter will be appended. can be used directly. Without static, subroutines require object creation before data is used. Example: (int quantity) accepts an integer parameter named quantity. Parameters are variables to store the values passed to the subroutine. Name of subature Special keywords The static keyword is placed in front of the subroutine name. Without this keyword, the subroutine does not Parameter container Parameter container is enclosed by parentheses "(" and ")". If the parameter container is empty, the symbol These include int, double, String and char. If there is no need to return data, use the void keyword . This name is given by the organizer. Any suitable name can be given. The name must start with a letter (usually lowercase) and can contain numbers but not symbols. The type of data returned in the "header" depends on the type of data the "body" wants to return. Mandatory mandatory parameters Data types Return name Body Special keywords public static void main(String[] args){ } Header main() method http:// goo.gl/ 1dVWyL Figure 1.55 Subprogram main() Computer Science Form 4 Machine Translated by Google
143 you ? Did you know? Has special keywords public and static: • public is the access scope of the subroutine. Public allows this software to be accessed from Subroutine name Mandatory name is main. Special keywords Return data type The play subroutine does not return data, so use void. • All subroutines have static so that they can be used directly without objects Parameter container The parameter container must contain a String array parameter with the name "args". any project code. In Java in particular, the subroutine header of the main() method must have the following characteristics: The MyClass body is from rows three to eight. Example: The subroutine header of the main() method is rarely changed. Keep the substring syntax of the main() method as shown in Figure 1.55 to avoid syntax errors. The body of the main() subroutine contains computer codes. The statements in the main() subroutine will define the properties of the program. Therefore, these statements should be written based on a tested algorithm. The following example is a simple program that displays the string "Hello Malaysia.". In the diagram above, the subroutine of the main() method is located on lines four through six. Subroutines must be in the class body, MyClass. place except in the subature only. Remember that computer code statements cannot be written anywhere Figure 1.56 An example of the Play subroutine Otherwise, the code will throw an error CHAPTER 1 PROGRAMMING when compiled. Machine Translated by Google
144 Special keywords The parameter container static void hello() static void subSet01 () Name of subature way } System.out.println("Hello world."); Return data type { Example: • The closing brace symbol "}" on line six is a pair The first line in main() is on line five. Java code statement System.out.println("Hello Malaysia."); will print "Hello Malaysia." on the output screen. Line six is the closing brace symbol "}" which marks the end of the Java program's main() method substring . In addition to the main() subroutine , the programmer can write other subroutines. This activity is called subroutine definition. Another subroutine is similar to main() but simpler: The programmer defines a new subroutine by referencing the subroutine syntax above. An example of a simple subroutine is a subroutine that displays the text "Hello world.". See the following example: • The closing brace symbol "}" on line eight, is the counterpart to the opening brace symbol "{" on line two. This pair is a pointer to the MyClass class body. Attention! In the source code file, this new subroutine is located outside the main() subroutine . As with the main() subroutine , other subroutines must also be inside the class body. See figure 1.57. to the opening brace symbol "{" on line four. This pair is a pointer to the substring body of the main() method. you ? Did you know? Other Ways Defining methods Indentation is for The syntax error is http:// goo.gl/ hKk5lw symbol. Make sure the pairing is correct. Each opening brace symbol "{" must have a closing symbol "}". To prevent carelessness, make the same indentation for the same pair. Computer Science Form 4 add a blank space before the symbol using the "Tab" key. Students either forgot to put the symbol or http:// goo.gl/ S1XKyT Java Methods Calling over put error using the bracket symbol. Machine Translated by Google
In the example above, the subroutine of the Mark entry method is located on code lines 9 to 15. In the body of the code, there is a use of the java.util.Scanner procedure to read the user's input. To use it, declare the scanner variable to be of type java.util.Scanner and assign it to the new java object. Example: In the next line, line 13, the scanner variable is used to read input of type double from the screen using the nextDouble() procedure. util.Scanner(System.in). Normally, the java.util.Scanner(System.in) object configuration only needs to be done once. The second example is a subroutine called masukMarkah. This subprogram asks the user to input marks for the Computer Science subject. The score is accumulated to a variable called scoreComputer. Figure 1.57 Another subprogram in the class body Based on the second example, try building a subroutine called enterAge and ask the user to input the age of the students in your class. have other procedure procedures like (a) nextInt() for read input of type int, (b) next() to read input of one word, (c) nextLine() to read input of one line of text. Figure 1.58 Score entry subroutine Mind Test In addition to reading data of type double, java.util.Scanner CHAPTER 1 PROGRAMMING you ? Did you know? 145 Machine Translated by Google
The definition or definition of the subroutine must be made before the subroutine can be called from main() or any other subroutine, ie the caller. As the main module, absolute control rests with main(). When main() needs the help of another subroutine to perform a particular process, control is transferred to that subroutine. Once the subroutine is complete, control is returned to the main() subroutine. When there are more than two subroutines, which one will be executed first? How is this software organized and coordinated? Usually, the main() substring uses the substring of other substrings. See Figure 1.60(a). Subroutines can use other subroutines. The purpose is so that the code of statements in other subatures is also implemented. Generally, the relationship between two subroutines is the caller and the called. The caller calls the subroutine name of the method called in the body of the subroutine of the caller. void. play() Did you know? you ? Call Subatur main() Calling Subatur from main() CALLER Subprograms Returns control (iii) static means the subature belongs to the class, not the object. (iv) The last word other ways Figure 1.59 A subprogram can call or be called Main module before the subatur name can be called from various locations consisting of classes Computer Science Form 4 others. (i) When the main() substring is called, all the statements that are part of the substring will be executed. Subprogram (v) When calling a substring that returns something, you can use what was returned. 1 (ii) The word public CALLED Using software 2 Figure 1.60(a) The relationship between the main() subroutine and other subroutines call _ before subatur is 2 Remember these five things! Subprogram 146 Machine Translated by Google
play() Method 1 http:// goo.gl/ 502bir 1 2 5 Returns control Figure 1.61(a) Hello() call and hello() definition 3 Figure 1.60(b) Sub program main() as main module CHAPTER 1 PROGRAMMING Module Module Creating objects and calling methods Pointer Method calling method 2 Using software http:// goo.gl/ yxNojd Main module Module 4 way 3 The following example shows how to subroutine the hello() method In figure 1.60(b), the example shows the main module main() using the name called hello(). Try to identify the main() subroutine, the hello() subroutine definition and the hello() subroutine call . called from main(). The call is made in the main() procedure using subroutine module 1 followed by subroutine 2 and subroutine 3. Finally, control is returned to the main module main (). The program starts with main() and ends with main(). 147 Machine Translated by Google
you ? Did you know? http:// goo.gl/ GUP954 Figure 1.61(b) Calling hello() from main() Figure 1.62(a) Calling two subroutines from main() 2 Calling Java Methods When calling a substring that takes one or more arguments, make sure the appropriate value is provided. This matter is because arguments are often required and the caller's substring must have the correct value when calling a substring. A further explanation of the argument is on the next page. 1 Computer Science Form 4 In this case, subroutine calls to the hello() method are made from the body of the main() caller. Next, control is transferred to the subroutine definition of the hello() method to execute the statements in its body. Another example shows the subroutine main() calling two other subroutines. 148 Machine Translated by Google
149 Did you know? you ? you ? Did you know? Thus, subroutines can still share the value of variable values through parameters. to reference a variable inside the caller's subroutine. Some subroutines can accept parameters. Remember the mandatory "args" parameter in the main() method substring? The expression actual parameter is used What are parameters? Parameters or arguments are variables that allow subroutines to receive values from the caller. which is used to read the text in line 17 and read the integer in line 24 using the nextLine() and nextInt() function methods respectively. Note that the scanner object variable is located inside the class body but is not located under any subroutine. This is because the scanner object variable is shared by all subroutines in the class above. When compiled and run, the output of the above program is as shown. Note that the order of the output depends on the order of subroutine calls in main(). Figure 1.62(a) defines two substring definitions of the requestName() and requestMark() methods. Each accepts input and displays output for its respective name and score. Notice in line 4, the scanner variable is a new java.util.Scanner(System.in) object The formal parameter expression (formal parameter) is used to refer to parameters for subroutines. Parameters A special use of the public keyword is the scope of access. For the other subroutine subroutines in the example shown, the use of public can be omitted without any effect. The Java programming language is unlike any other programming language. Java has no mechanism for Figure 1.62(b) Output change the actual parameter value. This is because CHAPTER 1 PROGRAMMING public static void main(String[] args){ } Parameters Machine Translated by Google
} Parameter name System.out.print(answer); noun; } Data types static void findTotal(int x, int y, int z){ Declaration of parameters x, y and z * double answer = nom System.out.print(answer); int answer = x + y + z; static void nameSubaturCara (int x){ } static void square(int nom){ parameters Declaration parameter nom If a parameter is required, the parameter needs to be declared in parentheses before the parameter in the subroutine. Declaring parameters is the same as declaring variables. There is no limit to the number of parameters and also the order of parameters depends on the programmer. The use of parameters must be declared during the definition of method substrings: Example 1: Example 2: (a) static void kuasaTiga (int no) { Accepts parameters Computer Science Form 4 1 and 2, label the parameter declarations for the following questions. No parameters Based on Example (b) static void findTotal (int Subprogram Figure 1.63 Some subroutines can accept parameters Mind Test 150 a, int b, int c) double answer noun; * { } = nom nom System.out.print(answer); } * int answer = a + b + c; System.out.print(answer); static void subAtur01 (int x){} static void subAtur03 (int [] x, String z){} static void subAtur02 (){} static void subAtur01 (){} static void subAtur03 (){} static void subAtur02 (int x, double y){} Machine Translated by Google
Mind Test CHAPTER 1 PROGRAMMING The parameter name cannot be the same as the name of another parameter in the same substring and the name of a local variable in that substring. Based on Examples 3 and 4, construct an appropriate syntax for declaring parameters. Make sure the syntax has the correct order of values and that there is parameter-toparameter value assignment. The name given to the parameter must be a unique name according to the parameter. 151 In example 3, the call returns three integer numbers that are compatible with the findAmount definition. Each integer number 1, 2 and 7 will be assigned to parameters x, y and z in order. However, subroutine calls must use value values that are compatible with parameter declarations in the subroutine. Example 4: In the example above, the list of parameters must be in the correct order. This means displayPrice(1500.0, "smartphone"); is wrong because it assigns a value to an incorrect data type. The number of values sent must be exact, i.e. neither more nor less. Usage displayPrice("smartphone"); is wrong because there is no price information. The order of values is important. Example 3: System.out.print(answer); } static void displayPrice(String item, double h){ static void findTotal(int x, int y, int z){ displayPrice("smartphone",1500.0); public static void main(String [] args){ " is " Assignment of parameter values to parameters Assignment of parameter values to parameters + findSum(1,2,7); h); + item + public static void main(String [] args){ } } int answer = x + y + z; } System.out.print("Price " Did you know? you ? Machine Translated by Google
Returns data Returns control AND parameters A quick note to remember how to restore data. method 2 Using software Module Using subroutines AND passing parameters (c) A subprogram can return data by using the word "return". Computer Science Form 4 Method 1 Pointer Module (a) Determines whether the data type of the subroutine returned is a primitive data type or a class name. play() Figure 1.64 Types of parameters and returns from the method subroutine called Module returns any value. way 3 Returns control Main module (b) The data type can be void which means no you ? Did you know? 152 Some subroutines return not only control but also data. In the following figure, example subroutine 3 returns data to the main() caller. For those that return control only, such as subroutines 1 and 2, the void keyword is used when declaring subroutines. If the subroutine returns data, the final line in the subroutine body has a return statement and the data to be returned to the caller. The subroutine name does not have void as the return data type. Instead, the data type corresponding to the returned data is declared in the syntax. All subroutines will return control to the caller. Data can be returned as the result of an expression, a value in a variable, a constant value or the value of the data itself. Each subroutine can only return one type of data. Refer to Table 1.18. Machine Translated by Google
153 The name of the subroutine that returns the data is usually prefixed with get. For example, getName, getAddress and getTelephone. The following example shows a main() subroutine that uses a subroutine to return data. See code lines 9, 10 and 11 for the call. The lines of code for the getName, getAddress and getTelephone subroutine definitions are 20-23, 25-28 and 30-33 respectively. static void subProcedure(){} static double subProgram(){} static int subProgram(){} static String subProgram(){} The same. (a) The return data type must match the data type specified by the subroutine. in order and received by the software in order CHAPTER 1 PROGRAMMING Table 1.18 Subprograms and their explanations (b) Parameters must be There are two important things to pay attention to when restoring data, namely, Figure 1.65 Using subroutines to return data For example, when the return data type is from an integer subroutine, you cannot return a String. you ? Did you know? Software definition Returns data of type integer Explanation Returns data of type String Returns data of type double Does not return data. Only control is returned Machine Translated by Google
154 Computer Science Form 4 Table 1.19 Comparison between procedures and functions The two types of subroutines are procedures and functions. The differences are summarized as follows: In general, the syntax of a function is similar to that of a procedure. The body of a function is like a procedure except on the last line there is a Return statement to return the data. Data can be returned as the result of an expression, a value in a variable, a constant value or the value of the data itself. 1.6.3 Difference between Function (Function) and Procedure (Procedure) on SubaSystem.out.print(answer); int answer = x + y; variableData type; static void variable = Function name([Parameter nameData type]); findSum(5, 8); Procedure name([Datatype static int findAmount(int x, int y) { int answer = x + y; Procedure name([data typeParameter name]); parameter name]){} return answer; int total = findTotal(5, 8); static void findAmount(int x, int y) } } parameter name]){} { static typeData nameFunction([typeData Differences: Differences: Does not return data. The body ends with a return statement followed by the returned data. Call syntax Function Definition syntax Returns control. Procedure Returns data. Example definition Returns control. The return data type in the syntax is int, double, char, String, array or Java object. Comparative aspect The return data type in the syntax is void. Example call The equation The body is not terminated with a return statement. way Machine Translated by Google
Did you know? you ? static int requestNumber(){ int name; } return amount; } } int amount; int totalNumber(int x, int y){ return nom sum = x + y static void hello(){ System.out.print("Hello world."); java.util.Scanner sc; nom = sc.nextInt(); sc = new java.util.Scanner(System.in); The following pointers can be used to choose the procedure: • The result of the process is used in the subroutine only once and is not needed again. used to select functions: • The processed data needs to be stored in the caller's body. Function Procedure anywhere. When is a procedure or function optional? The following pointers can • Subprograms are used to request input. Example 1: Example 1: • Subprograms do not display results or save results in • The processed data will be used again by the caller. • Subprograms are used to create displays only, such as messages to the user. The data may be used by subroutine main() or other subroutines. Example 2: • It should be noted that functions only return one type of data at a time. The returned data type must match the declared return data type. CHAPTER 1 PROGRAMMING • A common error for functiontype subroutines is failure to accept returned data. Common errors in the use of functions are as follows: 155 Machine Translated by Google
That's right Wrong Write a Software program that uses the getName() function subroutine to request a user's name. The name will not be displayed in the function. Instead, the value will be returned to the main() procedure to be displayed. Sample output is as follows: 156 int x; System.out.print(x); requestNumber() int x; x = requestNumber() System.out.print(x); Table 1.20 Correct and incorrect way to call a function Utility functions in Java Computer Science Form 4 The utility functions are built-in, that is, they are already in Java programming language . Table 1.20 shows some commonly used utility functions. Example 2: Example 3: In the table below, the requestNumber() function returns an integer. Study the code for the requestNumber() function definition. Those integers need to be "received" by assembling to an integer variable. Based on the example in the table, x is used as a variable to store the returned value. Example 61 { System.out.print("Hello " } static void findAmount(int x, int y) static int requestNumber(){ return 100;} static void hello(String name){ System.out.print(answer); } + name); int answer = x + y; you ? Did you know? Machine Translated by Google
157 Note that the getName() declaration must have a String return data type. The body of getName() has a statement return scanner.nextLine(); which returns a String. In main(), the returned value is assigned to the String variable x. The stack statement is x = getName();. Returns the number n after being rounded to the nearest integer. Example: Example: Returns the larger number between m and n. Function Syntax To generate the answer generate a project with the name Computer Software project. Use the software package name My. Use the class name MyClass. In MyClass, enter the following code: Returns the nearest integer but less than or equal to the value of n. Returns the smaller number between m and n. Solution: Example: Explanation Example: Returns the square root of the value of n. Example: Math.round(2.3); return 2. Math.sqrt(double n) Math.sqrt(100); Math.round(2.7); return 3. Math.floor(-2.7) returns -3. Math.max(double m, double n) Math.round(double n) Math.min(double m, double n) Math.floor(2.7); return 2. Math.max(100,10); returns 100. Math.min(100,10); returns 10. Math.floor(double n) } } public class MyClass { My software package; static String getName(){ Table 1.21 Examples of utility functions in Java System.out.println("Greetings, " + x); String x; } x = getName(); CHAPTER 1 PROGRAMMING static java.util.Scanner scanner = new java.util.Scanner(System.in); System.out.print("Enter name: "); public static void main(String[] args){ return scanner.nextLine(); Machine Translated by Google
Write a program that accepts two integers and determines the larger integer number using the Math.max(m,n) function. Solution: " is greater."); nom1 = scanner.nextInt(); Mind Test My software package; System.out.println("Enter number 2: "); Based on Example 62, write a program that accepts four integers and determines the larger integer number using the Math.max(m,n) function. double nom1, nom2; System.out.println("Enter number 1: "); sc = new java.util.Scanner(System.in); } public static void main(String[] args){ } public class MyClass { nom2 = scanner.nextInt(); Computer Science Form 4 static java.util.Scanner sc; System.out.println(Math.max(nom1,nom2) + 158 In the example above, the variables nom1 and nom2 are used as parameters in Math.max(nom1, nom2). Built-in functions Java will return the larger number between these two options. The returned number will be displayed directly in the System.out.println(); statement. Example 62 Machine Translated by Google
159 This program calls several procedures from main(). The following programs each ask for the student's name and score using the getName() and getMarkah() procedures. Then, the grade is determined using the setGred() procedure. The paparInfo() procedure displays the student's information. The output of interaction with the user is as follows: Modular Arrangement 1.6.4 Writing Modular Programs Containing Array Structures Figure 1.67 The main() subroutine calls several other subroutines CHAPTER 1 PROGRAMMING Figure 1.66 User interactive output Machine Translated by Google
Let's review universal variables! Figure 1.68 Subroutine getName() and getMarkah() Computer Science Form 4 Universal variables • Universal variables work only within programs. • Use of global variables is current within program functions only. When the procedure has finished, the memory space allocated to variables and constants will also finish. Figure 1.69 Subroutine setGred() Note that in the main() procedure, there are not many algorithm statements. This is because the statements have been placed in the substructure defined in the following diagrams. Calling the subroutines should follow a logical sequence. The subprogram in Figure 1.69 asks the user to enter the name and score that will be stored in the global variables, namely name and score. 160 Did you know? you ? The program for this example is a console program. The variable name, score and grade variables are declared as universal (global) variables. A universal variable has the advantage of access to all subroutines in a program. This means that the procedures main(),getName(), getMarkah(), setGred() and showInfo() can read and write to the same set of variables. Machine Translated by Google
161 Figure 1.70 DisplayInfo() procedure CHAPTER 1 PROGRAMMING The displayInfo() procedure finally retrieves the variable values to be displayed back to the user. The values of the name and score variables are derived from user input via the getName() and getMarkah() procedures. The grade value is determined by the setGred() procedure. Can a very large number of data be sent through a parameter? Try to imagine sending 100 data from the subroutine of the caller to the subroutine of the called. If you remember using arrays, you might be able to answer these questions. To pass an array as a parameter, make sure the subroutine can accept an array parameter. This is ensured from the declaration of the subroutine head which accepts an array type parameter. See the data type in the following subroutine header: Aren't procedural subroutines returning no data? For function subroutines, only one value can be returned. How are arrays processed in subroutines? The for loop control structure is needed to accumulate or access the values of the elements in the array. If there are 10 elements in the array, the for loop needs to repeat 10 times from index 0 to 9. The setGred() procedure will use the entered grades to determine the corresponding grade . An optional if-else control structure is used. Selection results are stored in the grade variable . See how 10 integers are stored in the list array variable Number . How does the subroutine return a large number of data to the caller? An array is a variable that can hold many elements using the same name (but a unique different index representing each element). Can large amounts of data be put into an array to be passed to the subroutine as a parameter? Array Structures in Modular Programming static void displayList(int[] listNumber){} int[] listNumber={1,2,3,4,5,6,7,8,9,10}; Machine Translated by Google
Computer Science Form 4 Example 63 The output is displayed as follows: The above example shows all the elements in the array being passed to the List display subroutine. The use of arrays makes such transmissions easier because the size of the array can be changed to transmit more elements. So, it is possible to pass 100 integer numbers through the listNumbers array in the example above. An array of listNumbers contains 10 integers from 1 to 10. A program passes a list of Numbers as a parameter to the showList procedure subroutine to be displayed. The code to produce the output as required above is as follows: {System.out.print(listNumbers[i] + ",");} for(int i=0; i<10; i++) 162 How to return array data? The elements in an array can be changed directly from any subroutine. Therefore, array variables do not need to be returned to the caller. Let's look at some examples of using arrays in modules. Machine Translated by Google
The setRandomList subroutine is called from main() on line 6. The empty listNumber array is passed as a parameter to the setRandomList subroutine to be filled with random numbers. random()*10) which is between 0 and 9 is taken. Addition with the integer 1 ensures a range of random numbers between 1 and 10. The random number generation process is performed 10 times in the for loop control structure. In the same repeat block, a random number is inserted into the listNumbers array and displayed on the screen. An empty array of numbers is declared in the main() procedure. From main(), a call is made to the setRandomList() procedure. In the setRandomList() procedure, an empty array of numbers is populated with random values generated by Math.random(). The values of the elements are displayed in both the setRandomList() method subroutine and the main() procedure. The code for this example is as follows: See line 17. Math.random() is a Java function subroutine that will generate a random decimal number between 0.0 and 1.0. To generate a random number between 1 and 10 (including 1 and 10), the following expression is used: In this expression, the use of (int) ensures that only the integer part of the double result (Math. The output for this example is as follows: 163 CHAPTER 1 PROGRAMMING (int)(Math.random()*10) + 1; Example 64 Machine Translated by Google
164 Computer Science Form 4 No Score Student Score Student Malay, English and Mathematics subjects. The output is as follows: 1 Use a simple variable to store all the data in the following table: 2 Look at the following table: (d) Accumulate an array of listScores Determine the element returned by each of the following commands: (f) listAge[4] will return the value 18 3 Given the following array: 4 Write a new subroutine testScore input(). This subroutine accepts test score input for (b) Declare an array of listScores (a) Declare an array of listStudents. (c) listAge[3] will return the value 18 (c) Stack an array of listStudents. (d) listAge[2] will return the value 18 (e) listAge[0] will return the value 17 (a) listAge[5] will return the value 19 (b) listAge[1] will return the value 17 Example 64 shows that passing an array via parameter is not like passing a variable. In normal variable passing by parameter, the value of the variable has two copies in both the substring of the calling method and the substring of the called method. Changes made in the substring of the called method will change the original value in the substring of the calling method. int [] listAge = {17, 17, 18, 18, 18, 19}; 85 83 Malay score input: English score input: 34 34 Alia Abdul Majid 56 Ang Yi Leng 78 2 78 Alia Abdul Majid Ang Yi Leng 56 1 Adam M. Saad Adam M. Saad 3 Formative Training 1.6 Machine Translated by Google
65-69 G 80-89 A+ 75-79 A 40-44 D 0-39 E 90-100 50-59 B C+ 45-49 C 70-74 A 60-64 B+ 4 static void displayPrice(String item, double h){ + item + Score 5 System.out.print("Price " + h); 3 } 6 } is " 2 showPrice("smartphone",1500.0); " CHAPTER 1 PROGRAMMING 1 public static void main(String [] args){ Grade Math score input: __________________________________ Malay Score: 85 Math Score: 90 90 English Score: 83 165 6 In the following Java code: (c) Price display call (b) Definition of displayPrice 5 Write a new subroutine of courseGred(). nettuGred() accepts student grade input and uses the selection control structure to select the appropriate grade. Next, the grade is displayed on the computer screen. Grade marks are determined based on the following table: (a) Main() subroutine Identify the statement line below by writing the line number of the above program: (d) Subroutine of the caller (e) The subroutine is called Machine Translated by Google
166 Computer Science Form 4 Program A Program B How do you define it? 10 Write Java code that defines a substring of the findLargest() method. The subroutine will check the array in receive to find and return the largest element. (ii) 10 (d) Determine which one uses procedural subsystems. (b) Can the subroutine given be used to process data "2" ? (b) Determine the output of Program B: to determine the square of the following values: (c) Determine which one uses the function subroutine. 7 Given the following definitions: (i) 2 8 Write a complete program in Java code to accept user name input and then pass the name to the hello subroutine parameter to be displayed. Given a piece of code in the main() method substring as follows: (a) Write a Java code statement in the main () subroutine for the given subroutine definition (a) Determine the output of Program A. 9 Given two sets of Java programs as follows: Justify your answer. How do you define it? Justify your answer. (c) Can the given software be used to process "12.3" data? { System.out.print(increment(9)); static void square(int nom){ nom = nom + 1; double answer = nom * System.out.print(increment(9)); public static void main(String[] args) double numberMaximum = findLargest(listNumber); static void increment(int nom){ public static void main(String[] args) } } return name; } } } double []numberlist = {2.0, 3.142, 37.5}; System.out.print(answer); static int increment(int nom){ { noun; nom = nom + 1; Machine Translated by Google
Index static void showQuantity(String item, int x){ } + " is " + x); item + CHAPTER 1 PROGRAMMING System.out.print("Quantity " Determine whether or not the following call matches the subroutine parameter. (b) displayQuantity(1500.0, "smartphone"); 13 Write the Java code for a function subroutine that finds the value of the hypotenuse of a triangle with x and y sides. The formula is, hypotenuse = ÿx2 +y2 . 12 Given the following definition. (e) displayQuantity("smartphone",10, 1500.0); (a) displayQuantity("smartphone", 10.0); 11 Observe the memory cells for the following array: (d) displayQuantity("smartphone", 30); Identify the memory cell component names (a), (b) and (c) for the array structure. Give your explanation if it doesn't match. (c) displayQuantity(30, "smartphone"); Note: Use Java's built-in function Math.sqrt(double n). 167 2 (a) (b) listAge (c) 5 18 18 19 3 89 4 17 0 17 1 Machine Translated by Google
problem Design solutions Documentation Test and debug Analysis Execute the solution Application Development 2 1 3 4 5 1.7 168 The waterfall model is used as an application development model since this model is similar to the processes in the SDLC. This model is the earliest model, easy to understand and easy to manage. The application development life cycle is a term used in systems and software engineering, information systems, and application development that describes the process of planning, designing, testing and implementing an application or software. The SDLC consists of a cycle of sequential phases and serves as an effective action plan for the project team. In addition, the SDLC helps track the status of the completion of the project. The waterfall model contains five phases in general, where each phase in the waterfall model is structured ie one phase must be completed before moving on to the next phase. Information for each phase is required for the next phase and cannot be reversed. Common methodologies available for SDLC are waterfall model (Waterfall model), RAD model (Rapid Application Development model), iteration model (Iterative model), spiral model (Spiral model) and agile model (Agile model). A hybrid model is a combination of several models. Documentation is important regardless of the model used and often goes hand in hand with the development process. For example, there are methods that suit a specific type of project but in the final analysis, the most important factor is the success of the project being developed. System Development Life Cycle (Software Development Life Cycle -SDLC) is also known as the application development life cycle. Solution design is prepared from problem analysis. System design specifications are used as input for the next phase. (v) Documentation The work is divided in sub modules / units and coding begins. The longest phase in the SDLC Data acquisition, problem analysis, problem statement 1.7.1 Describe each phase in the System Development Life Cycle (SDLC): (i) Analyze the problem to determine the requirements (iv) Testing and debugging 1.7.2 Creating an application or applet with a graphical interface Computer Science Form 4 (iii) Implement solutions Various types of testing, debugging, fixing errors and improvements are carried out. (ii) Designing a solution Documentation is provided at each phase. Examples: flowcharts, program codes and even IPO charts. CONTENTS STANDARD LEARNING STANDARDS Machine Translated by Google
1.7.1.1 Problem Analysis Phase 1.7.1.2 Solution Design Phase The problem solving design phase is made after the IPO analysis which is the set of requirements to start the design phase is done. Even with small projects and simple needs, a mental design for understanding needs with solutions needs to exist. This phase looks at potential solutions that exist and determines effective and efficient solutions. This answers the "how" to build the best solution. Staff salary an hour of work Input Suppose you are required to solve the problem of counting staff wages according to working hours. Process (c) Input for the formula which is the rate per hour worked and the number of hours worked. 2 Get the number of working hours. The IPO analysis of the above problem is as follows: 3 Calculate staff salary = rate x number (b) Formula to produce the output 'staff salary'; that is, the hourly rate of work multiplied Hourly rate Number of hours worked with the number of hours worked. 1 Get the hourly rate. Solution: Output required which is staff salary as output. (a) The way to fill in the IPO chart is to determine which solution The problem analysis phase is the process of identifying program requirements and finding why a program is built. Systematic steps should be followed to solve the problem and it is important that we understand the problem statement clearly. First, analyze the problems faced by using IPO analysis which is input, process and output analysis. The following example shows how to analyze a problem using an IPO chart. 1.7.1 System Development Life Cycle 169 Example 65 Waterfall Model CHAPTER 1 PROGRAMMING Several phrases are often used to describe inputs, outputs and processes. Process users - ...enter inputs in algorithms..., ...use formulas... Output - ...to display..., to determine..., to calculate... goo.gl/8BLz8D For example, the phrases used: Input - the user enters, Prompt ... for..., Input you ? Did you know? Machine Translated by Google
Get hourly rates for staff. Then, multiply the number of hours the staff worked. The result is the salary of the staff. Algorithm to calculate staff salary: 3. Calculate staff salaries 2. Read the number of hours 1. Read the rates = rate * billHour 4. Display staff salaries work, billHour per hour, rate The use of algorithms is the initial step for problem solving in the solution design phase. Pseudocode is a set of steps written in spoken language while a flow chart is a graphic representation that shows the steps of solving a problem and has a relationship with each other. For example, flowchart. The result is as shown below. Flowchart After building the algorithm, we finish by writing the pseudocode and Pseudocode Hardware, design and procedures Finished Abstract specification Computer Science Form 4 Actual physical specifications Career Science Input the number of hours Display “Your salary is RM” Physical Computer SDLC Logical So far, Malaysia has managed to win two silver medals and three bronze medals since participating in this competition from 2012. Input, output, process and security controls Start Mark Zuckerberg's Success Secret goo.gl/WJirLL SHAPE Figure 1.71 Design from logical and physical aspects Input hourly rate Calculate staff salary My Malaysia A description of what the system will do The International Olympiad in Informatics (IOI) is one of the international competitions in the field of science and informatics. This annual competition comparable to the Olympics aims to generate interest in computer science and programming among high school students. Description of the function of a system 170 Machine Translated by Google
29 Coding also changes program specifications to source code. used for the variable hourly rate a person works and staff wages. The variable names used are 'gajistaf' and 'kadarsj'. The arithmetic solution is to multiply the rate per hour worked by the number of hours worked. The results of this application will display staff salaries. The main purpose of the solution implementation phase is to transform the design into a program that will be installed on the hardware and ready to implement the solution. In addition, this phase aims to build and produce a system that can solve the problems faced. Application development activities involve coding. Coding requires programming languages such as Java, Javascript and so on. Compilation is the process of converting programming code into executable code. After preparing the pseudocode and flow chart, we can go to the next step which is the implementation of the solution to find the staff salary by writing program code. The data type used is an integer for the variable number of working hours, which is 'bilJam', while double public class HelloWorld { // Display the text } } //Program to display Hello World message public static void main(String[ ] args) System.out.println(“Hello World!”); The importance of interviews and questionnaires to obtain the information needed in the analysis phase. Figure 1.72(a) Example program code Figure 1.72(b) Example of executable code CHAPTER 1 PROGRAMMING Pseudocode and Flowcharts Daily Application goo.gl/FTn1QW 171 (a) Display the text "Salam 1Malaysia", "Congratulations on coming to school today." (b) Comment on the score. If 86-100%, “Well done, keep up the good work!” 60-85%, “Good, you can go further!” Less than 60%, “Don't give up, try again until you succeed!” Write the pseudocode and sketch the flowchart for the situation below: 1.7.1.3 Solution Implementation Phase Teamwork Machine Translated by Google
Solution analysis, design and implementation phases Shape Computer Science Form 4 Implementation of the solution (a) Number of years working 1-3 years, hourly rate is RM12.50 (b) Number of years working 4-6 years, hourly rate is RM14.00 Build a program code (c) Number of years working 7 years and above, the hourly rate is RM16.00 for staff salaries with the provisions as shown below: Analysis Mind Test 30 int billHours = 20; double gajistaf, kadarsj; gajistaf = rateh*billHour; System.out.println(" Your salary is RM"+staff salary); public static void main(String[] args) { } ratej = 25.0; public class Employee { } Individual Work Fill in the blanks with the activity in the correct phase. System Design Specifications Instructions for Programmers System design specifications System Requirements New System System Proposal Maintenance Plan 172 Machine Translated by Google
Follow the fascinating stories of programmers who are working hard to innovate in the field of computing. What improvement measures are needed for an error-free program? Test and showcase your work. As a review exercise, state what are logical syntax errors and runtime errors? Computer CHAPTER 1 PROGRAMMING goo.gl/WqE12V Science Innovation goo.gl/ZFav0F Mind Test Phases of System Development Life Table 1.22 Types of review Types of errors such as syntax errors, logical errors and run time errors are performed until the program code is free from all errors. All errors found, fixed and retested. a Ensure all requirements are met. b Ensure all coding works as intended. d Obtain feedback from system users for the purpose of correction and improvement. g Help the project team create documentation by tracing In this phase, the completed program code will be tested. The testing phase plays an important role in the SDLC. This phase has several purposes as follows: user error. f Detect dropped errors. Code review (code review) is done to detect errors. The programmer will refer to the displayed log to correct and remove the detected errors. The review can be made in three stages as in Table 1.22. e Involve users fully at the development stage. h Save test results as proof of completion of system development. c Ensure all modules can work when combined. 1.7.1.4 Test and Debugging Phase 173 Who? Author After completing the module Review Alone After completing the module Type After the above two stages Peer Peer Peer When? Project team led by programming language experts During coding Machine Translated by Google
Syntax error Types of Testing Integration Text spelling of variable names Details Alone These tests are carried out during integration testing by system users to ensure that it meets the user's requirements. Tick (ÿ) or (x) Comment text spelling Input calculations for hourly rates Runtime error Item Check the staff salary output Ensure that the system can work with the existing system. System Activities Input the calculation for the number of hours Ensure that every unit in the built system works. Acceptance Logical error Testing the system as a whole after testing individual units. 174 Computer Science Form 4 Data type declaration for staff salary Table 1.23 Staff salary calculation checklist Hourly rate data type declaration Table 1.22 Types of testing and details Data type declaration for the number of hours worked goo.gl/vjCiLm Steps to test the program according to the built program Use of unfamiliar objects or characters In application development, documentation is an ecosystem of content with the purpose of teaching users to interact with the Application Programming Interface (API). An API is a set of routines, protocols and tools for building applications. An API defines how application components should interact. A good API makes application development easier by providing development blocks, into which computer programmers can stitch the blocks together. Test scripts need to be written to automate the system module testing process because there are tests that need to be done repeatedly. Imagine being in a situation when ordering food at a restaurant where the server is an API. The kitchen and the menu are part of the system. The server as an API will take your order and tell the kitchen i.e. what system to execute. Then, the waiter will bring you food, which is a response back to you. Examples of APIs are Google maps API and Twitter API. Tick in the checklist below to test and debug staff salary calculations. Machine Translated by Google
Testing and Debugging CHAPTER 1 PROGRAMMING 1.7.1.5 Documentation Phase 175 Documentation is a process of collecting and gathering data, gathering information and summaries such as test reports, flowcharts, program codes and IPO charts. These documents are very important for the reference of system users, IT officers and even new staff at each phase. For example, a Gantt chart is an important document because a Gantt chart sets deadlines for each stage of development. Therefore, complete documentation of the project phase from the beginning in each phase will be used as a reference for the next phase. a comment for the code of the staff salary calculation program Each phase must be completed before proceeding to the next phase. The result of one phase serves as an input for the next phase sequence. An example of documentation in the application for calculating staff salaries is as shown below. Pair Work 31 POS system at CZF Restaurant Sdn. Bhd. State the type of testing that should be carried out based on the situation below. Application of the addition operation in the arithmetic system (1-10) Revenue Management System School Examination Analysis System (SAPS) Borrowing books at the School Resource Center (PSS) Types of Testing Pupil Registration System to be used with the System The situation ratej = 25.0; // Get the hourly payment rate data double gajistaf, kadarsj; //Variable declaration int billHours = 20; //Variable declaration Machine Translated by Google
Stated in RM Computer Science Form 4 By referring to the phases in the Waterfall Model, we can build and produce problem-solving applications that contain b Gantt chart for application development to calculate staff salaries d API c Testing and debugging Input: Number of hours worked Cannot be a negative number Type 3. Build an algorithm to calculate staff salaries rate double 5. Conduct testing and debugging Notes Input: Hourly Rate Notes integers double correct the error 20 500.00 Hourly rate March 20 March 21 March 22 March 23 March 24 March 25 March 26 March 27 March 28 March 8. Documentation 2. Get information for the work done by the staff Staff Name Description 4. Build program code payroll Name Output: Staff Salaries A101 hour bill The product of the number of hours worked by the hourly rate 6. Improve and Stated in RM 7. Using the program - staff salary List of Activities Number of hours worked 1. Prepare a staff information form 25.00 1.7.2 Application or Applet Creation 176 Machine Translated by Google
Design a solution Documenting Analyze problems to determine requirements Implement a solution Testing and debugging 177 Graphical user interface (GUI) is a user interface that allows users to interact with systems such as computers and smartphones. A key feature in a GUI is that indicators and icons are visual in nature. Users can perform actions by manipulating or manipulating the graphic icon. In our daily lives, we often face situations that require a solution. However, many problems can be solved with simple application development. Let's look at the problem of finding the area of an object that is often solved in Mathematics subjects. An alternative method of solution can be made by building a simple application. subroutine or array using stack statements and control structures in producing output based on the given input as in the figure shown below. Figure 1.74 An example of a graphical interface display CHAPTER 1 PROGRAMMING goo.gl/Nf1bQq Figure 1.73 Steps to create an application or applet Learn JavaScript Java Applets goo.gl/otWkD1 Daily Application Machine Translated by Google
Table 1.24 Analysis of IPOs —2 Among the applications successfully commercialized by local application developers in the Apps Store are unXT Sports (game) by Just Mobile Sdb Bhd, Ganoo Jump (game) by Commix Arts Sdn Bhd, ESentral (e-book) by Xentral Methods Sdn Bhd and YaHanana Club (entertainment) by CouponXcess Sdn Bhd. Computer Science Form 4 goo.gl/BP6bCV My Malaysia goo.gl/bf0FD6 1 Debugging Source: http://www.kkmm.gov.my/ Applet vs Java Application 178 The data that students need to know is the shape of the object and also the formula to find the area of the object. Other information to know is the meaning of terms such as radius, height, base and width. Step 2: Design the Solution a Write pseudocode for an application to find the area of an object The identified problem is a program to find the area of an object that is either a circle, triangle or square. This program needs to solve the problem with students choosing the type of object, entering input and output will be produced based on the object and input entered. b Build a graphical interface to make choices to find the area of an object, after which type the program code for each choice This phase can be started by writing pseudocode, followed by sketching a flow chart to design a solution for an application to find the area of an object. Step 1: Problem Analysis Phase OUTPUT Check the staff salary output Width Calculate the area of the object = x width x height Get the width Object selection Height Get the object INPUT Area of the object PROCESS 5. Input width and height 3. Optional input name 3 objects x width x height 7. Display wide 1. Start 2. Display “Please make your selection” and three will be displayed. 6. Area = 2 4. If you select a triangle, the form calculates the area of the sides 1 8. End Machine Translated by Google
Complete the flowchart below to find the area of the selected object, for example for the area of the given triangle. After that, test the algorithm to find the area of the selected object and record the test results. 179 Broad Start Start 2 *width*height Yes Nope Area = height 1 Read it Finished width CHAPTER 1 PROGRAMMING Display the triangular form — Triangle Display Machine Translated by Google
After knowing how to sketch a flow chart to design the solution required for an application to calculate the area of an object, then a graphical interface can be prepared for the application. The example shown in Figure 1.75(a) is a suggested graphical interface for calculating the area of a circle. By using the provided tools from Swing Controls, build an interface for the display to calculate the area of the object. Tools that need to be used are Label, Button and TextField. The function of jButton is to provide three options, namely Calculate, Reset and Exit. Jlabel is used to label and display output; and jTextField to input data. Figure 1.75(b) shows the 'tools' used to build a graphical interface as shown in Figure 1.75(a). By using the provided tools from Swing Controls, build an interface to display the area of the object. The tools you need to use are Label, Button and TextField. The function of jButton is to provide three options namely "Calculate", "Reset" and "Exit". Jlabel is used to label and display output and jTextField to input data. Calculate Image Calculate the area of a circle Reset Get out Radius2 Broad c Provide a graphical interface for the application. Text Computer Science Form 4 Java – Lesson using swing controls Labels Figure 1.75(b) Swing Controls used to build a graphical interface goo.g1/5Ria3Z Java - How to use various components Figure 1.75(a) Proposed graphical interface Button goo.g1/5Ria3Z 180 Machine Translated by Google
CHAPTER 1 PROGRAMMING Graphical interface sketch Figure 1.75(c) How to change the 'border' 32 Figure 1.75(c) shows how to change the 'border' of the "graphical interface" in Figure 1.75(a). Individual Work Using a jframe as shown in the figure below, sketch the graphical interface for the 'Calculate Object Area' view. Rearrange Swing Controls according to your creativity. You can insert an image for the jframe background when generating this interface in Netbeans Java software. 181 Machine Translated by Google
Input After building the desired design, the next process is to implement the solution. Pupils can build a 'jframe' in Netbeans Java software and write the correct program code. Here's how to build an interface for finding the area of a circle and program code. Try testing the program you have built. Step 3: Implementation of the Solution a Build a “graphical interface” to make options for finding the area of an object, then type in the program code for each option. Method Figure 1.75(e) The interface for calculating the area of a circle and the program code for the area of a circle Computer Science Form 4 JavaLang Floatparse Float() goo.g1/pOENQs Output Figure 1.75(d) Interface for making object selections to find the area and program code of each selection 182 Machine Translated by Google
Problem Analysis Implement ACTIVITY Design a solution Solution Testing and debugging PHASE a Enter the required inputs, then check the output produced. If there is an error, we need to delete/debug and fix it. Next, the system needs to be tested again to ensure that the program is error-free. Step 4: Testing and Debugging Step 5: Documentation b Test all the units that have been built, display the output of the application that has been built. Can the application that has been built produce the desired output? After successfully building the interface and program code for all three objects, test each program that has been developed. In order to test and debug errors that exist in a developed program, steps such as the following need to be done. Document each phase of the process of creating an application to find the area of the selected object. Show off your work in the form of a presentation and discuss in a group. CHAPTER 1 PROGRAMMING goo.g1/gKW2Ts Figure 1.75(f) Display of testing program and the output of testing carried out How to debug in Java? 183 Machine Translated by Google
1 2 Plan the phases of the system development life cycle completely based on the diagram shown below. Then, build an error-free program and show off your work. The diagrams below can be used as a guide to complete your project. Plan the phases of the system development life cycle completely based on the diagram shown below. Then, build an error-free program and show off your work. The diagrams below can be used as a guide to complete your project. Mix and match School Gate Counting Two Numbers for Operations Message Display for Notice Boards at Pair Work Individual Work programming Get NetBeans from: programming (b) Goodness in terms of: (a) Career in Computer https://techprep.fb.com goo.gl/bWL9Cg Computer Science Form 4 Programming description /why/ programming Career Science (c) Career future 184 Machine Translated by Google
(b) Build the above application with Netbeans Java software, test and debug the errors found. 1 500. Display your answer in 1 Based on the pseudocode below, sketch a flowchart to design a solution to problem below. (c) Try to find the square root answer https://www.youtube.com/watch?v=Hs3Ulbx1GPA (a) Sketch the algorithm and explain the program code that has been used. (d) Type the above program code in Java Netbeans, display the result of the nom1-nom2+nom3 operation if nom1 = 30, nom2=7 and nom3=10. (c) What display is produced when the above program is tested? shape as on the side. 3 Watch this video about building an applet for finding the square root of a number at (d) Round your answer to two decimal places in the constructed program. (a) Name all the variables used. to the following numbers: 120, 975 and 2 Refer to the diagram below and answer the following questions: (b) State the type of data represented by the variable. CHAPTER 1 PROGRAMMING Formative Training 1.7 If age >= 60 then " OUTPUT What's your name?' OUTPUT “Well done + name, you are retired!” + answer ); nom1 = 15; nom2 = 40; answer = nom1 + nom2; INPUT user enter age System.out.println("Mixed result = SAVE user input as age variable OUTPUT 'Good morning' + name public static void main(String[ ] args) { OUTPUT 'How old are you?' int nom1, nom2, answer; INPUT user enter name ELSE SAVE user input as variable name OUTPUT “WAH+NAME, YOU ARE STILL YOUNG.” 185 Machine Translated by Google
4 The following program is to produce an application of mathematical operations. (a) Name the variables in this program. (b) Sketch the graphical interface for the above application. 5 Create a simple game involving the use of numbers or the alphabet. The age level Suitable for this application are preschoolers. Based on the program: (c) Implement the above solution by producing an error-free application. Computer Science Form 4 186 Machine Translated by Google
Relational operators, logical operators, multiplication operators, subtraction operators, Linear Real numbers Parameterized Translate algorithms into programming languages Repeat A string Universal Subatur Cara • if-else • for • Define action Procedure • Implement solutions Array parameters • Arithmetic statements Integer • do-while • Make an assessment • Generate ideas-remove obstacles Characters Pseudocode Options • Generate solutions • Define the problem • Make improvements Math random and Boolean flags Array • switch-case Flowchart Local Boolean Without parameters • Statement of focus CHAPTER 1 PROGRAMMING Function • while • Collect and analyze data Algorithm Control structure Problem solving strategies Fix the error Programming Modularity and data structure Variables, constants Identify the output Data types RESCAN 1 2 4 6 3 8 5 7 187 Machine Translated by Google
SDLC 1 3 4 5 2 Runtime error Programming best practices Variables Meaningful Comment Indent Display the output Logical error Application development Detect and fix errors Input Stack up Identify the value of a variable on a given section Expression Syntax error Identify the Good style output • Test and debug • Shape • Problem analysis • Execute Computer Science Form 4 • Documentation 188 Machine Translated by Google
Objective Questions 1 SUMMATIVE TRAINING I Detailed instructions D programmers can produce error-free programs that are easy to understand. C Improve thinking skills III Scaling D The process of designing the details of a problem to obtain a solution. D All of the above A = False the ability to make decisions based on conditions that have been determined by the programmer. A provides computer software C II, III and IV B Programmers can write program code well. make referrals based on conditions that have been determined by the organizer B The process of studying the details of something A I, II and III B final D Public B Encourage self-learning II Pattern recognition D enables computer software B provides computer users 4 What are the exact characteristics of an algorithm? common practices followed to produce a good program. 5 What is the function of the optional control structure? B I, II and III A The programmer can run the program without any errors. A The process of delving into the details of a problem to find a solution. IV Feasible A int C Class I Solution Technique way. C = True to explain the concept of problem solving? III Has limitations the ability to make decisions based on conditions that have been determined by the programmer. D All of the above C programmers can practice A Helping the development of a concept Answer all questions. C The process of reviewing the details of a problem to find a solution. C III and IV boolean variable. the following is used to declare and allocate storage space for one or more variables? 2 Which is the correct statement? A I and II 6 What is meant by best practice in programming? C enables computer software II The details are clear 7 Which of the key words which 1 Which of the following is an incorrect statement about why strategies are needed in problem solving? 3 Which of the following is an accurate statement about techniques in problem solving? make an assessment based on the conditions that have been determined by the regulator B = True problem to find a solution. B II, III and IV 8 The information below refers to some values D Create one-way communication IV Algorithms way. CHAPTER 1 PROGRAMMING 189 Machine Translated by Google
Structured question Number < 0 "Zero" OUTPUT Number > 0 "Positive numbers" OUTPUT OUTPUT Computer Science Form 4 "Negative numbers" Finished Start C Do… Until will check the condition after the command block is repeated A C Or (A And Not C) C produce a neat plan about 1 Write Java programming code to implement the following algorithm. This program code can receive input data from the double type keyboard. C Not A Or Not(B Or Not C) B (B Or C) Or Not A 9 The following options are true regarding Do... While loops and Do... Until loops, EXCEPT A writes software using programs such as Java. Answer all questions. Which of the following gives a False result? statement in a loop when the condition being tested returns a false result B collects user requirements regarding the desired program functions. how software is developed to meet user needs. 10 The analysis phase of software development involves activities... D all of the above D Not C Or ( A And (B Or C)) A Do… While is also called a pretest loop D Do… While will just process B Do… Until will repeat the command block in a certain frequency Flowchart 190 Machine Translated by Google
i++; public class Tutorial4 { public static void main(String[] args) { String x = “22”; public static void main(String[] args) { int i = 0; } public class Use_While { } } } } String y = “88”; while (i < 5){ System.out.println(x + y); System.out.println(“Welcome To JAVA Programming”); Output <= 18.5 >= 30 = 18.5 – 24.9 Your health is good 3 Less weight Obesity CHAPTER 1 PROGRAMMING default BMI reading 1 Input You didn't choose 1, 2 or 3! Normal 2 Decision Heavier Your health is satisfactory = 25 – 29.9 You are not well 2 Determine the output of the following program: Answer all questions. integer type. Then, the program will display the output as below. 4 What is the function of the loop control structure involving Math.random()? 3 What is the possible output of the program below? 1 Write a Java program using a switch-case control structure to accept a number input 2 Generate an error-free program to calculate BMI (Body Mass Index). Your program must be able to accept weight and height in doubles and be able to display the results as below. Problem solving 191 Machine Translated by Google