Question

14.3: More Sentences Write a program that allows a user to enter a sentence and then...

14.3: More Sentences

  • Write a program that allows a user to enter a sentence and then the position of two characters in the sentence.
  • The program should then report whether the two characters are identical or different.
  • When the two characters are identical, the program should display the message:

<char> and <char> are identical!

  • Note that <char> should be replaced with the characters from the String. See example output below for more information.
  • When the two characters are different, the program should display the message:

<char> and <char> are unique characters.

  • Note that <char> should be replaced with the characters from the String. See example output below for more information.
  • Name your program Sentences.java
  • Your program must use a do-while loop to allow the user to enter a series of sentences, or "X" to exit.
    • The program should accept both lower and upper case "X" as an indication the user wishes to exit the program.
    • Please see example output below
  • It should also verify that the user provides numerical input for the positions of the characters in the String.
    • Hint: Use a while loop and !input.nextInt() to check for input mismatch exception.
    • See Lesson 14 notes for a discussion on input mismatch exception
    • You will need two while loops, one for each input.nextInt() statement for the numeric location of each character in the String
  • Important: Note that you will need to use input.nextLine() to account for the fact that the loop causes an input.nextInt() to come before an input.nextLine().
    • See lesson 14 notes regarding the problem that can occur when you use input.nextInt() before an input.nextLine()
  • When your program runs identically to the example output below, submit it to Canvas.

Your output should look identical to the following, except user input will vary:

Welcome!

This program compares two letters in a sentence.

Enter a sentence or X to exit: Let's have cake and ice cream for dinner!
Enter the numeric location of the first letter: 1
Enter the numeric location of the second letter: 9

e and e are identical.

Enter a sentence or X to exit: "Flight Behavior" is a good book.
Enter the numeric location of the first letter: six

Error! Enter a number, not text!
Enter the numeric location of the first character: six

Error! Enter a number, not text!
Enter the numeric location of the first character: six

Error! Enter a number, not text!
Enter the numeric location of the first character: 6
Enter the numeric location of the second letter: 10

t and h are unique characters.

Enter a sentence or X to exit: Summer vacation is almost here!
Enter the numeric location of the first letter: 2
Enter the numeric location of the second letter: three

Error! Enter a number, not text!
Enter the numeric location of the second character: three

Error! Enter a number, not text!
Enter the numeric location of the second character: three

Error! Enter a number, not text!
Enter the numeric location of the second character: 3

m and m are identical.

Enter a sentence or X to exit: x
Goodbye!

0 0
Add a comment Improve this question Transcribed image text
Know the answer?
Add Answer to:
14.3: More Sentences Write a program that allows a user to enter a sentence and then...
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
  • Write a C program that takes two sets of characters entered by the user and merge...

    Write a C program that takes two sets of characters entered by the user and merge them character by character. Enter the first set of characters: dfn h ate Enter the second set of characters: eedtecsl Output: defend the castle Your program should include the following function: void merge(char *s3, char *s1, char *s2); The function expects s3 to point to a string containing a string that combines s1 and s2 letter by letter. The first set might be longer...

  • IN C language Write a C program that prompts the user to enter a line of...

    IN C language Write a C program that prompts the user to enter a line of text on the keyboard then echoes the entire line. The program should continue echoing each line until the user responds to the prompt by not entering any text and hitting the return key. Your program should have two functions, writeStr andcreadLn, in addition to the main function. The text string itself should be stored in a char array in main. Both functions should operate...

  • ****C PROGRAMMING**** (100 points) Write a program that prompts the user to enter the name of...

    ****C PROGRAMMING**** (100 points) Write a program that prompts the user to enter the name of a file. The program encoded sentences in the file and writes the encoded sentences to the output file. Enter the file name: messages.txt Output: encoded words are written to file: messages.txt.swt The program reads the content of the file and encodes a sentence by switching every alphabetical letter (lower case or upper case) with alphabetical position i, with the letter with alphabetical position 25...

  • Exercise #3: write a Java program that prompts the user to enter a sentence. The program...

    Exercise #3: write a Java program that prompts the user to enter a sentence. The program has to find the print: a. the position of vowels in the sentence. b. the number of vowels in the sentence (A, a, U, u, E, e, O, o, I, i) c. the number of characters as numbers or special characters (other than English letters a.z, A..Z). Hint: remember to ignore the spaces. Sample input-output: Enter the sentnse: UAEU is the university of the...

  • Objectives: Use strings and string library functions. Write a program that asks the user to enter...

    Objectives: Use strings and string library functions. Write a program that asks the user to enter a string and output the string in all uppercase letters. The program should then display the number of white space characters in the string. You program should run continuously until the user enters an empty string. The program must use the following two functions: A function called count_spaces that counts the number of white spaces inside a string. int count_space(char str[]); which tell you...

  • 1. Write a program that prompts the user to enter three integers and display the integers...

    1. Write a program that prompts the user to enter three integers and display the integers in non-decreasing order. You can assume that all numbers are valid. For example: Input Result 140 -5 10 Enter a number: Enter a number: Enter a number: -5, 10, 140 import java.util.Scanner; public class Lab01 { public static void main(String[] args) { Scanner input = new Scanner(System.in);    } } ---------------------------------------------------------------------------------------------------------------------------- 2. Write a program that repeatedly prompts the user for integer values from...

  • Write a program in python that asks the user to input a sentence. The program will...

    Write a program in python that asks the user to input a sentence. The program will ask the user what two letters are to be counted. You must use a “for” loop to go through the sentence & count how many times the chosen letter appears in the sentence. You are not allowed to use python built-in function "count()" or you'll get a Zero! Output will show the sentence, the letter, and the number of times the letter appears in...

  • Python program. Character-Analysis Program Problem Statement: Design a program - IN PYTHON - that asks the...

    Python program. Character-Analysis Program Problem Statement: Design a program - IN PYTHON - that asks the user to enter a string. The string will then be displayed back to the user. This is followed by determining the number of alphabetic characters, numeric characters, lower_case letters, upper_case letters, whitespace characters, and then displaying them. The user should be given additional chances to enter additional strings, and each time a string is entered, the above process is to be performed. The inputting...

  • USING PYTHON PROGRAMING LANGUAGE Write a program that first asks the user to enter a “special”...

    USING PYTHON PROGRAMING LANGUAGE Write a program that first asks the user to enter a “special” letter. The program should then ask the user to enter a single line sentence containing all lowercase letters and no punctuation, except for a period at the end. The program will then output the number of times that this letter appears in the sentence. Example: Enter a special letter: t Enter a sentence: here is my little sentence. Your letter appears 3 times. (t...

  • (Process a string) Write a program that prompts the user to enter a string and displays...

    (Process a string) Write a program that prompts the user to enter a string and displays its length and its first character. java StringLength Enter a string:Does quantum determinacy have anything to with whether human cognition is deterministic? The string is of length 88 and the first character is D import java.util.Scanner; class StringLength{    public static void main (String args[]){        Scanner input = new Scanner(System.in);        System.out.println("Enter a string:");        String ans = input.nextLine();        System.out.println("The string...

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