Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For Eclipse Word Project Use these two classes below - Word - WordTest as starter files for a project named WordProject. Complete the class named

For Eclipse
Word Project
Use these two classes below
- Word
- WordTest
as starter files for a project named WordProject. Complete the class named Word by correctly implementing the constructors and following
methods:
String getWord()- an accessor method that returns the String property of the Word object
String getFirstLetter()- returns the first letter of the Word object.
String getLastLetter()- returns the last letter of the Word object.
void removeFirstLetter()- permanently removes the first letter of the Word object.
void removeLastLetter()- permanently removes the last letter of the Word object.
int findLetter(String stringToFind)- the position of the first occurrence of the String stringToFind is returned if it is present in
the Word object. Otherwise, the method returns the value -1.
Edit and complete the class named WordTest which constructs a Word object and uses Scanner to test the Word class methods with a user's
inputted word. The client program must use and test every method from the Word class and display annotated output so that the instructor can
easily tell that the methods work properly.
Preconditions:
o A Word object is one word with three or more letters when each of the methods above are invoked.
You must hand in the following on separate pages stapled in this specified order:
1. The source code for the Word class.
2. The source code for the WordTest class.
3. The printscreen of your console window output.
/**
Word
@author John Doe Period 4
*/
public class Word
{
public Word()
{
myWord ="";
}
public Word(String word)
{
myWord = word;
}
public String getWord()
{
return myWord;
}
public String getFirstLetter()
{
return "a";
}
public String getLastLetter()
{
return "z";
}
public void removeFirstLetter()
{
myWord = myWord.substring(0);
}
public void removeLastLetter()
{
myWord = myWord.substring(0);
}
public int findLetter(String stringToFind)
{
return -1;
}
private String myWord;
}
/**
WordTest
@author John Doe Period 4
*/
import java.util.Scanner;
public class WordTest
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter a word: ");
String userInput = keyboard.next(); // user's inputted word
Word word1= new Word(userInput); // testing other constructor
System.out.println("You entered the word: "+ word1.getWord()); // testing
getWord
System.out.println("The first letter of your word is: "+ word1.getFirstLetter()); // testing
getFirstLetter
word1.removeFirstLetter();
System.out.println("The word without the first letter is: "+ word1.getWord());
// testing removeFirstLetter
System.out.print("Enter a letter to find: ");
String letter = keyboard.next(); // letter to find
// more code here to test other methods of Word class
}
}

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_2

Step: 3

blur-text-image_3

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 Database Relational Model A Retrospective Review And Analysis

Authors: C. J. Date

1st Edition

0201612941, 978-0201612943

More Books

Students also viewed these Databases questions

Question

6.2 Describe the key features of dissociative amnesia.

Answered: 1 week ago