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
tamaranim1 [39]
4 years ago
6

Write a program that asks the user for the number of males and the number of females registered in a class. The program should d

isplay the percentage of males and females in the class. Hint: Suppose there are 8 males and 12 females in a class. There are 20 students in the class. The percentage of males can be calculated as: (8/20) * 100, or 40%. The percentage of females can be calculated as: (12/20) * 100, or 60%.
Computers and Technology
1 answer:
Bond [772]4 years ago
4 0

Answer:

import java.util.Scanner;

public class PercentagePopulation {

public static void main(String[] args) {

 // 1. Create an object of the Scanner class

 // This will allow for user's inputs

 Scanner input = new Scanner(System.in);

 // 2. Create a prompt asking the user to enter the number of males

 System.out.println("Please enter the number of males");

 // 3. Receive the number entered by the user and store in an int

 // variable called  number_of_males.

 int number_of_males = input.nextInt();

 // 4. Create a prompt asking the user to enter the number of

               // females

 System.out.println("Please enter the number of females");

 // 5. Receive the number entered by the user and store in an int

 // variable  called, number_of_females

 int number_of_females = input.nextInt();

 // 6. Find the sum of the number of males and females

 // Store the result in an int variable called total.

 int total = number_of_males + number_of_females;

 // 7. Find the percentage of males by using the appropriate

 // formula.  Do a type-casting to allow for division in floating point

               // representation by prepending the number_of_males by (double)

 double percentagemales = (double) number_of_males / total * 100.0;

 // 8. Find the percentage of females by using the appropriate

 // formula.  Do a type casting to allow for division in floating point

               // representation by prepending the number_of_males by (double)

 double percentagefemales = (double) number_of_females / total * 100.0;

 // 9. Print out the results

 System.out.println("Percentage males : " + percentagemales + "%");

 System.out.println("Percentage females : " + percentagefemales + "%");

}

}

Explanation:

Please go through the comments in the code to give an explanation of the program. The source code file has also been added to this response. Please download it and go through it.

Download java
You might be interested in
The risk of carbon monoxide poisoning can be reduced by
lisov135 [29]
A machine. I foget the name but there can be a machine, or fresh air, or turning off your car, or opening doors and getting out when there;s a fire or smoke.
5 0
4 years ago
In Excel, an anchor($) allows you to:
Oksana_A [137]
The answer is the letter B.
6 0
3 years ago
Read 2 more answers
After a CPU decodes an instruction, what is the next step in the execution cycle?
Nat2105 [25]

Answer: E) The CPU executes the instruction by performing ALU operations.

Explanation: The execution cycle is of three stages namely; fetch, decode and execute. These are the functions that the CPU carries out from the time of boot-up up until it's shut down.

At the fetch stage, the computer retrieves program instructions from its memory register, at the decode stage; the decoders interprets the instructions from the instructions register and then the next stage will be the executions, at this stage; the interpreted instructions are then passed to relevant function units of the CPU to carry out the required instructions.

E.g mathematical and logic functions are passed on the ARITHMETIC AND LOGIC UNIT(ALU) to perform.

8 0
3 years ago
Which is the best book for C,C++,C# and objective C??
Korvikt [17]

Answer:

Head First books

Explanation:

My professor recommended them for basically any language. I ordered one for C off amazon and I love it. It's funny, interesting and educational all at once. Would recommend 10/10.

3 0
3 years ago
Importance of spread sheets​
Tema [17]

Answer:

It’s not that important but you can use it to help organize and grow your business.

Explanation:

3 0
3 years ago
Other questions:
  • Which cloud computing service model gives software developers access to multiple operating systems for testing?
    5·1 answer
  • A user has a PC with RAID configuration and reports slow computer performance. A technician uses the manufacture’s diagnostic so
    12·1 answer
  • How to make a sad face on keyboard using alt?
    5·2 answers
  • What is the difference between file and directory​
    12·1 answer
  • All of the following are good reasons to attend a cummunity college except
    10·2 answers
  • What does aperture control? A)amount of light the image sensor captures when taking a photo. B)how sensitive the camera is to in
    10·2 answers
  • Linux is a kind of software whose code is provided for use, modification, and redistribution. what kind of software is this?
    5·1 answer
  • GuardIN is an IT security firm. It deals with highly secure data for a wide variety of software and e-commerce agreements, trade
    7·1 answer
  • What is web <br>searching engine ?​
    9·1 answer
  • So im new how exactly does this point system work???​
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!