Question: ArraySum Method to transform a number of an array Assume that we receive two numbers with the same number of digits. We should transform each

ArraySum 

Method to transform a number of an array

Assume that we receive two numbers with the same number of digits. We should transform each number into an array of integers that represent the given number such that each element is a digit in the array. example: given number:

1234->[1,2,3,4]

InArraySum.javaimplementthisfunctionalityinsidethetransformmethod.

int[]transform(intnum)



1b)Methodtocomputethesumoftwoarraysthatrepresentaverybignumber.

Assumeyouhavetwoarraysofintegersthatrepresenttwoverybignumbersasexplainedaboveand shown as follows:

Atthisstep,weshouldtransformthetwobignumbersintotwoarrays. First:

transform(1234)->awhichis[1,2,3,4]

transform(1211)->bwhichis[1,2,1,1]

Weknowthataandbrepresent1234and1211respectively.

Now,completethefollowingmethodinArraySumclassthatcomputesthesumoftwogivenarrays.


Note:Youarenotallowedtotransformthearraysintointegersandthencomputethesumsincethe numbers will be very large numbers and you cannot store them into simple primitive data types.


Hint:Inmath,wealwaysstartfromthelastdigitintheright(indexi).Inthecaseofhavingacarry,we should include it in the sum calculation of the next digits (index i - 1).int[] sum(int[] a, int[] b)


Testcase 1:

a->[1,2,3,4]

b->[1,2,1,1]


sum(a,b)->sum([1,2,3,4],[1,2,1,1])

Theresultis:[2,4,4,5]



Testcase 2:

a->[1,2,3,4]

b->[9,2,9,5]


sum(a,b)->sum([1,2,3,4],[9,2,9,5])

Theresultis:[1,0,5,2,9]



Note:You are not allowed to useArrayList or other data structures that we have not covered in the class in order to solve this question.


Question2:TMax (40points)


2a)Generatearandomarray

InTMax.java,completethegetRandomArray()methodthatisresponsibletogenerateaonedimensional random array with the size of a random number between 2 and 10. Then populate the Array with some random real values from [0, 1].

Note:youcansettheseedbyusingtheargsinthemainmethod.


Outputexamples:

Theoutputresultsmightbevarieddependsontheseedthatyouareusing.

getRandomArray() -> [0.123, 0.235, 0.3573, 0.657]

getRandomArray() -> [0.067,0.235,0.657]


2b)Findthethirdbiggestnumberinthearray

Then, complete thirdBiggest(int[] array). This method should accept an array that we generated above and return the third biggest number in this array. In the case of having less than three numbers that are bigger than the rest of the elements, you should return the maximum.

Note:Youarenotallowedtousethepredefinedsortmethodinjavaorothersorting algorithms.

Testcase 1:

a -> [0.123, 0.235, 0.3573, 0.657]

thirdBiggest(a)->0.235

Testcase 2:

a->[0.067,0.235]


AsexplainedaboveinthiscaseweshouldreturntheMaximumnumber.Therefore:

thirdBiggest(a)->0.235



Question3:Rotatea2DArray (30points)

InRotate.java,completethemethodofrotate180.Themethodreceivesa2Darrayofintegersandrotatesthegiven 2D array in 1800 degrees (clockwise).


Assumematrix"a"representa2Darrayasfollows:



1

2

3

4

5

6

7

8

9

10

11

12

13

1415

16

17

18

1920

21

22

23

2425




Afterrunningtherotate180(a)thematrixshouldbechanged(in-place)suchthatithas180degreesrotationof elements.


Therefore,afterrunningrotate180(a)thematrix"a"willchangetothefollowingmatrix:




25

24

23

22

21

20

19

18

1716

15

14

13

1211

10

9

8

7

6

5

4

3

2

1



WhatToSubmit

Please put all your files in a folder called Assignment3. Zip the folder (DO NOT RAR it) and submit it through MyCourses.

Insideyourzippedfolder,theremustbeonlythefollowingfiles.Donotsubmitanyotherfiles,especially

.classfiles.Anydeviationfromtheserequirementsmayleadtolostmarks.

ArraySum.java TMax.java Rotate.java

Confession.txt(optional)Inthisfile,youcantelltheTAaboutanyissuesyouranintodoingthis assignment.

5 5 Rotate.java x public class Rotate { public static void main(String[]args) { int[] [] matrix = { {1, 2, 3, 4, 5},{6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}, {16, 17,

5 5 Rotate.java x public class Rotate { public static void main(String[] args) { int[] [] matrix = { {1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}, {16, 17, 18, 19, 20}, [21, 22, 23, 24, 25} }; print (matrix); rotate180 (matrix); System.out.println("\1 print (matrix); 5 A 8 public static void rotate180 (int[] [] matrix) { } // TODO Implement this part of the code. public static void print (int[] [] matrix) { for (int i = 0; i < matrix.length; i++) { for (int j = 0; j < matrix[i].length; j++) { } System.out.print (matrix[i] [j] + " "); System.out.println(); A } # ");

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

public class ArraySum public static void mainString args int nu... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Operating System Questions!