Question

First, launch NetBeans and close any previous projects that may be open (at the top menu...

First, launch NetBeans and close any previous projects that may be open (at the top menu go to File ==> Close All Projects).

Then create a new Java application called "MultiDimensions" (without the quotation marks) that declares a two-dimensional array of doubles (call it scores) with three rows and three columns and that uses methods and loops as follows.

Use a method containing a nested while loop to get the nine (3 x 3) doubles from the user at the command line.

Use a method containing a nested for loop to compute the average of the doubles in each row.

Use a method to output these three row averages to the command line.

Be sure to comment each method appropriately.

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

Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks

// MultiDimensions.java

import java.util.Scanner;

public class MultiDimensions {

      // method to read and fill a 2d array

      static void readArray(double array[][]) {

            // scanner to read input

            Scanner scanner = new Scanner(System.in);

            // looping through each row

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

                  // looping through each column

                  for (int j = 0; j < array[i].length; j++) {

                        // asking for a value, reading it to current position

                        System.out.printf("Enter a value for row %d column %d: ", i, j);

                        array[i][j] = scanner.nextDouble();

                  }

            }

      }

      // method to calculate and return an array containing averages of each row

      // in 2d array

      static double[] rowAverages(double array[][]) {

            // creating an array big enough to store averages of all rows

            double avgs[] = new double[array.length];

            // looping through each row

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

                  // initializing sum to 0

                  double sum = 0;

                  // looping through each column

                  for (int j = 0; j < array[i].length; j++) {

                        // summing values

                        sum += array[i][j];

                  }

                  // finding average, adding to avgs array

                  avgs[i] = (double) sum / array[i].length;

            }

            return avgs;

      }

      // method to output row averages into the console window

      static void outputRowAverages(double avgs[]) {

            // looping through each value and printing it. formatting average to 3

            // decimal digits

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

                  System.out.printf("Average of row %d is %.3f\n", i, avgs[i]);

            }

      }

      public static void main(String[] args) {

            // creating a 3x3 double array

            double array[][] = new double[3][3];

            // reading, filling values

            readArray(array);

            // finding row averages

            double avgs[] = rowAverages(array);

            // displaying row averages

            outputRowAverages(avgs);

      }

}

/*OUTPUT*/

Enter a value for row 0 column 0: 1

Enter a value for row 0 column 1: 2

Enter a value for row 0 column 2: 3

Enter a value for row 1 column 0: 4

Enter a value for row 1 column 1: 5

Enter a value for row 1 column 2: 6

Enter a value for row 2 column 0: 7

Enter a value for row 2 column 1: 8

Enter a value for row 2 column 2: 9

Average of row 0 is 2.000

Average of row 1 is 5.000

Average of row 2 is 8.000

Add a comment
Answer #2

As an AI language model, I don't have direct access to your computer to launch NetBeans or interact with its graphical interface. However, I can provide you with the Java code to create the "MultiDimensions" application as described. You can then copy and paste this code into a new Java project in NetBeans.

Here's the Java code for the "MultiDimensions" application:

javaCopy codeimport java.util.Scanner;public class MultiDimensions {    public static void main(String[] args) {        // Create a two-dimensional array of doubles with three rows and three columns
        double[][] scores = new double[3][3];        // Call the method to get the nine doubles from the user
        getDoublesFromUser(scores);        // Call the method to compute the average of the doubles in each row
        double[] rowAverages = computeRowAverages(scores);        // Call the method to output the row averages to the command line
        outputRowAverages(rowAverages);
    }    // Method to get the nine doubles from the user at the command line
    public static void getDoublesFromUser(double[][] scores) {        Scanner scanner = new Scanner(System.in);
        System.out.println("Enter nine doubles for the 3x3 array:");        for (int i = 0; i < 3; i++) {            for (int j = 0; j < 3; j++) {
                scores[i][j] = scanner.nextDouble();
            }
        }
        scanner.close();
    }    // Method to compute the average of the doubles in each row
    public static double[] computeRowAverages(double[][] scores) {        double[] rowAverages = new double[3];        for (int i = 0; i < 3; i++) {            double sum = 0;            for (int j = 0; j < 3; j++) {
                sum += scores[i][j];
            }
            rowAverages[i] = sum / 3;
        }        return rowAverages;
    }    // Method to output the row averages to the command line
    public static void outputRowAverages(double[] rowAverages) {
        System.out.println("Row Averages:");        for (int i = 0; i < 3; i++) {
            System.out.println("Row " + (i + 1) + ": " + rowAverages[i]);
        }
    }
}

To create the "MultiDimensions" Java application in NetBeans, follow these steps:

  1. Launch NetBeans.

  2. Click on "File" in the top menu, then choose "New Project..."

  3. In the "New Project" dialog, select "Java" in the "Categories" list, and "Java Application" in the "Projects" list. Click "Next."

  4. Enter "MultiDimensions" as the project name and choose the desired project location. Click "Finish."

  5. In the "Projects" tab on the left, right-click on the "MultiDimensions" project and choose "New" > "Java Class."

  6. Name the class "MultiDimensions" and make sure the "Main Class" checkbox is checked. Click "Finish."

  7. Replace the default code in the "MultiDimensions" class with the code provided above.

  8. Save the file (Ctrl + S or Command + S).

  9. Run the program by clicking the green "Play" button (or press Shift + F6).

