1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Alexxx [7]
4 years ago
10

Write a Java program that will 1. Ask the user to type in a sentence, using a JOptionPane.showInputDialog(). 2. The program will

examine each letter in the string and count how many time the upper-case letter 'E' appears, and how many times the lower-case letter 'e' appears. The key here is to use the charAt method in class String. 3. Using a JOptionPane.showMessageDialog(), tell the user how many upper and lower case e's were in the string. 4. Repeat this process until the user types the word "Stop". (Check out the method equalsIgnoreCase in class String to cover all upper/lower case possibilities of the word "STOP").
Please provide a code for this in JAVA.

Computers and Technology
1 answer:
Paraphin [41]4 years ago
6 0

Answer:

Here is the JAVA program :

import javax.swing.JOptionPane;   //to use JOptionPane  

public class Main {   //class name

public static void main(String[] args) { //start of main method

   int ECount= 0;   //counts number of upper case E

   int eCount= 0;  //counts number of lower case e

   String sentence;   //stores input sentence string

sentence = JOptionPane.showInputDialog(null, "Type a sentence (type stop to exit)");  //uses showInputDialog method to display a dialog box which prompts user to enter a sentence

 int length = sentence.length();  //stores the length of the sentence

 while (!sentence.equalsIgnoreCase("stop"))  //the loop continues to execute until the user types stop

{ for (int i = 0; i < length; i++) { //loops through the sentence

             if (sentence.charAt(i) == 'E')  //if the character is an uppercase E

                  ECount += 1;  //adds 1 to the count of Ecount

             if (sentence.charAt(i) == 'e')  //if the character in a sentence is lowercase e

                  eCount += 1;}  //adds 1 to the count of lower case e

JOptionPane.showMessageDialog(null, "There are " + ECount + " number of E's and " + eCount + "  number of e's in " +sentence);   //displays the number of times uppercase and lowercase (E and e) occur in sentence

sentence = JOptionPane.showInputDialog(null, "Type a sentence (type stop to exit");  //prompts user to enter the next sentence

length = sentence.length();  //stores the length of sentence at each iteration of while loop until user enters stop

eCount=0;  //resets the counter of lowercase e

ECount=0;  } } } //resets the counter of uppercase e

Explanation:

The program uses showInputDialog() method that displays a dialog box on output screen. This dialog box prompts the user to enter a string (sentence) Suppose user enters "Evergreen" as input sentence so

sentence = "Evergreen"

Next the length of this string is computed using length() method and stored in length variable. So

length = sentence.length();

length = 9

The for loop iterates through this input sentence until the variable i is less than length i.e. 9

At first iteration

if (sentence.charAt(i) == 'E') becomes

if (sentence.charAt(0) == 'E')

Here charAt() method is used which returns the character at the specified index i. This if condition is true because the character at 0-th index (first character) of the sentence Evergreen is E. So ECount += 1; statement adds 1 to the count of upper case E so

ECount = 1

At second iteration:

if (sentence.charAt(1) == 'E')

this condition is false because the character at 1st index of sentence is 'v' which not an upper case E so the program moves to next if condition if (sentence.charAt(i) == 'e') which is also false because the character is not a lower case e either.

At third iteration:

if (sentence.charAt(2) == 'E')

this condition is false because the character at 2nd index of sentence is 'e' which not an upper case E so the program moves to next if condition if (sentence.charAt(i) == 'e') which is true because the character is a lower case e. So the statement eCount += 1; executes which adds 1 to the count of e.

eCount = 1

So at each iteration the sentence is checked for an upper case E and lower case e. After the loop breaks, the program moves to the statement:

JOptionPane.showMessageDialog(null, "There are " + ECount + " number of E's and " + eCount + "  number of e's in " +sentence);

which displays the number of uppercase E and lower case e in a message dialog box. So the output is:

There are 1 number of E's and 3 number of e's in Evergreen.

Then because of while loop user is prompted again to enter a sentence until the user enters "stop". Now the user can enter Stop, StOp, STOp etc. So equalsIgnoreCase method is used to cover all upper/lower case possibilities of the word "stop".

The screenshot of the program and its output is attached.

You might be interested in
Leonardo is having difficulty accessing the course website. he should contact the for assistance. (points:1)
Alona [7]
He should contact the teacher for assistance
3 0
3 years ago
Insurance can help you:
Blababa [14]
No it can not .............
3 0
4 years ago
Consider the scenario below. Will the solution attempted by the technician fix the problem or make it worse? Defend your answer.
PSYCHO15rus [73]

Answer:

Answer is depend on situation.

Explanation: If data stored on individual computer not using server ,answer will be  To fix the problem, the technician installed new, larger hard drives on all the computers. But most the time if many computer in the network ,they have to share data and will need server to share data, Over 20 pc in the network can not use standard pc for share files need to have server so,need more info to provide proper answer

i hope i help you

4 0
3 years ago
Hashing algorithms are used on evidence files to uphold the chain of custody in an investigation. Which of the following is NOT
raketka [301]

Answer:

C. DAT-1

Explanation:

Chain of custody is applied when examining digital evidence and checking for proof that no alterations have been made to the document. It ensures that the original piece of digital evidence which could be in text, image, video, or other electronic formats, is preserved and protected from alterations. Hashing algorithms which are mathematical computations that help to condense files are applied during this procedure.

Common hashing algorithms applied, include;  the message digest 4, secure hashing algorithms 1, 2, 256, 224, 512, etc. The message digest 4 is used to evaluate why a particular piece of evidence was handled by an individual. This is further authenticated by examining the fingerprint.

4 0
3 years ago
Reggie has hired you to design a home network. The home network will share a printer but will mainly be used to stream movies to
SIZIF [17.4K]

Answer:

i think the answer is a

Explanation:

3 0
3 years ago
Other questions:
  • video-sharing sotes such as youtube and vimeo provide a place to post short videos called clips true or false?
    5·1 answer
  • ____ errors occur when a formula is written incorrectly, when a mistake is made with a decision condition, or when the wrong var
    11·1 answer
  • Rows within a spreadsheet are identified by:
    8·1 answer
  • Hackers often argue that hacking is for the good of all people because it points out flaws in computer systems. do you agree wit
    6·1 answer
  • Which of the following companies develop, own, and provide travel products for people?
    8·1 answer
  • When workers use techology to work from home or an office center, they are
    7·2 answers
  • QUESTION 56 Use the Windows ________ to check on a nonresponsive program. Backup utility Error-checking System Restore Task Mana
    6·1 answer
  • 1) APPLICATION BASED QUESTION:-
    5·1 answer
  • Computer operates nearly 100% accurately but why is the phrase'garbage in garbage out'(GIGO) associated with their use?Describe
    15·1 answer
  • Which of the following controls computer memory?
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!