for beginning java, here's my assignment " Write a program that ask the user to enter a list of positive scores until the user enters a negative score to terminate the input.  You need to store these scores in an array.   You can assume the maximum number of scores the user may enter is 50.  However, you need to keep track of the actual number of scores entered.  Write 2 methods:

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter9: Advanced Array Concepts
Section: Chapter Questions
Problem 7PE
icon
Related questions
Question

for beginning java, here's my assignment "

Write a program that ask the user to enter a list of positive scores until the user enters a negative score to terminate the input.  You need to store these scores in an array.   You can assume the maximum number of scores the user may enter is 50.  However, you need to keep track of the actual number of scores entered.  Write 2 methods:

1. calculateAverage(): this method takes the list of scores and return the average score.

2. countPerfectScores(): this method takes the list of scores and return the number of perfect scores (100).

The main program reads the input and calls these methods and print the results.

Please make sure you write a comment line to document what your method does."

 

Here is my code, "

import java.util.Scanner;
class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    // Start array for scores
    int[] scores = new int[50];
    int size = 0;

    // Have user enter scores until negative Score is entered
    int score = sc.nextInt();
    while (score >= 0 && count<50) {
      scores[count] = score;
      count++;
      score = sc.nextInt();
  }
}

  // Calculate average score
  double average = calculateAverage(scores, size);
  System.out.println("Average: " + average);

  // Calculate number of Perfect Scores
  int perfect = calculatePerfect(scores, size);
  System.out.println("Number of Perfect Scores: " + perfect);
}

/** 
  * Calculates the average of the scores
  * @param scores - array of scores
  * @param size - number of scores
  * @return average - average of scores
  */
public static int calculatePerfect(int[] scores, int size) {
  int perfect = 0;
  for (int i = 0; i < size; i++) {
    if (scores[i] == 100) {
      perfect++;
    }
  }
  return perfect;
}"

Why won't it run? Also, what am i missing from completing the problem?

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning