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
Qual è la differenza tra variabile semplice e variabile strutturata? <br>​
Mrrafil [7]

Answer:

Sia la variabile semplice che la variabile strutturata possono avere il diverso set di valori, ma entrambi differiscono poiché la variabile semplice può contenere solo i valori di un tipo di dati. Tuttavia, la variabile strutturata può contenere la variabile di diversi tipi di dati come la struttura in c ++ ed elencare in Python. Ci sono anche molti altri esempi.

Ad esempio in c ++:

int num;  è una variabile semplice

e   struct class

        {

             int roll;

             string name;

        } class[25];

è una variabile strutturata che può memorizzare i dettagli dei 26 studenti.

Explanation:

Si prega di controllare la sezione di risposta.

6 0
4 years ago
What command do you use to set the suid bit on a script?
Debora [2.8K]
Unix/Linux question, cool.

<span>Typically we'd use chmod with +s in there.

chmod u+s script


</span>
5 0
3 years ago
The Fibonacci sequence {fib}i≥1 is defined recursively as follows: fib(1) = 1, fib(2) = 1 and, fib(n) = fib(n-1) + fib(n-2) for
nadya68 [22]
<h2>Answer:</h2>

// Create a class header definition

public class Fibonacci {

   

   //Create a method fib to return the nth term of the fibonacci series

   public static long fib(int n){

       

       //when n = 1, the fibonacci number is 1

       //hence return 1

       if (n <= 1){

           return 1;

       }

       

       //when n = 2, the fibonacci number is 1

       //hence return 2

       else if(n == 2){

           return 1;

       }

       

       //at other terms, fibonacci number is the sum of the previous two

       //numbers

       //hence, return the sum of the fib on the previous two numbers - n-1

       // and n-2

       else {

           return fib(n-1) + fib(n-2);

       }

       

   }

   

   //Create the main method to test the fib() method

   public static void main(String[] args) {

     

       // Test the fib method with n = 9        

       System.out.println(fib(9));

     

   }

}

=====================================================

<h2>Sample Output:</h2><h2></h2>

34

======================================================

<h2>Explanation:</h2>

The program above has been written in Java and it contains comments explaining each line of the code. Kindly go through the comments.

The actual lines of code are written in bold face to distinguish them from comments.

Also, a sample output of a run of the program has been provided.

4 0
3 years ago
Unlike bar codes and other systems, _____ devices do not have to be in contact with the scanner to be read.
UNO [17]

Answer:

radio frequency identification

Explanation:

7 0
3 years ago
A shrug is an example of
Gwar [14]
A shrug is an example of a non verbal expression that could mean the person does not know or has doubt but it depends on the context.
3 0
3 years ago
Other questions:
  • Match the feature to its function. 1. Normal view provide rows of icons to perform different tasks 2. Notes view an area in whic
    15·2 answers
  • If you only use part of a quotation, it is not necessary to include a citation
    6·1 answer
  • Which best describes a computer bug? A piece of computer hardware that is out of date or has a newer version a piece of computer
    14·2 answers
  • You often insert your company's logo into documents you create. One way to make it easier for you to quickly insert it is to sav
    12·1 answer
  • What is the Documenter?
    10·1 answer
  • The LPN/LVN cares for an older client admitted to the hospital for treatment of a fractured femur. The LPN/LVN notes the client
    10·2 answers
  • Advantages against its counterpart because of its portability​
    8·1 answer
  • Which of the following statements about security in the network is true?
    15·1 answer
  • In what ways can you sort data by using the sort procedure? Check all that apply.
    6·1 answer
  • Does anyone know how to write this right? This is for a coding class and I’m super confused on it.
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!