Hi, can someone please help me with this? I've been having a lot of trouble with it.

The assignment

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
Milestones
As you work on this assignment, you can use the milestones below to inform your development process:

Milestone 1: Set up a program that takes a string input and converts all the letters to lowercase. Start implementing algorithm 1: create a counter variable and iterate through the characters of the String, incrementing this each time a vowel is encountered which is not preceded by a space or is at the start of the String. So at the end of the loop this counts the number of vowels that are not at the start of a word.

Milestone 2: Add further conditions (using else if) in your loop to count any non-vowel characters which appear immediately after the same character. Make a new empty String to hold the shortened message at the start of the code, then add a final else condition in the loop to add all characters which were not vowels or repeated letters to this String. Then print the statements for algorithm 1 using your counts and shortened message.

Milestone 3: Start implementing algorithm 2 by writing code that iterates through the String and checks that each character is not a space and has not already appeared in the word before that point. You will need to use nested loops - an outer loop to iterate through the String characters and an inner loop that looks through the previous characters up to that point - and a flag variable to record if a letter was found in the inner loop. Use a counter variable to count all such "unique" characters in the String.

Milestone 4: Add a second inner loop inside the outer loop from the previous which counts all appearances of a character that passes the tests from milestone 3. Add the character and the number of times it appears to another shortened message String (which should start as blank String). Finally, print the statements for algorithm 2 using your unique character count and shortened message.

Answers

Answer 1

Answer:

Scanner scan = new Scanner(System.in);

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

String msg = scan.nextLine();

System.out.println();

msg = msg.toLowerCase();

String newStr = "";

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

int vowels = 0;

int repeats = 0;

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

{

if((msg.substring(i, i +1).equals("a") || msg.substring(i, i+1).equals("e") || msg.substring(i, i +1).equals("i") || msg.substring(i, i+1).equals("o") || msg.substring(i, i +1).equals("u")))

{

if(i != 0 && !msg.substring(i -1, i).equals(" "))

{

vowels++;

}

else

newStr += msg.substring(i, i +1);

}

else if(i != 0 && msg.substring(i, i +1).equals(msg.substring(i -1, i)))

{

repeats++;

}

else

{

newStr += msg.substring(i, i +1);

}

}

System.out.println("\nAlgorithm 1");

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

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

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

System.out.println("Algorithm 1 characters saved: " + (vowels + repeats));

algorithm2(msg);

}

public static void algorithm2(String msg)

{

String alg2Msg = "";

int uniqueLetters = 0;

// Iterate through each letter in msg

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

{

String ltr = msg.substring(i,i+1);

// Only process if this character is not a space

if(!ltr.equals(" "))

{

/* Check whether this character has already appeared by

* iterating through characters from start up to the current

* letter and using a boolean flag variable.

*/

boolean alreadyUsed = false;

for(int j=0; j<i; j++)

{

if(msg.substring(j,j+1).equals(ltr))

{

alreadyUsed = true;

}

}

/* If this character hasn't already appeared,

* iterate through the rest of the characters

* and count how many times it appears.

*/

if(!alreadyUsed)

{

uniqueLetters++;

int count = 0;

for(int j=i; j<msg.length(); j++)

{

if(msg.substring(j,j+1).equals(ltr))

{

count++;

}

}

alg2Msg += count + ltr;

}

}

} //end for loop

System.out.println("\nAlgorithm 2");

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

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

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

} //end algorithm2

}

Explanation:

Here you go!


Related Questions

Why did England establish the Sugar Act?

Answers

Answer:

The Revenue Act of 1764, also known as the Sugar Act, was the first tax on the American colonies imposed by the British Parliament. Its purpose was to raise revenue through the colonial customs service and to give customs agents more power and latitude with respect to executing seizures and enforcing customs law.

Explanation:

Hope this helps- Good luck ^w

NEED HELP ASAP JAVA
multiple choice
How many times will the following loop repeat?
int num = 49;
while (num > 0)
{
if (num % 2 == 0)
{
num++;
}
else
{
num--
}
}
A. 21
B. 22
C. 20
D. Infinite Loop
E. 23

Answers

I think is C tbh sorry if that’s wrong my fault

Pls Help need it before 1pm PLS.
Before taking a photograph, which of the following should you check?

The time of day
The weather report
That the colors in the photograph do not clash
That the lines in the photograph are straight

Answers

Answer:

Explanation:t

the weather

The weather report should you check. Therefore option B is correct.

Before taking a photograph, checking the weather report is important to ensure favorable conditions for capturing the desired shot. Weather can significantly impact the outcome of a photograph.

For instance, bright sunlight might cause harsh shadows or overexposure, while a cloudy day may provide softer, more diffused lighting.

Additionally, weather conditions like rain or strong winds can affect the feasibility and safety of the photo shoot.

By checking the weather report beforehand, photographers can plan accordingly, choose suitable equipment, and make adjustments to achieve the best possible results.

Considering the weather helps to avoid potential issues and enhances the overall quality and success of the photography session.

Therefore option B The weather report is correct.

Know more about The weather report:

https://brainly.com/question/18196253

#SPJ6

Worms and Trojans are typically harmless because the originator of such attacks are usually known to the recipient, and as such, are not intended to cause much harm.
(A) True
(B) False

Answers

Answer:

False

Explanation:

Viruses, worms and trojans are all malicious programs that can damage your computer. Also i got an A soo...

Which statements describe an If statement? Check all that apply.
A conditional If statement is used when the programmer wants decision-making included in the
code.
A conditional If statement executes code when the condition returns a value of false.
A conditional If statement executes a piece of code when one statement is false and the following
statement is true.
A conditional If statement tests whether the condition following it is true or false before executing a
specified part of the code.

Answers

Answer:

A and D

Explanation:

The that describe an If statement are;

A conditional If statement is used when the programmer wants decision-making included in the code.A conditional If statement executes code when the condition returns a value of false.A conditional If statement tests whether the condition following it is true or false before executing a specified part of the code.

According to this question, we are to discuss about If statement .

As a result of this we can see that conditional If statement is used when the programmer wants decision-making included in the cod.

Therefore, If statement executes code when the condition returns a value of false

Learn more about If statement at;

https://brainly.com/question/18736215

Why does it not let me see my messages? In brainy?

Answers

Answer:

Was removed you can only message the brain

Explanation:

give some examples of technologies that have improved human living conditions

Answers

Answer:

Apps. Apps are a very well-known example of eHealth; most people have tried out an app to improve their mental or physical health at least once. ...

Wearables. Maybe you possess or have seen people wearing devices like the Apple watch, Fitbit, or Pebble. ...

Websites. ...

Virtual Reality. ...

Videoconferencing.

Explanation:

PLEASE HURRY!!
Look at the image below

Answers

Answer:

The function usernameMaker.

Explanation:

strFirst is a local variable in the function usernameMaker since it is an argument that is passed into that function. This means that the scope of strFirst is the function usernameMaker, since it cannot be accessed anywhere else in the code.

Hope this helps :)

help please!! worth 10 pts! answer quick please!

Answers

Answer:

it has helped the people of today by

1.helped the young generation with there homework

2.you can book an hotel through the internet

3.you can also book a plane ticket via the internet

4.it is easier to look to ur email message via the internet

Why is it important to perform routine computer maintenance? It can make more room for junk files and downloadable programs. It can help prevent hardware, software, and Internet access problems. It can stop computer problems from occurring more than once. It can help you remember how to perform steps to solve computer problems.

Answers

b :D

hope this helps

plz give me brainliest

only typed tht so i can have enough words lol

Answer:

B. It can help prevent hardware, software, and Internet access problems.

Explanation: trust dawg

PLS HURRY!!
Look at the image below

Answers

Answer: 1. for

2. while

Explanation:

Hey i have a question i have Iphone and there’s no feature for the tutor? But on my dad”s samsung there is?

Answers

I do not know, I’m on iPhone and it allows me to ask a tutor.

