Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Given that the private state variables of the class are: Display 10 lines public

ID: 3722640 • Letter: G

Question

Given that the private state variables of the class are: Display 10 lines public static final int LINES = 10; private ArrayList [| lines; urrentLine; private intc Give an algorithm for adding a wordlet to the current line, if lines] is already inilized as: lines = (AList []) new Alist[LINES + 1]; Algorithm addWordlet(Wordlet w) Give an algorithm for moving to the next line in the array lines, defined above. It goes to the next line, if the number of lines has exceeded LINES, shift them all up by one Algorithm nextLine 0

Explanation / Answer

(a)

function addWordlet(Wordlet w)

BEGIN

    // if the number of lines in lines is more than the // maximum size

    if currentline > LINES

    BEGIN

         // create a temporary array of double size

         temp = ( AList<Wordlet> [])ne AList[ 2 * LINES + 1 ];

         LINES = LINES * 2

         // copt content of lines to temp

         for i <- 1 to lines.length()

         BEGIN

             temp[i] = lines[i];

         END

         lines = temp

    END

    // add w to lines

    lines[ currentLine ] = w;

    currentLines++

END

(b)

function nextLine()

BEGIN

    // if number of lines has exceeded LINES

    if currentLine > Lines

    BEGIN

         // shift all lines up by 1

         for i <- 2 to currentLine

         BEGIN

             lines[i - 1] = lines[i]

         END

    END

END

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote