Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi, I'm doing an exercise and have a hard time understanding to read the instruction and how to proceed with writing this java code. class

Hi, I'm doing an exercise and have a hard time understanding to read the instruction and how to proceed with writing this java code.

class Word

[The Task]

image text in transcribed

2 Task1: The class Word Word has the class diagram shown to the left. Set the class constants to the values 0,1 , and 2 when you declare them. Use the name of the constants in your code (in all classes) since that makes the code easier to read. Initialize sortCriterion with ORIGINAL when you declare it. The instance variables the Word and count are initialized in the constructor. getCount() and getWord() return the values of count and the Word. setCriterion(arg) changes the value of sortCriterion to one of the class constants and getCriterion() returns its value. compareTo ( arg ) should always return 2 if sortCriterion == ORIGINAL. Otherwise, it compares two instances of Word either by the values of theWord or by those of count. Which one, depends on the value of sortCriterion. If sortCriterion equals BYNAME, compareTo(arg) should compare the values of the Word alphabetically. Use the instance 1 method compareTo(..) of String with the same name as yours (which compares two instances of Word) to compare the values of both strings the Word alphabetically. If sortCriterion equals BYCOUNTS, then your compareTo(..) method should compare the values of count numerically. For these two criteria, your compareTo(arg) method should send back one of the possible values 1,0, or 1 . It should return a value 1 if the value of the instance variable (either count or theWord) of the calling instance of Word is smaller than that of arg in the argument list of compareTo(arg). It should return 0 if the values of the instance variables match. If the value of the instance variable of the calling instance is larger than that of its counterpart in arg, compareTo(arg) should return 1. toString() returns a formatted string. It starts with "Word:" followed by the value of word in a column 10 characters wide and aligned to the right. You leave 3 empty spaces and write "Count:" followed by the value of count in a column 3 characters wide

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

Refactoring Databases Evolutionary Database Design

Authors: Scott Ambler, Pramod Sadalage

1st Edition

0321774515, 978-0321774514

More Books

Students also viewed these Databases questions