Search Header Logo
2024-06-23

2024-06-23

Assessment

Presentation

Computers

11th Grade

Practice Problem

Easy

Created by

Arasaka Teacher

Used 1+ times

FREE Resource

1 Slide • 5 Questions

1

9618-paper2

By Arasaka Teacher

2

Open Ended

Question image

public class AlgorithmExample {

public static void main(String[] args) {

int[] data1 = {1, 2, 3, 4};

int[] data2 = {5, 6, 7, 8};

// 计算 data1 的平方和

int sum1 = 0;

for (int num : data1) {

sum1 += num * num;

}

System.out.println("data1 的平方和: " + sum1);

// 计算 data2 的平方和

int sum2 = 0;

for (int num : data2) {

sum2 += num * num;

}

System.out.println("data2 的平方和: " + sum2);

}

}

3

Drag and Drop

:
The calculateSquareSum method can be called anywhere in the program without​
.




:
If the calculation logic needs modification (e.g., changing to cube sum num num num), only the calculateSquareSum method needs adjustment,​
the need to modify all code segments using the algorithm.




:
The main program logic becomes clearer and easier to understand, as complex algorithms are abstracted into dedicated methods.
Drag these tiles and drop them in the correct blank above
Improved Readability
Code Reusability
rewriting duplicate code
Enhanced Maintainability
eliminating
Increased Complexity
Reduced Performance
More Code Duplication

4

Reorder

————————:

Look at the code that is used in many places and does the same calculation.

————————:

Create a new method (or function) and put the repeated code inside it.

Make sure this method can take different data, such as an array of numbers.

————————:

Let the method give back the result of the calculation so the rest of the program can use it.

————————:

Replace the old repeated code with calls to the new method.

Send the needed data to the method when calling it.

——:

Verify that the new method works correctly with various inputs.

Ensure that the overall program behaves as expected after the modification.

Find the Repeated Code

Make a New Method

Return the Result

Use the New Method

Test and Validate

1
2
3
4
5

5

Dropdown

1. ​


List the Variables:

Write down all variables you will use. For example:

declare A, B, C

Initialization:

Remember to initialize variables. For example:

initialize A to 0



2. ​


Identify Needed Structures:

Decide if you need an array, a record, or a file. For example:

declare an array called Numbers

or

declare a record called Student

3. ​


Loops and Repetition:

Describe how the loop works. For example:

: “set a conditional loop, repeating until the condition is met.”

For Loop: “set a ​
to iterate through the objects.”File Operations (if needed):

If your program uses a file, include steps like:

open file in read mode

read data from the file

close the file



6

Dropdown

4. ​


Assignment and Calculation:

For assignment, use words like “set” or “assign”.

Example: “assign A to B”

For addition: “calculate the new value of C by adding A to B”

For subtraction: “calculate the new value of C by subtracting A from B”

For multiplication: “calculate the new value of C by multiplying A by B”

For division: “calculate the new value of C by dividing A by B”

s:

Example: “obtain the new string by concatenating A with B, and assign the new string to Variable2.”

Prompting the User:

Always include a prompt when the program should ask for user input.

Example: “display prompt 'Enter a number:'”

5. ​
Mark Loop Ends:

Write “end while” or “next i” after the loop to show it ends.

Always indicate when a block of instructions is finished.

6. Using Functions (if any)

Call Functions Clearly:

Example: “use the function INT() to obtain the whole number part of the digit.”

9618-paper2

By Arasaka Teacher

Show answer

Auto Play

Slide 1 / 6

SLIDE