Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Assignment 15.1: Comparing Characters (10 pts) (this is intro to java so please use the very basic method and concept to write it. Don't use

Assignment 15.1: Comparing Characters (10 pts) (this is intro to java so please use the very basic method and concept to write it. Don't use advanced methods and concepts. Heres the class material. http://deanzacollegecis.jenniferparrish.net/home/cis36a/cis-36a-schedule/lesson15
  • 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:

and are identical!

  • Note that 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:

and are unique characters.

  • Name your program CharComp.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.hasNextInt() to check for input mismatch exception.
    • See Lesson 15 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 15 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!

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

Students also viewed these Databases questions

Question

When is it appropriate to use a root cause analysis

Answered: 1 week ago