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
serious [3.7K]
3 years ago
13

Create a new Java class called AverageWeight. Create two arrays: an array to hold 3 different names and an array to hold their w

eights. Use Scanner to prompt for their name and weight and store in correct array. Compute and print the average of the weights entered using printf command. Use a loop to traverse and print the elements of each array or use Arrays class method to print. Submit your code.
Computers and Technology
1 answer:
Ainat [17]3 years ago
5 0
<h2>Answer:</h2><h2></h2>

//import the Scanner class

import java.util.Scanner;

//begin class definition

public class AverageWeight{

       //declare the main method

    public static void main(String []args){

     

       //declare the names array

       String [] names = new String [3];

       

       //declare the weights array

       double [] weights = new double [3];

       

       //Create an object of the Scanner class

       Scanner input = new Scanner(System.in);

       

       

       //create a loop to ask for the names and weights.

       for(int i = 0; i< names.length; i++){

           System.out.println("Enter name " + (i+1));

           names[i] = input.next();

           

           System.out.println("Enter weight " + (i+1));

           weights[i] = input.nextDouble();

           

       }

       

       

       

       //find the sum of the weights

       double sum = 0.0;

       for(int j = 0; j< weights.length; j++){

           sum += weights[j];

           

       }

       

       //find the average

       double average = sum / weights.length;

       

       //print out the average of the weights

       System.out.printf("%s%f \n", "The average of the weights is ", average);

       

       

       //print out the elements of the names array

       System.out.println("Names : ");

       System.out.print("{ ");

       for(int i = 0; i< names.length; i++){

           

           System.out.print(names[i] + " ");

           

       }

       System.out.print(" }");

       

       

       //print out the elements of the weights array

       System.out.println();

       System.out.println();

       System.out.println("Weights : ");

       System.out.print("{ ");

       for(int i = 0; i< weights.length; i++){

           

           System.out.print(weights[i] + " ");

           

       }

       System.out.print(" }");

       

     

    } //end of main method

   

   

} //end of class definition

<h2>Sample Output</h2>

>> Enter name 1

Peter

>> Enter weight 1

12.0

>> Enter name 2

Joe

>> Enter weight 2

23.4

>> Enter name 3

Paul

>> Enter weight 3

23.9

The average of the weights is 19.766667  

Names :  

{ Peter Joe Paul  }

Weights :  

{ 12.0 23.4 23.9  }

<h2>Explanation:</h2>

The code contains comments explaining important lines.

The source code file has been attached to this response.

A sample output has also been provided.

Download java
You might be interested in
If a user inserts a piece of clip art over some text but does not want the art to block the text, the user should select
Yuri [45]

Answer:

send backward

Explanation:

4 0
4 years ago
Read 2 more answers
TRUE OR FALSE: THE BUILDER'S CLUB IS A PAID SUBSCRIPTION.
nadya68 [22]

Answer:

true

Explanation:

3 0
3 years ago
Read 2 more answers
3. In 1989, the first handheld console was released by _____ and it was called ________.
beks73 [17]
Answer: b) Nintendo, Game Boy

In 1989, the first handheld console was released by _Nintendo_ and it was called _Game Boy_.
5 0
3 years ago
How do you know how much space is on the computer
Vladimir79 [104]
Depending on which computer you have you can go into settings and check the data tab or it should be on the box how much it comes with :)
5 0
4 years ago
Read 2 more answers
Microsoft words spell checker
Virty [35]
To check spelling<span> in a </span>Word<span> document, open up the document, head to the “Review” tab, then click on “</span>Spelling<span> & Grammar” (part of the “Proofing” group of tools). 

</span>
4 0
3 years ago
Other questions:
  • The speed of a cpu is expressed in cycles called ________.
    14·1 answer
  • The media is a phase that people often use to refer to:
    6·1 answer
  • Which one of the following may be used as an input as well as an output device? A. Fax machine B. Scanner C. Printer D. Voice re
    9·1 answer
  • One of the network printers is producing copies where the toner is smeared on paper after printing. What component should be che
    11·1 answer
  • Useful open source applications include the popular Web browser Mozilla Firefox, the e-mail application Thunderbird, the relatio
    7·2 answers
  • Visual-verbal synergy has nothing to do with text, but solely with images used in a design.
    9·1 answer
  • When you buy software, you then own it and can do anything you’d like with it, including giving it to friends to install on thei
    12·1 answer
  • Question 4 (Worth 5 points)
    14·2 answers
  • you are teaching a class about basic camera functions like power, basic date/time, menu navigation, and how to properly attach a
    9·1 answer
  • Write a Python statement that displays the value referenced by the number variable formatted as1,234,567.5
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!