answer.
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
hichkok12 [17]
2 years ago
4

Allow a user to enter any number of double values up to 20. The user should enter 99999 to quit entering numbers. Display an err

or message if the user quits without entering any numbers; otherwise, display each entered value and its distance from the average. im using cengage and its only 15% correct but it works?import java.util.Scanner;public class DistanceFromAverage{public static void main(String[] args){double[] input = new double[20];int sentinal = 99999;double value;double total =0;int counter =0;boolean repeat=true;Scanner keyboard = new Scanner(System.in);// read valuesfor (int i = 0; i < input.length && repeat; i++) {System.out.print("Enter a value(99999 to exit):");value = keyboard.nextDouble();// breaks when values is 99999if (value == sentinal) {repeat=false;} else {input[i] = value;total += input[i];counter++;}}double average= total/counter;if (counter == 0)System.out.println("Error! Please enter any values");else {// calculate averageSystem.out.printf("%-10s%-20s\n","value","Distance from average");// calculate distancefor (int a = 0; a < counter; a++) {System.out.printf("%-10.2f%-10.2f\n",input[a],average-input[a]);}}}}
Computers and Technology
1 answer:
tangare [24]2 years ago
8 0

Answer:

import java.util.Scanner;

public class DistanceFromAverage

{

static double[] userValues = new double[20];

static double userInput;

static int totalValues = 1;

static int y = 0;

static double totalUserInput = 0;

static double avg;

public static void main(String[] args)

{

getInfoFromUser();

calculation();

}

public static void getInfoFromUser() {

 

Scanner input = new Scanner(System.in);

System.out.print("Enter an integer or enter 99999 to quit: ");

userInput = Double.parseDouble(input.nextLine());

if(userInput == 99999)

System.out.println("Enter a value: ");

while(userInput != 99999 && totalValues < userValues.length)

{

userValues[totalValues] = userInput;

totalUserInput = totalUserInput + userInput;

System.out.print("Enter an integer or enter 99999 to quit: ");

userInput = Double.parseDouble(input.nextLine());

if(userInput == 99999)

break;

totalValues++;

}

}

public static void calculation() {

avg = totalUserInput / totalValues;

System.out.println("You have entered " + totalValues + " numbers and their avg is " +avg);

for (y = 1; y < totalValues; ++y)

{

System.out.println(userValues[y] + " is " + (userValues[y] - avg) + " away from the avg");

}

}

}

Explanation:

  • Create the getInfoFromUser method that takes information from the user and save it in the array and if user enters 99999 then it exits
  • Stop taking information from user if it exceeds 20  inputs.
  • Create the calculation method that finds the average and as well as calculates the distance from the average.
  • Calculate the average by using the following formula:

avg = totalUserInput / totalValues

  • At the end, display all the results.
You might be interested in
Write a code segment that uses an enhanced for loop to print all elements of words that end with "ing". As an example, if words
nadezda [96]

Answer:

 public static void main(String[] args) {

   String ing[] = {"ten","fading","post","card","thunder","hinge","trailing","batting"};

   for (String i: ing){

     if (i.endsWith("ing")){

       System.out.println(i);

    }

   }

 }

Explanation:

The for-loop cycles through the entire list and the if-statement makes it so that the string is only printed if it ends with "ing"

6 0
2 years ago
Your friends credit scores are 560, 675, 710, 590, and 640. Your credit score is 680. What is the difference between the average
Wittaler [7]

Answer:

560+675+710+590+640=3175/5=635

so your credit score is 45 credits better than the average of your friends

Explanation:

3 0
2 years ago
You want to register the domain name ABCcompany.org, but the registration service is not allowing you to do that. What's the mos
Andreyy89

Options :

The domain name is registered to someone else.

Domain names must end in ".com".

You are not the legal owner of ABC Company.

Domain names must be all in lowercase.

Answer:

The domain name is registered to someone else.

Explanation: In the scenario above, ABCcompany.org represents the domain name of a particular person or establishment which provides access to the website of the owner. The domain name given to an individual or website must be distinct, that is no two different organizations or persons can use exactly the same domain name. Domain names can end with :. com, org, ng and various other and they aren't case sensitive. Therefore, the inability to register the domain name abive will likely stem from the fact that the domain name has is already registered to someone else.

6 0
2 years ago
What best describes the purpose of the Recycle Bin (Microsoft Windows) and Trash (Apple Mac) features
alexandr1967 [171]
Its to delete the files from the computer that you no longer want. Once its put in the recycling bin it stays there, then when you empty it, its off your computer and there is no way you can get those files back. This can also free-up some space from your computer since mega and giga bites are being removed from your computer.
7 0
2 years ago
Read 2 more answers
Rohan is creating a presentation with at least 50 slides. He wants the slides to use a consistent layout and formatting. Which o
erma4kov [3.2K]

The parts of the presentation that he should design first is Slide master

Slide master is a slide that enables you  to do the following:

•Modify your presentation to suit your taste

•It enables you to make  a partial or minor change  on the slide layout of your presentation

•Slide master  help you to  create a perfect and special  presentation.

•With Slide master  you can easily modify your slide text color.

Inconclusion The parts of the presentation that he should design first is Slide master.

Learn more about Slide master here:

brainly.com/question/12600334

4 0
2 years ago
Other questions:
  • What language(s) must be used to display a bare-minimum web page?
    9·2 answers
  • n the video, McWhorter says that “textspeak” might be a good thing for young people’s brains. Why does he think this?
    13·1 answer
  • Seneca has just applied conditional formatting and realizes that she has made a mistake. Which action should she take to fix the
    12·1 answer
  • Suppose a retailer who has no technology expertise wishes to set up an online presence for his business. He ________. a. ​can us
    6·1 answer
  • When using the following symbol, there are two arrows coming out of it. One arrow corresponds to what happens in the program if
    7·1 answer
  • In this assignment, you are provided with working code that does the following: 1. You input a sentence (containing no more than
    14·1 answer
  • In this problem, we want to compare the computational performance of symmetric and asymmetric algorithms. Assume a fast public-k
    11·1 answer
  • Given positive integer numInsects, write a while loop that prints that number doubled without reaching 200. Follow each number w
    14·1 answer
  • Write a loop to populate the list user_guesses with a number of guesses. The variable num_guesses is the number of guesses the u
    13·1 answer
  • Write a method so that the main() code below can be replaced by simpler code that calls method calcMilesTraveled(). Original mai
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!