(JAVA PLS)Your job in this assignment is to write a program that takes a message as a string and reduces the number of characters it uses in two different set ways. The first thing your program will do is ask the user to type a message which will be stored as a String. The String entered should be immediately converted to lowercase as this will make processing much easier. You will then apply two different algorithms to shorten the data contained within the String.

Algorithm 1

This algorithm creates a string from the message in which every vowel (a, e, i, o, and u) is removed unless the vowel is at the very start of a word (i.e., it is preceded by a space or is the first letter of the message). Every repeated non-vowel character is also removed from the new string (i.e., if a character appears several times in a row it should only appear once at that location). So for example the string "I will arrive in Mississippi really soon" becomes "i wl arv in mssp rly sn".

After applying this algorithm, your program should output the shortened message, the number of vowels removed, the number of repeated non-vowel characters removed, and how much shorter the shortened message is than the original message. The exact format in which the program should print this information is shown in the sample runs.

Algorithm 2

This algorithm creates a string by taking each unique character in the message in the order they first appear and putting that letter and the number of times it appears in the original message into the shortened string. Your algorithm should ignore any spaces in the message, and any characters which it has already put into the shortened string. For example, the string "I will arrive in Mississippi really soon" becomes "8i1w4l2a3r1v2e2n1m5s2p1y2o".

After applying this algorithm, your program should output the shortened message, the number of different characters appearing, and how much shorter the shortened message is than the original message. The exact format in which the program should print this information is shown in the sample runs.

Sample Run 1
Type the message to be shortened
This message could be a little shorter

Algorithm 1
Vowels removed: 11
Repeats removed: 2
Algorithm 1 message: ths msg cld b a ltl shrtr
Algorithm 1 characters saved: 13

Algorithm 2
Unique characters found: 15
Algorithm 2 message: 4t2h2i4s1m5e2a1g1c2o1u3l1d1b2r
Algorithm 2 characters saved: 8
Sample Run 2
Type the message to be shortened
I will arrive in Mississippi really soon

Algorithm 1
Vowels removed: 11
Repeats removed: 6
Algorithm 1 message: i wl arv in mssp rly sn
Algorithm 1 characters saved: 17

Algorithm 2
Unique characters found: 13
Algorithm 2 message: 8i1w4l2a3r1v2e2n1m5s2p1y2o
Algorithm 2 characters saved: 14

Answers

Answer 1
Answer:

import java.util.Scanner;

public class JavaApplication54 {

   public static int appearance(String word, char letter){

       int count = 0;

       for (int i = 0; i < word.length(); i++){

           if (word.charAt(i) == letter){

               count++;

           }

       }

       return count;

   }

   public static void main(String[] args) {

       Scanner scan = new Scanner(System.in);

       System.out.println("Type the message to be shortened");

       String message = scan.nextLine();

       message = message.toLowerCase();

       int volCount = 0, repCount = 0, num = 0;

       char prevC = ' ';

       String vowels = "aeiou";

       String newMessage = "";

       for (int i = 0; i < message.length(); i++){

           char c = message.charAt(i);

           

           if (vowels.indexOf(c) != -1 && prevC == ' '){

               newMessage += c;

           }

           else if (vowels.indexOf(c) == -1 && prevC != c){

               newMessage += c;

           }

           else if (vowels.indexOf(c) != -1){

               volCount ++;

           }

           else{

               repCount++;

           }

            prevC = c;

       }

       System.out.println("Algorithm 1");

       System.out.println("Vowels removed: "+volCount);

       System.out.println("Repeats removed: "+repCount);

       System.out.println("Algorithm 1 message: "+newMessage);

       System.out.println("Algorithm 1 characters saved: "+(message.length() - newMessage.length()));

       

       String uniqueMessage = "";

       

       for (int i = 0; i<message.length(); i++){

           char w = message.charAt(i);

           if (uniqueMessage.indexOf(w)== -1 && w!=' '){

               uniqueMessage += appearance(message,w)+""+w;

               num++;

           }

       }

       System.out.println("Algorithm 2");

       System.out.println("Unique characters found: "+num);

       System.out.println("Algorithm 2 message: "+uniqueMessage);

       System.out.println("Algorithm 2 characters saved: "+(message.length() - uniqueMessage.length()));

   }

   

}

I hope this helps!


Related Questions

7. Write a program in C to display the string "ARRAY" in the following format : A AR ARR ARRA ARRAY
Google Maps is an online atlas.a. Trueb. False
The software program you need to have to read PDF file, such as the PDF files you download from your My Courses page, isa. Adobe Reader. b. Shock Wave. c. Flash. d. Applet.
Which concept often comes in conflict with privacy rights?A.right to be left aloneB.right to encroachmentC.right to knowD.right to publicity
Dynamic alliance networks work best in industries: a. that are mature and stable in nature. b. where the coordination of product and global diversity is critical. c. that are characterized by predictable market cycles and demand. d. characterized by frequent product innovations and short product life cycles

It is most important to ask questions when looking at media messages because doing soa. provides a higher level of entertainment value.
b. helps you to prepare for a career in media.
c. enables you to be an intelligent consumer.
d. allows you to determine a product's quality.

Answers

The correct answer is letter d. allows you to determine a product's quality. It is most important to ask questions when looking at media messages because doing so it allows you to determine a product's quality. Knowing the quality of a product is nothing wrong to do because as consumers, we need to know what really the product that we are going to buy.

To sort records in a query, specify the sort order in the ____ row of the design grid below the field that is the sort key.

Answers

To sort records in a query, specify the sort order in the join row of the design grid below the field that is the sort key.

Give two examples of desktop publishing software

Answers

There are quite a lot of desktop publishing software as of today.
I'll give you the names of some of it.
- Adobe inDesign - one of the most popular
- Corel Draw
- Microsoft Publisher
- Serif
- Ultra Xml
And more.
There are actually a lot if you are just about to check in the internet.

When pointed over text within a paragraph, the cursor takes the shape of a/an

Answers

It takes the shape of an I beam.

The animation industry is solely reliant on 3-D modeling and 3-D virtualization to create the animated movies in the cinemas.True or false?

Answers

the answer is false       
false some people hand draw stuff as well

In a(n) ________ either one condition or some other condition must be met in order for an event to take place.a. nested decision
b. AND decision
c. OR decision
d. logical decision

Answers

I think the answer is D

hopethishelpsyouout