Question

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 output these three row averages to the command line.

Note

The requirement is to use a two-dimensional array of type double called ‘scores’ with 3 rows and 3 columns.

Two methods are required.

The first method prompts the user to enter 9 values and then stores them in the scores array. Using a nested loop (for or while) is required. As long as you use a nested loop of some type, that’s fine.

The second method calculates the row averages. My approach was to store the row averages in a separate 3-element array (declared in main and passed into the method as a parameter along with the scores array). Use a nested for loop for processing the rows and calculating the row averages.

The third method takes the 3-element array containing the row averages and uses a for loop to display each of the average values.

Here is an example run:

run:

Enter 9 numbers

Value 1: 10

Value 2: 20

Value 3: 30

Value 4: 40

Value 5: 50

Value 6: 60

Value 7: 70

Value 8: 80

Value 9: 90

The average of row 1 is 20.00

The average of row 2 is 50.00

The average of row 3 is 80.00

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

Program:

import java.util.Scanner;

public class Scorer {

public static void main(String args[])

{

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

getScores(scores);//method to get scores from user

double averages[] = new double[3];//to hold averages of user

getAverages(averages,scores);//method to calculate averages

printAverages(averages);//method to print averages

}

private static void printAverages(double[] averages) {

// TODO Auto-generated method stub

for(int i=0;i<3;i++)//iterating through array and printing averages

{

System.out.println("The average of row "+(i+1)+" is "+averages[i]);

}

}

private static void getAverages(double[] averages, double[][] scores) {

double sum=0;//to hold sum of each row

for(int i=0;i<3;i++)

{

for(int j=0;j<3;j++)

{

sum+=scores[i][j];

}

averages[i]=sum/3;//calculating and storing average

sum=0;

}

}

private static void getScores(double[][] scores) {

int i=0,j=0;

int count=1;

Scanner sc = new Scanner(System.in);//to read inout from user

System.out.println("Enter 9 numbers");

while(i<3)

{

j=0;

while(j<3)

{

System.out.println("value "+count);

scores[i][j]=sc.nextDouble();//reading into array

j++;

count++;

}

i++;

}

}

}

Output:

Problems@ Javadoc Declaration terminated- Scorer [Java Application] C\Program Fil Enter 9 numbers value 1 10 value 2 20 value 3 30 value 4 40 value 5 50 value 6 60 value 7 70 value 8 80 value 9 90 The average of row 1 is 20.0 The average of row 2 is 50.0 The average of row 3 is 80.0

Add a comment
Know the answer?
Add Answer to:
create a new Java application called "Scorer" (without the quotation marks) that declares a two-dimensional array...
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 "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...

  • create a new Java application called "MinMax" (without the quotation marks) that declares an array of...

    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.

  • create a new Java application called "CheckString" (without the quotation marks) according to the following guidelines....

    create a new Java application called "CheckString" (without the quotation marks) according to the following guidelines. ** Each method below, including main, should handle (catch) any Exceptions that are thrown. ** ** If an Exception is thrown and caught, print the Exception's message to the command line. ** Write a complete Java method called checkWord that takes a String parameter called word, returns nothing, and is declared to throw an Exception of type Exception. In the method, check if the...

  • Programing in Scala: Create a class called “Array” that implements a fixed-sized two-dimensional array of floating-point...

    Programing in Scala: Create a class called “Array” that implements a fixed-sized two-dimensional array of floating-point numbers. Write separate methods to get an element (given parameters row and col), set an element (given parameters row, col, and value), and output the matrix to the console formatted properly in rows and columns. Next, provide an immutable method to perform array addition given two same-sized array.

  • I've been assigned to create a new Java application called "CheckString" (without the quotation marks) according...

    I've been assigned to create a new Java application called "CheckString" (without the quotation marks) according to the following guidelines. ** Each method below, including main, should handle (catch) any Exceptions that are thrown. ** ** If an Exception is thrown and caught, print the Exception's message to the command line. ** Write a complete Java method called checkWord that takes a String parameter called word, returns nothing, and is declared to throw an Exception of type Exception. In the...

  • create a new Java application called "WeightedAvgDataAnalyzer" (without the quotation marks), that modifies the DataAnalyzer.java in...

    create a new Java application called "WeightedAvgDataAnalyzer" (without the quotation marks), that modifies the DataAnalyzer.java in Horstmann Section 7.5, pp. 350-351 according to the specifications below. The input file should be called 'data.txt' and should be created according to the highlighted instructions below. Note that even though you know the name of the input file, you should not hard-code this name into your program. Instead, prompt the user for the name of the input file. The input file should contain...

  • in java / You will: // 1- create a square 2 dimensional array of random size...

    in java / You will: // 1- create a square 2 dimensional array of random size (less than 11) // 2- fill the array with random integers from 1 to the size limit // 3- print the array // 4- prompt to see if the user wants to do another //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // 1- The square can use the same random value for x and y. Don't allow 0 size arrays. // 2- Maybe a nested set of for loops? to...

  • create a new Java application called "RecursiveTriangle" (without the quotation marks) according to the following guidelines....

    create a new Java application called "RecursiveTriangle" (without the quotation marks) according to the following guidelines. Modify the example in Horstmann Section 5.9, pp. 228-230 so that the triangle displays “in reverse order” as in the example below, which allows the user to set the number of lines to print and the String used for printing the triangle. Use a method to prompt the user for the number of lines (between 1 and 10) to print. This method should take...

  • Write a piece of code that constructs a two-dimensional array of integers with 5 rows and...

    Write a piece of code that constructs a two-dimensional array of integers with 5 rows and 10 columns. Fill the array with a multiplication table, so that array element [i][j] contains the value i * j. Use nested for loops to build the array. java Program

  •            1.         You often need to know the inheritance ____________________ of the Java API to work...

               1.         You often need to know the inheritance ____________________ of the Java API to work with its classes and subclasses.            2.         All objects have access to the methods of the ____________ class.            3.         If two classes share some common elements, you can define those elements in a ____________.            4.         To call a constructor or method of a superclass from a subclass, you use the ____________ keyword.            5.         A class that can be inherited by another...

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