Now, you should be able to enter nine doubles at the command line when prompted, and the program will compute and output the row averages for the 3x3 array.

answered by: Hydra Master
Add a comment
Know the answer?
Add Answer to:
First, launch NetBeans and close any previous projects that may be open (at the top menu...
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
  • First, launch NetBeans and close any previous projects that may be open (at the top menu...

    First, launch NetBeans and close any previous projects that may be open (at the top menu go to File ==> Close All Projects). Then create a new Java application called "MinMax" (without the quotation marks) that declares an array of doubles of length 5, and uses methods to populate the array with user input from the command line and to print out the max (highest) and min (lowest) values in the array. The methods that determine the max and min...

  • First, launch NetBeans and close any previous projects that may be open (at the top menu...

    First, launch NetBeans and close any previous projects that may be open (at the top menu go to File ==> Close All Projects). Then create a new Java application called "PasswordChecker" (without the quotation marks) that gets a String of a single word from the user at the command line and checks whether the String, called inputPassword, conforms to the following password policy. The password must: Be 3 characters in length Include at least one uppercase character Include at least...

  • "PhoneNumberConversion" First, launch NetBeans and close any previous projects that may be open (at the top...

    "PhoneNumberConversion" First, launch NetBeans and close any previous projects that may be open (at the top menu go to File ==> Close All Projects). Then create a new Java application called "PhoneNumberConversion" (without the quotation marks) based on the Horstmann textbook chapter 2 programming exercise called Business, P 2.23 on page 75, in the section on Programming Exercises near the end of Chapter 2, before the answers to the self-check questions. Request the ten-digit phone number from the user at...

  • create a new Java application called "Scorer" (without the quotation marks) that declares a two-dimensional array...

    create a new Java application called "Scorer" (without the quotation marks) that declares a two-dimensional array of doubles (call it scores) with three rows and three columns and that uses methods and loops as follows. Use a method containing a nested while loop to get the nine (3 x 3) doubles from the user at the command line. Use a method containing a nested for loop to compute the average of the doubles in each row. Use a method to...

  • This is the contents of Lab11.java import java.util.Scanner; import java.io.*; public class Lab11 { public static...

    This is the contents of Lab11.java import java.util.Scanner; import java.io.*; public class Lab11 { public static void main(String args[]) throws IOException { Scanner inFile = new Scanner(new File(args[0])); Scanner keyboard = new Scanner(System.in);    TwoDArray array = new TwoDArray(inFile); inFile.close(); int numRows = array.getNumRows(); int numCols = array.getNumCols(); int choice;    do { System.out.println(); System.out.println("\t1. Find the number of rows in the 2D array"); System.out.println("\t2. Find the number of columns in the 2D array"); System.out.println("\t3. Find the sum of elements...

  • Hello Guys. I need help with this its in java In this project you will implement...

    Hello Guys. I need help with this its in java In this project you will implement a Java program that will print several shapes and patterns according to uses input. This program will allow the use to select the type (say, rectangle, triangle, or diamond), the size and the fill character for a shape. All operations will be performed based on the user input which will respond to a dynamic menu that will be presented. Specifically, the menu will guide...

  • **JAVA PLEASE!!** CSE205 Assignment 2 ASCII Terrain Generator 5Opts Topics: Arrays Multidimensional Arrays Metho...

    **JAVA PLEASE!!** CSE205 Assignment 2 ASCII Terrain Generator 5Opts Topics: Arrays Multidimensional Arrays Methods Loops and Conditionals Description The goal of this assignment is for you to produce a simple procedurally generated terrain map out of ASCII character symbols. This will be done through simple probability distributions and arrays Use the following Guideline s: Give identifiers semantic meaning and make them easy to read (examples numStudents, grossPay, etc) Keep identifiers to a reasonably short length. User upper case for constants....

  • We learn arrays (and Arrays class) in Chapter 10 and ArrayList collection in Chapter 14. This...

    We learn arrays (and Arrays class) in Chapter 10 and ArrayList collection in Chapter 14. This assignment asks you to re-do Assignment 4 by using arrays and ArrayList collections to deliver exactly the same output. The input also stays the same, which are two argument values entered at the command line when 'java' command is issued. With the use of these data structures that help to store data in certain way, you are not going to print each character immediately...

  • The ACME Manufacturing Company has hired you to help automate their production assembly line. Cameras have...

    The ACME Manufacturing Company has hired you to help automate their production assembly line. Cameras have been placed above a conveyer belt to enables parts on the belt to be photographed and analyzed. You are to augment the system that has been put in place by writing C code to detect the number of parts on the belt, and the positions of each object. The process by which you will do this is called Connected Component Labeling (CCL). These positions...

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