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 "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...

  • 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....

  • 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...

  • Lab 2: (one task for Program 5): Declare an array of C-strings to hold course names,...

    Lab 2: (one task for Program 5): Declare an array of C-strings to hold course names, and read in course names from an input file. Then do the output to show each course name that was read in. See Chapter 8 section on "C-Strings", and the section "Arrays of Strings and C-strings", which gives an example related to this lab. Declare the array for course names as a 2-D char array: char courseNames[10] [ 50]; -each row will be a...

  • C Thank You for You x Home - OwNet x B Assignment 401 X CPP-A01 -...

    C Thank You for You x Home - OwNet x B Assignment 401 X CPP-A01 - Dynam x ASM-103 - Intege X ASM-A03 - Integex Calculus - Find voll x D (10) Disc method X + -ox + → C onedrive.live.com/view.aspx?resid-322690C11EFFEB37!1631&ithint-file%2cdocxêauthkey-!AOJByR3MAP202A Word Sign in OneDrive CPP-A01 - Dynamic Multiplication Table Accessibility Mode Download Save to OneDrive Print ... When completing this assignment, the student should demonstrate mastery of the following concepts: • Visual Studio Project Creation • C++ Formatted Output...

  • Advanced Object-Oriented Programming using Java Assignment 4: Exception Handling and Testing in Java Introduction -  This assignment...

    Advanced Object-Oriented Programming using Java Assignment 4: Exception Handling and Testing in Java Introduction -  This assignment is meant to introduce you to design and implementation of exceptions in an object-oriented language. It will also give you experience in testing an object-oriented support class. You will be designing and implementing a version of the game Nim. Specifically, you will design and implement a NimGame support class that stores all actual information about the state of the game, and detects and throws...

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