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
PLEASE HELP WITH MY CODING!!!!!!!!!!!!!!
igor_vitrenko [27]
A: Similar..............
6 0
3 years ago
Read 2 more answers
Consider the following program:
Nostrana [21]

Answer:

this would be answer D

Explanation:

7 0
3 years ago
Write a method called classAttendence() that creates a 10-by-10 two-dimensional array and asks for user input to populate it wit
gladu [14]

Answer:

The method written in Java is as follows:

public static void classAttendance(){

   Scanner input = new Scanner(System.in);

   String[][] names = new String[10][10];

   for(int i =0;i<10;i++){

    for(int j =0;j<10;j++){

       System.out.print("Student Name: "+(i+1)+" , "+(j+1)+": ");

       names[i][j] = input.nextLine();        

    }  

   }

}

Explanation:

This defines the classAttendance() method

public static void classAttendance(){

   Scanner input = new Scanner(System.in);

This declares the 2D array of 10 by 10 dimension as string

   String[][] names = new String[10][10];

This iterates through the rows of the array

   for(int i =0;i<10;i++){

This iterates through the columns of the array

    for(int j =0;j<10;j++){

This prompts user for student name

       System.out.print("Student Name: "+(i+1)+" , "+(j+1)+": ");

This gets the student name from the user

       names[i][j] = input.nextLine();        

    }  

   }

The method ends here

}

<em>See attachment for complete program that include main method</em>

Download txt
6 0
2 years ago
Timothy is a multimedia designer. He needs to create a prototype of a new product that his firm is launching. Which multimedia s
mestny [16]

Explanation:

The answer is D. 3-f modeling

5 0
3 years ago
you where discussing software piracy with a friend and were surprised to learn how software piracy can impact your life every da
umka2103 [35]
Ahh, software. What is software piracy?
.
Ok... so it sounds evil.
.
BECAUSE IT IS!!
.
Software piracy can get you and suspected accomplices in court.
.
Fines up to a million dollars and lots of jail time.
.
Lots.
.
And lots.
.
But an effect of software piracy is that the software stealer himself earns money...
.
illegaly.
7 0
3 years ago
Other questions:
  • Use cases can be used to document both the current (As-Is) system and the future (To-Be) system. A. True B. False
    13·1 answer
  • You are attempting to update a Windows image that has been mounted under C:\mount on your local system. What command must you us
    13·1 answer
  • On Gmail, can I have an email get sent to someone at a certain time?
    7·1 answer
  • Describe how to manage the workspace by putting each feature under the action it helps carry out
    8·1 answer
  • Fill in the correct formula called a contains numbers from Rhodes 1 to 20 you can use the formula blank to find the volume of th
    14·1 answer
  • As the network engineer, you are asked to design an IP subnet plan that calls for three subnets. The largest subnet needs a mini
    14·1 answer
  • What are some (free) good animation websites (for PC/Microsoft) for a short informational video about homelessness?
    15·1 answer
  • Write a function all_cats that consumes a comma-separated string of animals and prints whether all of the animals have "cat" in
    12·1 answer
  • 20 points for ez question lol
    9·2 answers
  • What are some other ways to program a robot to navigate a complicated environment other than straight paths and right angle (90
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!