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
Write a complete program that asks the user to input the height and radius of a cone (both of type double) and calls two individ
Vika [28.1K]

Answer:

The program in C++ is as follows:

#include <iostream>

#include <math.h>

using namespace std;

double area(double r, double h){

   double A = 3.14 * r * (r + sqrt(h*h + r*r));

   return A;}

double volume(double r, double h){

   double V = (1.0/3) * 3.14 * r*r * h;

   return V;}

int main(){

   double radius, height;

   cout<<"Radius: "; cin>>radius;

   cout<<"Height: "; cin>>height;

   cout<<"Area: "<<area(radius,height)<<endl;

   cout<<"Volume: "<<volume(radius,height);

   return 0;

}

Explanation:

This declares the area function

double area(double r, double h){

Calculate area

   double A = 3.14 * r * (r + sqrt(h*h + r*r));

Return the calculated area

   return A;}

This declares the volume method

double volume(double r, double h){

Calculate volume

   double V = (1.0/3) * 3.14 * r*r * h;

Return the calculated volume

   return V;}

The main begins here

int main(){

Declare radius and height

   double radius, height;

Get input for radius

   cout<<"Radius: "; cin>>radius;

Get input for height

   cout<<"Height: "; cin>>height;

Call the area function and print the returned value for area

   cout<<"Area: "<<area(radius,height)<<endl;

Call the volume function and print the returned value for volume

   cout<<"Volume: "<<volume(radius,height);

   return 0;

}

4 0
3 years ago
What sorts of items can be
Bumek [7]

Answer:

A router connects multiple computers to the Internet through a single connection. The router manages the flow of data, delivering the right information to each computer on the network. Routers may also be used to connect multiple networks. A managed router is a router that is owned and managed by a third-party.

6 0
4 years ago
Field whose data type is ____ can contain any characters.
liubo4ka [24]

1. B

2. A

3.C

4.D

5.C

6.B

7.D

8.A

9.C

10.D

11.D

12.A

13.B

14.C

15.D

7 0
3 years ago
if ( (ans == 'Y' &amp;&amp; errors &lt; 5) || numTries &lt; 10 ) // note uppercase 'Y' count++; Which combinations of values res
Shkiper50 [21]

The correction options to the case abode are:

Option B. ans = 'Y' (upper case)

errors = 6

numTries = 5

Option C. ans = 'y' (lower case)

errors = 4

numTries = 5

Option D. ans = 'Y' (upper case)

errors = 100

numTries = -1

<h3>What is Coding?</h3>

Computer coding is known to be the act that entails the use of computer programming languages to instruct the computers and machines on a given number of instructions on what need to be  performed.

Note that in the statement above,  the combinations of values results in count being incremented after the statement is complete is option B, C and D.

See full question below

Learn mode about coding from

brainly.com/question/22654163

#SPJ1

3 0
2 years ago
When computer criminals launch an intentional attack in which a malicious hacker floods a server with millions of bogus service
makkiz [27]
I'm pretty sure it's a DDOS or DOS attack
6 0
4 years ago
Other questions:
  • Given the following word addresses: 3, 180, 43, 2, 191, 88, 190, 14, 181, 44, 186, 253a.Show the final cache contents for a thre
    12·1 answer
  • When a program lets the user know that an invalid choice has been made, this is known as:?
    6·1 answer
  • From the Start screen, you can A. access recently opened Excel workbooks. B. create a document from a template. C. create new bl
    12·2 answers
  • What is the name of the process that is used to establish whether or not a user’s identity is legitimate?
    7·1 answer
  • Consider whether there are additional components that could be added to the IPv4 protocol to enhance its usefulness. What are th
    15·1 answer
  • Why is outfitting a workplace with video games in a technology development company consiered a strategic use of money
    14·1 answer
  • When you want to specify multiple criteria, and all criteria must be true for a record to be included in the results, when the _
    9·1 answer
  • )duplicate hash code
    15·1 answer
  • Write a program that prompts the user to enter an oligonucleotide sequence, such as TATGAGCCCGTA.
    7·1 answer
  • What is ICT?Write down the uses of ICT​
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!