Question: File 1 : { private String word; public StringStuff ( String word ) { this.word = word; } public String getFirstLastLetters ( ) { return

File 1:
{
private String word;
public StringStuff(String word)
{
this.word = word;
}
public String getFirstLastLetters()
{
return word.substring(0,1)+ word.substring(word.length()-1);
}
public char getMiddleLetter()
{
int middlePosition = word.length()/2;
if (word.length()%2!=0){
return word.charAt(middlePosition);
}
else {
return word.charAt(middlePosition -1);
}
}
public int diffInASCII( String letter )
{
return -1;
}
public boolean sameFirstLastLetters()
{
if (word.length()<1){
return false;
}
else {
return word.charAt(0)== word.charAt(word.length()-1);
}
}
public String toString()
{
return ""+ word;
}
}
File 2:
import java.util.Scanner;
public class StringRunner
{
public static void main ( String[] args )
{
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter a word :: ");
String word = keyboard.nextLine();
StringStuff myWord = new StringStuff(word);
System.out.println("Has first last letters :: "+ myWord.getFirstLastLetters());
System.out.println("Has middle letter :: "+ myWord.getMiddleLetter());
System.out.println("Has same first and last letters :: "+ myWord.sameFirstLastLetters());
}
}
How do i get the ASCII method right?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!