A _______ web page's content can change based on how the user interacts with it.

Answers

Answer:

Dynamic web page shows different information at different point of time.

Write a java program with the following instruction:- class name: prime, instance variable: int n. Member methods:-
prime(): default constructor to initialize n
void input(int x): to assign n with x,
void display(): to check whether the number is prime or not

Answers

class Prime {

int num = 1;

boolean flag = false;

public void input(int x) {

this.num = x;

}

public void display() {

for (int i = 2; i <= num / 2; ++i) {

// condition for nonprime number

if (num % i == 0) {

flag = true;

break;

}

}

if (!flag)

System.out.println(num + " is a prime number.");

else

System.out.println(num + " is not a prime number.");

}

}

May be some bugs as it is an untested code written using a mobile phone

PLEASE HURRY!!
Look at the image below

Answers

Answer is power and base

Explanation: both power and base are number variables

When writing research questions, use action words, such as

Answers

Answer: Effect

Explanation:

Research questions are demonstrated as the questions that directs or specifies the dimension of the research for a particular work and helps to determine the objectives of the paper or essay.

As per the question, while writing or farming research questions, action verb like 'effect' must be used as it would help determine the impact of a particular research question on the content and efficacy of the research and thus, frame questions that propose a clear, concise, intricate, and debatable thesis statement and offer an effective dimension to the essay that creates a valid impact on the audience.

Answer:

yes

Explanation:

because that helps to understand the text or article more

Which type of worker tends to earn the highest pay in comparison to the others? Science, Technology, Engineering, and Math Workplaces and Tasks

Answers

Answer:

All those options, just described computer science so be specific.

8. A sprite is a simple spider shaped thing with n legs coming out from a center point. The angle
between each leg is 360 / n degrees.
Write a program to draw a sprite where the number of legs is provided by the user.
For example, when the user enters 6, they should get the following output

Answers

import turtle

s = turtle.Screen()

t = turtle.Turtle()

t.penup()

t.goto(0,-10)

t.pendown()

t.fillcolor("black")

t.begin_fill()

t.circle(10)

t.end_fill()

legs = int(input("How many legs do you want your sprite to have? "))

i = 0

angle = 360 / legs

while i < legs:

   t.penup()

   t.goto(0,0)

   t.pendown()

   t.forward(30)

   t.back(30)

   t.right(angle)

   i += 1

s.mainloop()

You might need to adjust this to your liking. I was able to do everything but draw the triangles at the end of each leg. I hope this helps though.

Suppose that you use a 220 Ohm resistor as the fixed resistor in your Arduino burglar alarm.

Suppose that the photoresistor is the same one we used in our last homework assignment, where the resistance is 500 Ohms when it is fully illuminated by light, and 180 kiloOhms when it is in darkness.

What would the input voltage be to the Arduino when it is fully illuminated if we connect the Arduino so that its analog input pin "sees" the same voltage difference that the photoresistor has across it.

In the previous problem, what would the input voltage be to the Arduino when it is darkness if we connect the Arduino so that its analog input pin "sees" the same voltage difference that the photoresistor has across it.

Answers

Different types of light detectors are LDRs or Light Dependent Resistors Photo . First you need to connect the LDR to the analog input pin 0 on the Arduino. If intensity of light falling on LDR is high LDR will have low resistance

Select the correct answer.
Manuel is writing a sales proposal using a word processor. He wants his company's logo to appear at the top of each page of the proposal
document. Which tool of the word processor should he use?

A)Footer
B)Orientation
C)Header
D)Margins

Answers

The answer is C) Header. If you go in Word and use the header feature, and put a logo there, it appears on all pages.

Answer: it is c

Explanation: that is the only thing that would be at the top

2. Which of the following statements describes a need or problem that can be solved using the technology design process.
O A family needs a garage door that will automatically open when their car approaches.
A family needs to determine how to assign chores in the most fair manner
O A baseball player needs to improve his batting skills
A community needs to decide to install a new swimming pool or update the park

Answers

Answer:

The Family with the garage door

Explanation:

I could swear that that's the same question on my quiz. :o

Answer:

A family needs a garage door that will automatically open when there car approaches.

Explanation:

I did my test and knew it was this but i searched this up to see if i could get points and help LOL so this is 100% correct!

Which of these appliances can be classified as a robot? You can choose 2.

washing machine
sliding window
humidifier
a table lamp
ice cream vending machine

Answers

Answer:

ummmm i think b

Explanation:

the first two are washing machine and humidifier

You defined a book data type.

class book:
title = ''
author = ''
pages = 0

Then, you created an instance of your book.

myBook = book()

Which statement assigns a value to the title?

title = 'To Kill a Mockingbird'
myBook.title('To Kill a Mockingbird')
myBook.title = 'To Kill a Mockingbird'
myBook.book.title = myBook.title = 'To Kill a Mockingbird'

Answers

Answer:

myBook.title = 'To Kill a Mockingbird'

Explanation:

Correct answer edge 2020

What function text would you use to put today's date and time in a cell? =TODAY()
=NOW()
NOW()
TODAY()

Answers

Answer:

The answer to this question is given below in the explanation section.

Explanation:

The correct answer to this question is:

=NOW()

Now() is a function that you can use to put today's date and the current time in a cell. While Today() function is a function that can only be used to put today's date.

Other options are not correct because:

If you write NOW() and TODAY() as it is in a cell, then Excel will not consider them as a function. To write a function in a cell, you have to write the "=" symbol before the function name. If you will emit the "=" symbol before the function, then the function name will be consider as text in a cell.

Answer:

B.  =NOW()

Explanation:

edg 2020

Need help fast this is do a 4

Answers

Answer:

I believe the answer is B.

What can happen if you do not follow the directions when cooking or baking? (Give 4 examples in a sentence each)

Answers

Answer: 1: You will make it incorrectaly 2: It will taste terrible 3: You may break appliences 4: you may burn down your house.

Explanation:

A hash function is taking an input string of arbitrary length and produces a fixed-sized, short output called a digest.

A. True
B. False

Answers

Answer:

A. True

Explanation:

Digest is actually: a message digest algorithm, or put simply: a hash value, even simpler: the output.

Sophie used the software development life cycle to write a new program. Sophie planned her program using pseudocode and then wrote her actual code. Which stage of the software development life cycle is Sophie ready for next?

Answers

The stage of the software development life cycle that Sophie is ready for next is Building (software development)

What Is the Software Development Life Cycle?

Software Development Life Cycle is known to be a kind of application of laid down business practices to create software applications.

It is said to be divided into;

Planning RequirementsDesign BuildDocument Test DeployMaintain.

Learn more about software development  from

https://brainly.com/question/25310031

Answer:

Testing

Explanation:

I did it on my test!

which is the following should be selected in the paragraph dialogue box to prevent page break from occurring within a paragraph

a) Section break before
b) Do not hyphenate
c) Keep the next
d) Keep lines together

Answers

Answer:

Explanation: keep lines together

what is the purpose for using proper markup language

Answers

Answer:

n computer text processing, a markup language is a system for annotating a document in a way that is syntactically distinguishable from the text, meaning when the document is processed for display, the markup language is not shown, and is only used to format the text.

Explanation:

hold up reen deen ding ding ding ding

Answer:

Without the right tags the content wont be accurately indexed

Explanation:

ap3x approved

hope it helps

Other Questions
Which substance is the stronger base?Milk of MagnesiaSodium BicarbonateFerrous HydroxideDistilled Water How did settlers travel the correct route to the Pacific Northwest?A. They used the best guess they could make.B. They followed the signs along the trail.C. They watched for landmarks along the way.D. they followed the Columbia River. Which authors were known for their critical writing about the excesses and problems resulting from industrialization?Blake and PoeBlake and TwainDickens and TwainPoe and Dickens Its sometimes Change is a good man into a bad one, said the tall man. youve been under arrest for 10 minutes, Suki Bob. Chicago think she may have dropped over our way in wires she wants to have a chat with you. Going quietly, are you? Thats sensible. Now, before we go on to the station heres a note I was asked to hand to you. You may read it at the window. Its from patrolman wellsWhich sentence best state a theme being based on paragraph 30?Friend should remain loyal to each otherTime can change peopleStanding up for yourself can be hardIn difficult times friend support each other Food-Safe Schools (a program to work within school health programs to prevent food-borne illness) is managed by the-National Pest Management Association (NPMA)-National Restaurant Association-National Environment Health Association (NEHA)-American Academy of Sanitarians (AAS) please help me with this question Please help and answer A map has a scale of 1 cm: 5 km. Determine how far apart two cities are if they are 8 cm apart on the map. pls help fast Which lines from Abraham Lincolns Gettysburg Address support the claim that the presidents speech helped clarify the purpose of the war?Four score and seven years ago our fathers brought forth, upon this continent, a new nation, conceived in liberty, and dedicated to the proposition that "all men are created equal."Now we are engaged in a great civil war, testing whether that nation, or any nation so conceived, and so dedicated, can long endure. We are met on a great battle field of that war. We have come to dedicate a portion of it, as a final resting place for those who died here, that the nation might live. This we may, in all propriety do.But, in a larger sense, we can not dedicatewe can not consecratewe can not hallow, this groundThe brave men, living and dead, who struggled here, have hallowed it, far above our poor power to add or detract. The world will little note, nor long remember what we say here; while it can never forget what they did here. It is rather for us, the living, we here be dedicated to the great task remaining before us that, from these honored dead we take increased devotion to that cause for which they here, gave the last full measure of devotionthat we here highly resolve these dead shall not have died in vain; that the nation, shall have a new birth of freedom, and that government of the people by the people for the people, shall not perish from the earth. the difference between half a number and 19 number of titles need to cover a floor of a room 300cm by 200cm if the area of one of the title 2000sq.cm is _____please show working clearly. Which explanations explain why life on earth can exist 2. Which of the following statements describes a need or problem that can be solved using the technology design process.O A family needs a garage door that will automatically open when their car approaches.A family needs to determine how to assign chores in the most fair mannerO A baseball player needs to improve his batting skillsA community needs to decide to install a new swimming pool or update the park Brian earns $28.50 tutoring for 3 hours. Assuming he is paid at constant rate, how much would Brian earn tutoring for 18 hours? 12. Which of the following could be considered a cause of the American Revolution?The French alliance with the thirteen colonies angered England causing the warThe British imposed taxes that the colonists viewed as infringing on their rightsThe French Revolution inspired the thirteen colonies to rebel against EnglandThe British desire to end slavery moved the thirteen to rebel against England Which best explains how nutrients, salt, sediment and pollutants get into estuaries and oceans?A. from rivers and streams flowing into estuaries and oceansB. from organisms living and dying in estuaries and oceansC. from asteroids and comets impacting Earth at estuaries and oceansD. from precipitation falling over the estuaries and oceans En este tipo de enfoque para el desarrollo de nuevos productos, todos los departamentos implicados en el desarrollo de nuevos productos siguen un proceso secuencial literally plz someone do it What is the total cost of a cell phone that costs $97.03 if there is an eight percent sales tax? By the stipulations of this instrument, we are despoiled of our private possessions, the indefeasible property of individuals. We are stripped of every attribute of freedom and eligibility for legal self-defence. Our property may be plundered before our eyes; violence may be committed on our persons; even our lives may be taken away, and there is none to regard our complaints. We are denationalized; we are disfranchised. We are deprived of membership in the human family! We have neither land nor home, nor resting place that can be called our own. And this is affected by the provisions of a compact which assumes the venerated, the sacred appellation of treaty. Chief John Ross, 1836 Which statement best summarizes John Rosss response to the Treaty of New Echota and American Indian removal? He believes that the Cherokee should be able to defend themselves against white people. He feels the Cherokee are being treated as less than human, with no regard for their human or legal rights. He considers the treaty to be sacred, but is saddened by the loss of land.