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
Charra [1.4K]
3 years ago
11

Write the method public static doublell quizAverages (double (1 scores). which takes a 2D array of doubles that represent quiz s

cores for students in a course and returns an array of quiz averages. Specifically, each column represents a quiz, and each row represents a student in the class. Therefore, what the method returns is an array of column averages, essentially. Assume that all students take the same number of quizzes
Computers and Technology
1 answer:
Helga [31]3 years ago
8 0

Answer:

  1. import java.util.Arrays;
  2. public class Main {
  3.    public static void main(String[] args) {
  4.        double [][] studentScores = {
  5.                {78, 40, 97},
  6.                {89, 90, 68},
  7.                {70, 35, 88}
  8.        };
  9.        System.out.println(Arrays.toString(quizAverages(studentScores)));
  10.    }
  11.    public static double[] quizAverages(double [][] scores){
  12.        double average[] = new double[scores[0].length];
  13.        for(int col = 0; col < scores[0].length; col++){
  14.            double sum = 0;
  15.            for(int row =0; row < scores.length; row++){
  16.                sum += scores[row][col];
  17.            }
  18.            average[col] = sum / scores[col].length;
  19.        }
  20.        return average;
  21.    }
  22. }

Explanation:

The solution code is written in Java.

Firstly, create a static method that take one input parameter, double type two dimensional arrays and this method will return one array of average as required by question (Line 11).

In the method, declare a double type array and initialize its size with the length of the column of the input scores array (Line 12).

Create a double layer of for loop with outer loop to iterate through the column of the input score array and the inner loop to iterate through the row (Line 13-15). In the outer loop, create a sum variable to hold the value of summation for each column (Line 14). In the inner loop, increment the sum variable with the score in each row (Line 16). After finishing one inner loop cycle, the sum is divided by the length of column and assign it to an item of average array in outer loop before proceed to the next round of outer loop to repeat the same process (Line 18).

At last return the average array (Line 20).

We can test the method using a sample data (Line 4-8) and print out the output returned by the method (Line 9).  

You might be interested in
What is the computer?​
DiKsa [7]

Answer:

an electronic machine that can store, find and

8 0
2 years ago
Coupon collector is a classic statistic problem with many practical applications. The problem is to pick objects from a set of o
ahrayia [7]

Answer:

Here is the JAVA program:

public class Main {  //class name

public static void main(String[] args) {   //start of main method

//sets all boolean type variables spades, hearts diamonds and clubs to false initially

   boolean spades = false;  

   boolean hearts = false;

   boolean diamonds = false;

   boolean clubs = false;  

   String[] deck = new String[4];  //to store card sequence

   int index = 0;  //to store index position

   int NoOfPicks = 0;  //to store number of picks (picks count)

   while (!spades || !hearts || !diamonds || !clubs) {   //loop starts

       String card = printCard(getRandomCard());  //calls printCard method by passing getRandomCard method as argument to it to get the card

       NoOfPicks++;   //adds 1 to pick count

       if (card.contains("Spades") && !spades) {  //if that random card is a card of Spades and spades is not false

           deck[index++] = card;  //add that card to the index position of deck

           spades = true;  //sets spades to true

       } else if (card.contains("Hearts") && !hearts) {  //if that random card is a card of Hearts and hearts is not false

           deck[index++] = card;  

           hearts = true;   //sets hearts to true

       } else if (card.contains("Diamond") && !diamonds) {  //if that random card is a card of Diamond and diamonds is not false

           deck[index++] = card;

           diamonds = true;  //sets diamonds to true

       } else if (card.contains("Clubs") && !clubs) {  if that random card is a card of Clubs and clubs is not false

           deck[index++] = card;

           clubs = true;         }     }   //sets clubs to true

   for (int i = 0; i < deck.length; i++) {  //iterates through the deck i.e. card sequence array

       System.out.println(deck[i]);     }  //prints the card number in deck

   System.out.println("Number of picks: " + NoOfPicks);  }   //prints number of picks

public static int getRandomCard() {  //gets random card

   return (int) (Math.random() * 52); }   //generates random numbers of 52 range

public static String printCard(int cardNo) {   //displays rank number and suit

   String[] suits = { "Spades", "Hearts", "Diamonds", "Clubs", };  //array of suits

   String[] rankCards = { "Ace", "2", "3", "4", "5", "6", "7", "8", "9", "10",

           "Jack", "Queen", "King" };   //array of rank

  int suitNo = cardNo / 13;  //divides card number by 13 and stores to suitNo

 int rankNo = cardNo % 13;   //takes modulo of card number and 13 and store it to rankNo

   return rankCards[rankNo] + " of " + suits[suitNo];  }}  //returns rankCard at rankNo index and suits at suitNo index

Explanation:

The program is explained in the comments attached with each line of code. The screenshot of the program along with its output is attached.

8 0
3 years ago
Imagine that you need to be late to work next Thursday because of a doctor's appointment. Compose your own e-mail appropriate fo
ratelena [41]
In form your boss a week early
8 0
3 years ago
We need goku and naruto fight story someone
lana [24]

Answer:

goku comes in and turns super sayain  naruto come in with kurama and naruto get goku with a rasagen and geku is still fist fightin while naruto is using his kurama and turns into kurama and knocks out goku now naruto thinks he won and goku IS HITIN HIM WITH A KAMEKAMEHA GOKU IS SIROUS NOW

Explanation:

8 0
3 years ago
Read 2 more answers
Write a static method that implements a recursive formula for factorials. Place this method in a test program that allows the us
matrenka [14]

Answer:

Written in Java

import java.util.*;

public class Main {

  public static int fact(int n) {

     if (n == 1)

        return n;

     else

        return n * fact(n - 1);

  }

  public static void main(String[] args) {

     int num;

     Scanner input = new Scanner(System.in);

     char tryagain = 'y';

     while(tryagain == 'y'){

     System.out.print("Number: ");

     num = input.nextInt();

     System.out.println(num+"! = "+ fact(num));

     System.out.print("Try another input? y/n : ");

     tryagain = input.next().charAt(0);

}        

  }

}

Explanation:

The static method is defines here

  public static int fact(int n) {

This checks if n is 1. If yes, it returns 1

     if (n == 1)

        return n;

If otherwise, it returns the factorial of n, recursively

     else

        return n * fact(n - 1);

  }

The main method starts here. Where the user can continue executing different values of n. The program keep prompting user to try again for another number until user signals for stoppage

  public static void main(String[] args) {

This declares num as integer

     int num;

     Scanner input = new Scanner(System.in);

This initializes tryagain as y

     char tryagain = 'y';

This checks if user wants to check the factorial of a number

     while(tryagain == 'y'){

This prompts user for input

     System.out.print("Number: ");

This gets user input

     num = input.nextInt();

This passes user input to the function and also prints the result

     System.out.println(num+"! = "+ fact(num));

This prompts user to try again for another value

     System.out.print("Try another input? y/n : ");

This gets user response

     tryagain = input.next().charAt(0);

}        

Download txt
4 0
2 years ago
Other questions:
  • What feature new to Windows Server 2012 provides the ability to find identical sets of data on a SAN based storage array and red
    14·1 answer
  • What are three reasons teens might start drinking alcohol??
    7·2 answers
  • An Internet Service Provider (ISP) is a company that builds the routers and wired connections that allow individuals to access t
    12·2 answers
  • What is an activity that can help you enhance the appearance of your computer’s desktop?
    13·1 answer
  • (01.03 LC)
    9·1 answer
  • What is a cookie? *
    9·2 answers
  • What is the console.log function for?​
    13·1 answer
  • For her presentation on Italy, Matilda used a red background with light green text. When her friend critiqued her presentation,
    12·1 answer
  • what is one category of software mentioned in the unit materials as being example of groupware English technical
    15·1 answer
  • balance exercises used for introducing balance training should initially involve little joint motion and improve what type of co
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!