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]
2 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]2 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
Which of the following is the best example of market censorship
Papessa [141]
To bleep it out! hopefully this helped
4 0
3 years ago
Read 2 more answers
Which of the following is most likely to include technical vocabulary?
Step2247 [10]
<span>C. a scientific article</span>
6 0
3 years ago
The core of ___________ is the implementation of intrusion detection systems and intrusion prevention systems at entry points to
cestrela7 [59]

Answer:

sorry I can't understand what is this is

3 0
2 years ago
When you’re upset, you’re __ to get into a crash compared to when you’re not upset
Daniel [21]

Answer:

Your answer would be more likely.

Explanation:

When someone is upset and they are driving they usually have their music baring and the they can't hear their surroundings and all they can think about is what they are upset about so therefor they don't pay attention. Hope this helped! Have a great day! :)

7 0
3 years ago
The National Institute of Standards and Technology (NIST) guidelines list four different states a mobile device can be in when y
Ahat [919]

Answer:

quiescent

Explanation:

The National Institute of Standards and Technology (NIST) guidelines list four different states a mobile device can be in when you extract data. The quiescent mode is a dormant mode that conserves battery life while maintaining user data and performing other background functions.

4 0
3 years ago
Other questions:
  • Which transformation(s) can be used to map ARST onto
    8·1 answer
  • )in the link based implementation of the ADT sorted list what is the worst case time efficiency of the remove method?
    7·1 answer
  • A client accessing a network share folder has authenticated into the system and has full access rights to a folder share. But af
    11·1 answer
  • an object or device outside the computer, that one would plug into a port to control the functions of a computer are?
    9·2 answers
  • Why shouldn't a server use a glass to scoop ice?
    6·2 answers
  • When microsoft introduced its zune mp3 player, many people thought it would capture the mp3 player market by pricing its product
    8·1 answer
  • Provides images of weather systems, and helps to track storms at different altitudes
    7·1 answer
  • Write at least and explain four types of escape sequences and create an example in an IDE which consist of the mentioned escape
    7·1 answer
  • What do you think entertainment or gaming platforms will look like in the future?
    9·1 answer
  • ________ is the use of information technology to support the sharing of content among networks of users.
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!