Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Questions: a) Create the constructor in class Word. b) Draw the object referred to by reference w. c) Which output is generated if class Word

image text in transcribed

Questions:

a) Create the constructor in class Word. b) Draw the object referred to by reference w. c) Which output is generated if class Word is used like this?

char[] v1 = {'L', 'i', 'g', 'h', 't'}; Word w1 = new Word (v1); char[] v2 = {'L', 'o', 'v', 'e'}; Word w2 = new Word (v2); w1.combine (w2);

System.out.println (w1);

Please explain in detail how to think when tackling questions like these! :)

The class word represents a word. Characters in the word are stored in a sequence of linked nodes. class Word private class Node public char c; public Node next; public Node (char c) this c c; this next null the first node in the node sequence private Node first null Word creates a word from an array of characters code is missing here public String to String StringBuilder sb new StringBuilder Node node first; if (node null) while (node.next null) sb.append (node.c) i node node.nexti sb.append (node c) sb.append ("1") return sb. to String public void combine (Word w) if (w. first null) Node n1 this first Node n2 first if (this first null) this. irst new Node (n2.c) nl this. first; n2 n2.next while (nl.next null) nl ni next; while (n2 null) nl .next new Node (n2. c) i n1 nl .next; The class word is used like this: char CJ v 'L 'i', f 'e' Word W new Word (v); System Rpiniin (W); When this code fragment is executed, the following output is generated: [Life]

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database 101

Authors: Guy Kawasaki

1st Edition

0938151525, 978-0938151524

More Books

Students also viewed these Databases questions

Question

3. Job rotation is used for all levels and types of employees.

Answered: 1 week ago