Question

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

We are using blueJ for my java class, if you can help me id greatly appreciate it.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODE:

import java.util.Scanner;

public class AverageWeight {
    public static void main(String[] args){
        //declaring a scanner class object
        Scanner sc = new Scanner(System.in);
        //declaring two arrays of length 3
        String[] names = new String[3];
        double[] weights = new double[3];
        double average = 0.0;
        //a loop which runs 3 times
        for(int i=0;i<3;i++){
            //asking the name
            System.out.println("Enter name: ");
            names[i] = sc.nextLine();
            //asking the weight
            System.out.println("Enter "+names[i]+"'s weight: ");
            weights[i] = Double.parseDouble(sc.nextLine());
            //adding all the weights for the average
            average += weights[i];
        }
        //calculating the average weight
        average = average/3.0;
        //printing the average weight
        System.out.printf("The average of all weights %.2f \n\n",average);
        //printing the contents of both the array
        for(int i=0;i<3;i++){
            System.out.printf("Name - %s\t Weight: %.2f\n",names[i],weights[i]);
        }

    }
}

___________________________________________

CODE IMAGES:

___________________________________________

OUTPUT:

__________________________________________

Feel free to ask any questions in the comments section

Thank You!

Add a comment
Know the answer?
Add Answer to:
We are using blueJ for my java class, if you can help me id greatly appreciate...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • We use bluej for our JAVA class. If you can help me id greatly appreciate it....

    We use bluej for our JAVA class. If you can help me id greatly appreciate it. Create a new Java class called AverageWeight. Create two arrays: an array to hold 3 different names and an array to hold their weights. 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...

  • We are using blueJ for my java class, if you can help me id greatly appreciate...

    We are using blueJ for my java class, if you can help me id greatly appreciate it. Create a new Java project/class called ChangeUp. Create an empty int array of size 6. Create a method called populateArray that will pass an array, use random class to choose a random index and prompt the user to enter a value, store the value in the array. Create a method called printArray that prints the contents of the array using the for each...

  • We are using blueJ for my java class, if you can help me id greatly appreciate...

    We are using blueJ for my java class, if you can help me id greatly appreciate it. Create a new Java project/class called ChangeUp. Create an empty int array of size 6. Create a method called populateArray that will pass an array, use random class to choose a random index and prompt the user to enter a value, store the value in the array. Create a method called printArray that prints the contents of the array using the for each...

  • We are using blueJ for my java class, if you can help me id greatly appreciate...

    We are using blueJ for my java class, if you can help me id greatly appreciate it. Create a new Java program called Flip. Write code that creates and populates an array of size 25 with random numbers between 1-50. Print the array. Print array in reverse.

  • We use bluej for our JAVA program. If you can help id greatly appreciate it. Create...

    We use bluej for our JAVA program. If you can help id greatly appreciate it. Create a new Java program called Flip. Write code that creates and populates an array of size 25 with random numbers between 1-50. Print the array. Print array in reverse.

  • Programming in java In this part of this Lab exercise, you will need to create a...

    Programming in java In this part of this Lab exercise, you will need to create a new class named ArrayShiftMult. This class carries out simple manipulation of an array. Then you should add a main method to this class to check that your code does what it is supposed to do. 1. Create a BlueJ project named LAB06 as follows: a. Open the P drive and create a folder named Blue), if it does not exist already. Under this folder,...

  • Hello, can someone please help me correct this code? I greatly appreciate it. 7.16 Ch 7...

    Hello, can someone please help me correct this code? I greatly appreciate it. 7.16 Ch 7 Warm up: People's weights (Lists) (Python 3) (1) Prompt the user to enter four numbers, each corresponding to a person's weight in pounds. Store all weights in a list. Output the list. (2 pts) Ex: Enter weight 1: 236.0 Enter weight 2: 89.5 Enter weight 3: 176.0 Enter weight 4: 166.3 Weights: [236.0, 89.5, 176.0, 166.3] (2) Output the average of the list's elements...

  • I need help with my assignment. It is a java program. Please make it as simple...

    I need help with my assignment. It is a java program. Please make it as simple as you can. Create an ArrayList with elements the objects of previous class. Using a simple loop populate the ArrayList with data from some arrays with data, or from console. Use a loop with iterator and write the information in a File using PrintWriter. Use this address for the file (c:\\result\\MyData.txt). Use the Scanner class to display the content of the file on console.

  • JAVA I. Using the Event Class created previously, create an array of objects;        II. Demonstrate...

    JAVA I. Using the Event Class created previously, create an array of objects;        II. Demonstrate passing array reference to a method;        III. Demonstrate creating array of objects that prints out only x 0.0 for all objects. PROJECT 5C - ARRAYS Create a new file called " EventArray5C". There are some "challenging" directions in this project. . 1.Prepare a document box (tell me that task(s) the application is to accomplish, how it will accomplish the tasks, the author of...

  • IN JAVA USING ECLIPSE The objective of this assignment is to create your own hash table...

    IN JAVA USING ECLIPSE The objective of this assignment is to create your own hash table class to hold employees and their ID numbers. You'll create an employee class to hold each person's key (id number) and value (name). Flow of the main program: Create an instance of your hash table class in your main method. Read in the Employees.txt file and store the names and ID numbers into Employee objects and store those in your hash table using the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT