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
Ludmilka [50]
3 years ago
5

Create a new Java application called "AverageCalculator" (without the quotation marks) that prompts the user with three separate

prompts for three numbers (use double values for these), computes the average of those three doubles (use a double for the average), and then prints out explanatory text, the three numbers, and their average, printed with 2 decimal places.For example, if the user gives your program the numbers 30, 100, and 21, your output should look very much like the following: The average of the numbers 30.00, 100.00, and 21.00 is 50.33.
Computers and Technology
1 answer:
k0ka [10]3 years ago
4 0
<h2>Answer:</h2>

//import the Scanner class

import java.util.Scanner;

public class AverageCalculator {

   public static void main(String[] args) {

       //Create an object of the Scanner class to allow for user's input

       Scanner input = new Scanner(System.in);

       

       //Create first prompt for the user to enter the first number

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

       

       //Use the Scanner object input, to receive the first number

       //And store in a double variable called fnum

       double fnum = input.nextDouble();

       

       //Create second prompt for the user to enter the second number

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

       

       //Use the Scanner object input, to receive the second number

       //And store in a double variable called snum

       double snum = input.nextDouble();

       

       //Create third prompt for the user to enter the third number

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

       

       //Use the Scanner object input, to receive the third number

       //And store in a double variable called tnum

       double tnum = input.nextDouble();

       

       //Declare a variable of type double, called avg, to hold the average of the three numbers

       double avg;

       

       //Now find the average of the three numbers,

       // and store the result of the average in the avg variable declared above

       avg = (fnum + snum + tnum) / 3;

               

       //Print out the result with explanatory text while you convert

       //all numbers to 2 decimal places by using the String.format() method.

       //The String.format() method takes in two arguments - the format descriptor and  

       //the number to be transformed.

       //First argument : In this case, the format descriptor is %.2f

       //Where the % sign signifies that the string (%.2f) is a format specifier.

       //The .2 specifies 2 decimal places. It means, you would use .3 if you wanted the number in 3 decimal places.

       //The f signifies that the number in question is a floating-point number.

       //Second argument : specifies the floating-point number to be transformed.        

       System.out.println("The average of the numbers " + String.format("%.2f", fnum) + ", " + String.format("%.2f", snum) + ", and " + String.format("%.2f", tnum) + " is " + String.format("%.2f", avg));

   

}      //End of main method

   

}   // End of class declaration

<h2>Sample output:</h2><h2>---------------------------------------------------------------</h2>

>> Please enter the first number

30

>> Please enter the second number

100

>> Please enter the third number

21

>> The average of the numbers 30.00, 100.00, and 21.00 is 50.33

<h2>---------------------------------------------------------------</h2>

<h2>Explanation:</h2>

The code above has been written in Java and it contains comments explaining every segment of the code. Please go through the comments carefully for more understanding.

<h2>Code without comments:</h2><h2 />

import java.util.Scanner;

public class AverageCalculator {

   public static void main(String[] args) {  

       Scanner input = new Scanner(System.in);

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

       double fnum = input.nextDouble();

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

       double snum = input.nextDouble();

     

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

       double tnum = input.nextDouble();

     

       double avg;

       avg = (fnum + snum + tnum) / 3;

               

       System.out.println("The average of the numbers " + String.format("%.2f", fnum) + ", " + String.format("%.2f", snum) + ", and " + String.format("%.2f", tnum) + " is " + String.format("%.2f", avg));

   

}  

   

}

You might be interested in
I need the answers. i don’t get this
bixtya [17]
Run,lazy,turtles,slow,wandering, jump,45,weird,pigs, cows, cousins, pale,rude,candles

There are many answers for this but this is what first came to my mind

Hope this helps
4 0
3 years ago
What is the purpose of a mail merge field.
coldgirl [10]

adding merge fields is a way to personalize a document with information from the data source. The merge fields come from the column headings in the data source.

:)

3 0
3 years ago
Mike wants to build an amplifier. Which technology can he use?
RSB [31]

Answer: The component that is used for most amplifiers is the transistor. Semiconductors like gold,copper etc. are used although poor semiconductors like silicon are sometimes used as well. There are many electronic circuits that all under the amplifier category. The classification of an amplifier depends on the size of the signal and configuration.

8 0
3 years ago
The social commerce feature that includes a stream of events to create a history for friends to view​ is/are called​ ___________
lesya692 [45]
<span>The social commerce feature that includes a stream of events to create a history for friends to view​ is called a <u>timeline</u>.
You can see it on Facebook, or any other social media you use - timeline is where you can see what other people are doing, or where they can see what is happening in your life, if you choose to share that with your friends on a social media network of your choice.</span>
4 0
3 years ago
Gold jewellery is made when solid-gold is melted and then put into containers which are the shape of the jewellery. After this t
Scilla [17]

Answer:

B

Explanation:

Self Explanatory - It is melted into a liquid then poured into a mold. It cools and becomes solid.

5 0
3 years ago
Other questions:
  • HELP ASAP ILL DO ANYTHING
    6·1 answer
  • The ____________________ packet-filtering firewall allows only a particular packet with a particular source, destination, and po
    10·1 answer
  • True or false A ClassB fire involves live electrical equipment
    5·1 answer
  • An effective problem statement ensures that
    12·1 answer
  • You are setting up a RAID system in a server designed for optimum fault tolerance, accuracy, and minimal downtime. Which HDD is
    7·1 answer
  • Creating a Graphical User Interface in Java
    11·1 answer
  • Why is information broken down into packets
    15·1 answer
  • SYSTEMY INFORMATYCZNE: Archiwizacja i kompresja zbiorów systemu Linu
    8·1 answer
  • Where do you find the instructions, learning objectives, evaluation and scoring for this aba assignment?.
    15·1 answer
  • Which of the following is/are used in multimedia?
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!