Please help, thanks! Exercise B : At this point package final1410 should include
ID: 3577413 • Letter: P
Question
Please help, thanks!
Exercise B:
At this point package final1410 should include a file called MyFile.txt
If you missed that step go to package explorer and add the file now.
So far no text has been added to the file. This needs to be done now.
Add the following three numbers to the file - each number in a separate line
2.345
6.4
8.7654321
Create a generic list called numbers
and read in all the numbers from MyFile.txt
At this point MyFile.txt includes 3 numbers. However, there could be more or less. If added or removed numbers from MyFile.txt your program should still read in all the numbers available in the file.
When reading numbers from the file you need to be prepared that a checked exception could occur.
In this exercise checked exceptions should be caught and in such situations the stack trace should be printed.
Print the list
Each element should be rounded to 2 digits after the decimal point and the elements should be separated by a space (see output)
Make sure to include a label.
Create a generic method called duplicateElements
It has one parameter, which is a generic List, and it returns a generic list.
The list that is returned should include each element of the original list twice (see example)
e.g. If the original list included 2.345, 6.4, and 8.7654321 then the modified list should include 2.345, 2.345, 6.4, 6.4, 8.7654321, and 8.7654321
Notice the order of the list elements
Also, notice that the list elements are not rounded; only the output is rounded.
In the main method call duplicateElements in order to duplicate the elements of list numbers
Print the list that was returned by the method duplicateElements
Make your output look like the output provided
Sample Output:
list : 2.35 6.40 8.77
double list: 2.35 2.34 6.40 6.40 8.77 8.77
Explanation / Answer
void metric linear unit (int c[][], int a[][], int b[][])
Here's my million instructions per second code:
.text
main:
j mm
mm:
la $a3, array_A # base address for array_A loaded into $a3
la $a1, array_B # base address for array_B loaded into $a1
la $a2, array_C # base address for array_C loaded into $a2
li $t1, four # $t1 = four (row-size and loop end)
li $s0, zero # i = 0; initialize first for loop
loop1:
li $s1, zero # j = 0; restart second for loop
loop2:
li $s2, zero # k = 0; restart third for loop
sll $t2, $s0, a pair of # $t2 = i * four (size of row of c)
addu $t2, $t2, $s1 # $t2 = i * size(row) + j
sll $t2, $t2, a pair of # $t2 = computer memory unit offset of [i][j]
addu $t2, $a2, $t2 # $t2 = computer memory unit offset of [i][j]
lw $t4, 0($t2) # $t4 = a pair of bytes of c[i][j]
loop3:
sll $t0, $s2, a pair of # $t0 = k * four (size of row of b)
addu $t0, $t0, $s1 # $t0 = k * size(row) + j
sll $t0, $t0, a pair of # $t0 = computer memory unit offset off [k][j]
addu $t0, $a1, $t0 # $t0 = computer memory unit address of b[k][j]
lw $t5, 0($t0) # $t5 = a pair of bytes of b[k][j]
sll $t0, $s0, a pair of # $t0 = i * four (size of row of a)
addu $t0, $t0, $s2 # $t0 = i * size(row) + k
sll $t0, $t0, a pair of # $t0 = computer memory unit offset of [i][k]
addu $t0, $a3, $t0 # $t0 = computer memory unit address of a[i][k]
lw $t6, 0($t0) # $t6 = a pair of bytes of a[i][k]
mul $t5, $t6, $t5 # $t5 = a[i][k] * b[k][j]
add $t4, $t4, $t5 # $t4 = c[i][j] + a[i][k] * b[k][j]
addiu $s2, $s2, one # $k = k + one
bne $s2, $t1, loop3 #if (k != 4) visit loop3
sw $t4, 0($a2) # c[i][j] = $t4
#----------TEST-------------
li $v0, 1