Question: ***Please help me write this JAVA code using this psudocode. 6 Pseudocode Method Run() Returns Nothing Declare and create an ArrayList of Integers named list

***Please help me write this JAVA code using this psudocode.

6 Pseudocode

Method Run() Returns Nothing

Declare and create an ArrayList of Integers named list

list ReadFile("p01-in.txt")

Declare and create an ArrayList of Integers named listRunsUpCount

Declare and create an ArrayList of Integers named listRunsDnCount

listRunsUpCount FindRuns(list, RUNS_UP)

listRunsUpCount FindRuns(list, RUNS_DN)

Declare and create an ArrayList of Integers named listRunsCount

listRunsCount Merge(listRunsUpCount, listRunsDnCount)

Output("p01-runs.txt", listRunsCount)

End Method Run

Method FindRuns(In: pList is ArrayList of Integers; int pDir is RUNS_UP or RUNS_DN) Returns ArrayList of Integers

listRunsCount arrayListCreate(pList.size(), 0)

Declare int varaibles i 0, k 0

While i < pList.size() - 1 Do

If pDir is RUNS_UP and pList element at i is pList element at i + 1 Then

Increment k

ElseIf pDir is RUNS_DN and pList element at i is pList element at i + 1 Then

Increment k

Else

If k 0 Then

Increment the element at index k of listRunsCount

k 0

End if

End If

Increment i

End While

If k 0 Then

Increment the element at index k of listRunsCount

End If

Return listRunsCount

End Method FindRuns

Method Merge(In: pListRunsUpCount, In: pListRunsDnCount) Returns ArrayList of Integers

listRunsCount arrayListCreate(pListRunsUpCount.size(), 0)

For i 0 to pListRunsUpCount.size() - 1 Do

Set element i of listRunsCount to the sum of the elements at i in pListRunsUpCount and pListRunsDnCount

End For

Return listRunsCount

End Method Merge

Method arrayListCreate(In: int pSize; In: int pInitValue) Returns ArrayList of Integers

Declare and create an ArrayList of Integers named list

Write a for loop that iterates pSize times and each time call add(pInitValue) on list

Return list

End Method arrayListCreate

Method Output(In: pFilename; pListRuns ArrayList of Integers) Returns Nothing

out open pFilename for writing

out.print("runs_total, ", the sum of pListRuns)

For k 1 to pListRuns.size() - 1 Do

out.print("runs_k, ", the element at index k of pListRuns)

End For

Close out

End Method Output

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!