Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

------------------------------ WordData : import java.util.ArrayList; public class WordData { private String word; private ArrayList lineNumbers; private int WordCount; public WordData(String word, ArrayList lineNumbers, int wordCount)

image text in transcribed

------------------------------

WordData :

import java.util.ArrayList;

public class WordData {

private String word;

private ArrayList lineNumbers;

private int WordCount;

public WordData(String word, ArrayList lineNumbers, int wordCount) {

this.word = word;

this.lineNumbers = lineNumbers;

WordCount = wordCount;

}

public String getWord() {

return word;

}

public ArrayList getLineNumbers() {

return lineNumbers;

}

public int getWordCount() {

return WordCount;

}

public void setWord(String word) {

this.word = word;

}

public void setLineNumbers(ArrayList lineNumbers) {

this.lineNumbers = lineNumbers;

}

public void setWordCount(int wordCount) {

WordCount = wordCount;

}

@Override

public String toString() {

String res = word + " appears " + WordCount + " times on " + lineNumbers.size() + " lines: ";

int i=0;

for(i=0;i

res += lineNumbers.get(i) + ",";

}

res +=( lineNumbers.get(i) +"..." + lineNumbers.get(lineNumbers.size()-1));

return res;

}

@Override

public boolean equals(Object other) {

// TODO Auto-generated method stub

WordData obj = (WordData) other;

return word.equals(obj.word);

}

int compareTo(Object other) {

WordData obj = (WordData) other;

if(this.WordCount > obj.WordCount) {

return -1;

}else if(this.WordCount == obj.WordCount) {

return 0;

}

else

return 1;

}

}

----------------------

TestA4 :

public class TestA4 { public static void main(String[] args) { WordDataArrayList test = new WordDataArrayList(); try{ System.out.println("Testing WordDataArrayList basic operation: "+ "==========================================="); System.out.println("Should be empty list: "+test+" ----------"); test.add(99,"at"); System.out.println("Should be at(1 1)(99): "+test+" ----------"); test.add(103,"at"); System.out.println("Should be at(2 2)(99 103): "+test+" ----------"); test.add(103,"be"); System.out.println("Should be at(2 2)(99 103) and be(1 1)(103): "+test+" ----------"); } catch(Exception e){ System.out.println("Basic WordDataArrayList tests failed"); } try{ System.out.println(" Testing WordData equals and compareTo: "+ "======================================"); System.out.println("should be false: "+test.get(0).equals(test.get(1))); System.out.println("should be true: "+test.get(0).equals(test.get(0))); System.out.println("negative/positive may be reversed if \"be\" comes before \"at\":"); System.out.println("should be negative: "+test.get(0).compareTo(test.get(1))); System.out.println("should be 0: "+test.get(0).compareTo(test.get(0))); System.out.println("should be positive: "+test.get(1).compareTo(test.get(0))); } catch(Exception e){ System.out.println("WordData equals/compareTo tests failed"); } try{ System.out.println(" Testing WordDataArrayList additional operation: "+ "==============================================="); for(int i=0; i

} catch(Exception e){ System.out.println("WordScanner tests failed"); } } }

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

The Manga Guide To Databases

Authors: Mana Takahashi, Shoko Azuma, Co Ltd Trend

1st Edition

1593271905, 978-1593271909

More Books

Students also viewed these Databases questions

Question

Explain the key areas in which service employees need training.

Answered: 1 week ago

Question

Understand the role of internal marketing and communications.

Answered: 1 week ago