Question

Lab Description: Compare two Strings to see if each of the two Strings has the same first letter. Useful methods:: charAt) Sample Data: hello howdy one twO three two TCEA UIL State Champions ABC DEF Files Needed: StringFirstLetterCheck.java StringFirstLetterRunner.java Sample Output: hello has the same first letter as howdy one does not have the same first letter as two three has the same first letter as two TCEA does not have the same first letter as UIL State does not have the same first letter as Champions ABC does not have the same first letter as DEFimport static java.lang.System. public class StringFirstLettercheck String wordone, wordTwo; public stringFirstLettercheck() public stringFirstLetterCheck (string one, string two) public void setwords (String one, String two) public boolean checkFirstLetter() return false; public String tostring() return wordone +does not ha ve the sane first letter as wordTwoimport static java.lang.System.*i public class StringFirstLetterRunner public static void main( String args) /add test cases

0 0
Add a comment Improve this question Transcribed image text
Answer #1

class StringFirstLetterCheck {

String wordOne, wordTwo;

public StringFirstLetterCheck() {

}

public StringFirstLetterCheck(String one, String two) {

wordOne = one;

wordTwo = two;

}

public void setWords(String one, String two) {

wordOne = one;

wordTwo = two;

}

public boolean checkFirstLetter() {

return wordOne.charAt(0) == wordTwo.charAt(0);

}

public String toString() {

if (checkFirstLetter()) {

return wordOne + " does not have the same first letter as " + wordTwo;

} else {

return wordOne + " have the same first letter as " + wordTwo;

}

}

}

public class StringFirstLetterRunner {

public static void main(String[] args) {

StringFirstLetterCheck sfc = new StringFirstLetterCheck("Hello", "Good");

System.out.println(sfc);

sfc = new StringFirstLetterCheck("Hello", "Hi");

System.out.println(sfc);

}

}

Console X terminated> StringFirstLetterRunner [Java Application] CA Soft PegaEclipse-win64-4.5. Hello have the same first letter as Good Hello does not have the same first letter as Hi

Add a comment
Know the answer?
Add Answer to:
Lab Description: Compare two Strings to see if each of the two Strings has the same...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Lab Description Sort all words by comparing the length of each word. The word with the...

    Lab Description Sort all words by comparing the length of each word. The word with the smallest length would come first. If you have more than one word with the same length, that group would be sorted alphabetically Input: The data file contains a list of words. The first line in the data file is an integer that represents the number of data sets to follow Output: Output the complete list of words in order by length. Sample Data 10...

  • Lab Description: Sample Data Read in one word at a time from the file and output...

    Lab Description: Sample Data Read in one word at a time from the file and output the word as a square. # of data sets in the file . 6 HELLO CAT DOGHOUSE ONE IT Files Needed:: FancyHordrwo.java FancywordiwoRunner.java fancyword2. dat Sample Output: HELLO E L algorithm help OLLER CAT A. TAC 3 more statements //like the one I gave you DOGHOUSE ESUOHGOD ENO import java.util.Scanner; import static java.lang.System.* public class FancyWordTwo private String[1 mat; public FancyWordTwo (String s) //size...

  • Lab Description : Write a program that will sum all of a numbers digits. You must...

    Lab Description : Write a program that will sum all of a numbers digits. You must use % for this lab to access the right most digit of the number. You will use /to chop off the right most digit. Sample Data 234 10000 Files Needed: DigitAdder.java JavaLoopLabRunner.java 9005 84645 8547 123456789 55556468 8525455 8514548 1212121212 Sample Output 14 27 24 45 34 35 15 12 import static java.lang.System.* public class DigitAdder public static int go( int num ) return...

  • Consider the two strings "doggie dish" and "Drip coffee". What letters do they have in common?...

    Consider the two strings "doggie dish" and "Drip coffee". What letters do they have in common? That is, what is the letter intersection count for the pair of strings? Let's look at 'd' first. The first string has 2 d's (d's occurrence count is 2), while the second has just 1 d (capitalization doesn't count) - so the intersection for the strings for d is 1. What about g? There the occurrence counts are 2 and 0, so the intersection...

  • Hi I really need help with the methods for this lab for a computer science class....

    Hi I really need help with the methods for this lab for a computer science class. Thanks Main (WordTester - the application) is complete and only requires uncommenting to test the Word and Words classes as they are completed. The needed imports, class headings, method headings, and block comments are provided for the remaining classes. Javadocs are also provided for the Word and Words classes. Word The Word class represents a single word. It is immutable. You have been provided...

  • What is wrong with this Code? Fix the code errors to run correctly without error. There...

    What is wrong with this Code? Fix the code errors to run correctly without error. There are seven parts for one code, all are small code segments for one question. All the 'pets' need to 'speak', every sheet of code is connected. Four do need need any Debugging, three do have problems that need to be fixed. Does not need Debugging: public class Bird extends Pet { public Bird(String name) { super(name); } public void saySomething(){} } public class Cat...

  • Lab Description: Given a provided array, determine how many groups of a specified size exist. For...

    Lab Description: Given a provided array, determine how many groups of a specified size exist. For the array [i,1,1,2,2,2,3,3,3,4,5, 6, 7], there are 7 groups with at least one, 3 groups with at least 2, and 3 groups with at least 3. A group is a series of same values. 1 1 1 is a group of 3, but it also is a group of 1 and 2. To count as a group, all values must be the same. 1...

  • Need help coding this List. Lists are a lot like arrays, but you’ll be using get,...

    Need help coding this List. Lists are a lot like arrays, but you’ll be using get, set, add, size and the like instead of the array index operators [].​ package list.exercises; import java.util.List; public class ListExercises {    /**    * Counts the number of characters in total across all strings in the supplied list;    * in other words, the sum of the lengths of the all the strings.    * @param l a non-null list of strings   ...

  • DESCRIPTION: The purpose of this question is offload processing from the main method to a static...

    DESCRIPTION: The purpose of this question is offload processing from the main method to a static helper method. You will be given the main method. Do not alter this code. Your goal is to write a new method called oddOneOut, which will accept a String, and print it in out every other letter. For example, if the String was "abcdefghijk", the oddOneOut method will return "acegik" . METHOD INPUT: A string METHOD PROCESSING: Do not alter the  main method. Complete the...

  • Java, please. Work based on the code above. DESCRIPTION: The purpose of this question is offload...

    Java, please. Work based on the code above. DESCRIPTION: The purpose of this question is offload processing from the main method to a static helper method. You will be given the main method. Do not alter this code. Your goal is to write a new method called oddOneOut, which will accept a String, and print it in out every other letter. For example, if the String was "abcdefghijk", the oddOneOut method will return "acegik" METHOD INPUT: • A string METHOD...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT