Question: JAVA ONLY. Eye can do percentages Write a program that declares the following: A float variable named blue A float variable named green A float

JAVA ONLY.

  1. Eye can do percentages

Write a program that declares the following:

  • A float variable named blue

  • A float variable named green

  • A float variable named brown

  • A float variable named total

Have your program the following questions, then store the users response in the appropriate variable:

  • How many students have blue colored eyes?

  • How many students have green colored eyes?

  • How many students have brown colored eyes?

Firstly, compute the total number of students, and store the result inside of total. Next, divide color variable by the total number of students, then store that result inside of the same color variable. (Notice that this will replace whatever old data was inside of that variable.) Finally, multiply each color variable by 100 to convert it to a percent.

For example, lets say a class had 5 students with blue eyes, 5 students with green eyes, and 10 students with brown eyes. The total number of students would be 5+5+10=20. So dividing each by 20 gives the following values for each: Blue = 0.25 Green = 0.25 Brown = 0.5 Multiplying by 100 to convert from decimal values from 0 to 1 to percentage values from 0 to 100 means that at the end, the values of each should be: Blue = 25 Green = 25 Brown = 50

Next, display the following chart as output, noting that there is only a single space before and after the dash mark, and no space before the percentage sign.

Blue - <blue>%

Green - <green>%

Brown - <brown>%

Next, display the following chart as output, noting that there is only a single space before and after the dash mark, and no space before the percentage sign.

Lastly, use printf() to print your output with 1 decimal place. Notice that you may have to experiment with your different print statements (i.e. print, println, and printf) to get the output to look correct.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!