Question

Write a program that instantiates an array of integers named scores. Let the size of the...

Write a program that instantiates an array of integers named scores. Let the size of the array be 10. The program then first invokes randomFill to fill the scores array with random numbers in the range of 0 -100. Once the array is filled with data, methods below are called such that the output resembles the expected output given.

The program keeps prompting the user to see if they want to evaluate a new set of random data. Find below the names of methods and their description.

Hint: All methods are static and they will be in StatsArray.java under the main method. Please check out the static method demo before start working on this assignment.

  • public static void randomFill (int [] data)

This method fills an array with random numbers in the range of 0-100

  • public static int getTotal(int [] data)

This method calculates and returns the total of all values in the array

  • public static double getAvg(int[] data)

This method returns the average of the values in the array

  • public static int getLargest(int [] data)

This method finds and returns the largest value in the array

  • public static int getSmallest(int [] data)

This method finds and returns the smallest value in the array

  • public static int findLetterGrade(int lowRange, int highRange, int data [])

       The method counts and returns the number of values between the given range inclusive.

  • public static boolean isNumberFound(int someNumber, int data [])

This method returns true if the array contains someNumber , return false otherwise.

  • public static void displayData(int[] data)

This method displays the array with index in [ ] as shown in the given output.

Hint: In order to get number of A’s the range will be between 90-100 inclusive and for the number of B’s the range will be between 80-89 inclusive

Expected Output:

Exam Scores

-----------

[0] 51

[1] 0

[2] 91

[3] 8

[4] 96

[5] 11

[6] 74

[7] 27

[8] 80

[9] 20

The minimum value : 0

The maximum value : 96

The total is : 458

The average is : 45.8

Number of A's : 2

Number of B's : 1

Sorry, you DO NOT have a perfect exam score.

Please enter Y to continue and N to quit: y

Exam Scores

-----------

[0] 59

[1] 75

[2] 91

[3] 50

[4] 45

[5] 85

[6] 12

[7] 82

[8] 84

[9] 68

The minimum value : 12

The maximum value : 91

The total is : 651

The average is : 65.1

Number of A's : 1

Number of B's : 3

Sorry, you DO NOT have a perfect exam score.

Please enter Y to continue and N to quit: n

Goodbye!

import java.util.*;

/**
 * Program name: StatsArray.java
 * @author 
 * Class:
 * Date:  
 * Description: Makes a random array of number and that are used to represent
 * test scores at random and allows the user to continually make new ones
 */
public class StatsArray {
    

        public static void main(String[] args) {
                final int SIZE = 10;
                //Declaring scores array
                int[] stats = new int[SIZE];
        
                //Your code 
                
                
                
                
                
                
                
                
        
}  // end of main method

/**
 * This method randomFill fills array with random numbers in the range of 0-100
 * @param data array to be filled with random numbers
 */
        public static void randomFill( int[] data ) {
            
           Random rand = new Random();
           
            for( int i = 0; i < data.length; ++i ) {
            
                data[i] = rand.nextInt(101);
                
           }


   }  //end randomFill method
        
        
        //ADD the rest of the static methods given in the assignment below. 
        
        
        
  
} //end of StatsArray Class 
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Screenshot

Program

import java.util.*;

/**
* Program name: StatsArray.java
* @author
* Class:
* Date:
* Description: Makes a random array of number and that are used to represent
* test scores at random and allows the user to continually make new ones
*/
public class StatsArray {
  

        public static void main(String[] args) {
                final int SIZE = 10;
                //Declaring scores array
                int[] stats = new int[SIZE];
                char ch;
                Scanner sc=new Scanner (System.in);
                do {
                   randomFill(stats);
                   displayData(stats);
                   System.out.println("The minimum value : "+getSmallest(stats));
                   System.out.println("The maximum value : "+getLargest(stats));
                   System.out.println("The total is : "+getTotal(stats));
                   System.out.printf("The average is : %.1f\n",getAvg(stats));
                   System.out.println("Number of A's : "+findLetterGrade(90,100,stats));
                   System.out.println("Number of B's : "+findLetterGrade(80,89,stats));
                   if(findLetterGrade(90,100,stats)==SIZE) {
                       System.out.println("Congradulation, you have a perfect exam score.");
                   }
                   else {
                       System.out.println("Sorry, you DO NOT have a perfect exam score.");
                   }
                   System.out.print("Please enter Y to continue and N to quit: ");
                   ch=sc.nextLine().charAt(0);
                   while(Character.toUpperCase(ch)!='Y' && Character.toUpperCase(ch)!='N') {
                       System.out.print("Please enter Y to continue and N to quit: ");
                       ch=sc.nextLine().charAt(0);
                   }
                }while(Character.toUpperCase(ch)=='Y');
} // end of main method

/**
* This method randomFill fills array with random numbers in the range of 0-100
* @param data array to be filled with random numbers
*/
        public static void randomFill( int[] data ) {
          
           Random rand = new Random();
         
            for( int i = 0; i < data.length; ++i ) {
          
                data[i] = rand.nextInt(101);
              
           }


   } //end randomFill method
        /**
         * This method calculates and returns the total of all values in the array
         * @param data
         * @return total
         */
      
   public static int getTotal(int [] data) {
       int total=0;
       for( int i = 0; i < data.length; ++i ) {
         
          total+= data[i];
         
      }
       return total;
   }
   /**
    * This method returns the average of the values in the array
    * @param data
    * @return avg
    */
   public static double getAvg(int[] data) {
       return (double)getTotal(data)/data.length;
   }
   /**
    * This method finds and returns the largest value in the array
    * @param data
    * @return large
    */
   public static int getLargest(int [] data) {
       int large=data[0];
       for( int i = 1; i < data.length; ++i ) {
           if(large<data[i]) {
               large=data[i];
           }
       }
       return large;
   }
   /**
    * This method finds and returns the smallest value in the array
    * @param data
    * @return small
    */
   public static int getSmallest(int [] data) {
       int small=data[0];
       for( int i = 1; i < data.length; ++i ) {
           if(small>data[i]) {
               small=data[i];
           }
       }
       return small;
   }
   /**
    * The method counts and returns the number of values between the given range inclusive.
    * @param lowRange
    * @param highRange
    * @param data
    * @return cnt
    */
   public static int findLetterGrade(int lowRange, int highRange, int data []) {
       int cnt=0;
       for( int i = 0; i < data.length; ++i ) {
           if(data[i]>=lowRange && data[i]<=highRange) {
               cnt++;
           }
       }
       return cnt;
   }
   /**
    * This method returns true if the array contains someNumber , return false otherwise.
    * @param someNumber
    * @param data
    * @return true/false
    */
   public static boolean isNumberFound(int someNumber, int data []) {
       for( int i = 0; i < data.length; ++i ) {
           if(data[i]==someNumber) {
               return true;
           }
       }
       return false;
   }
   /**
    * This method displays the array with index in [ ] as shown in the given output.
    * @param data
    */
   public static void displayData(int[] data) {
       System.out.println("Exam Scores\r\n-----------");
       for( int i = 0; i < data.length; ++i ) {
           System.out.println("["+i+"] "+data[i]);
       }
   }

} //end of StatsArray Class

----------------------------------------------------------------

Output

Exam Scores
-----------
[0] 19
[1] 73
[2] 37
[3] 61
[4] 81
[5] 35
[6] 10
[7] 12
[8] 89
[9] 78
The minimum value : 10
The maximum value : 89
The total is : 495
The average is : 49.5
Number of A's : 0
Number of B's : 2
Sorry, you DO NOT have a perfect exam score.
Please enter Y to continue and N to quit: y
Exam Scores
-----------
[0] 23
[1] 52
[2] 29
[3] 49
[4] 4
[5] 1
[6] 11
[7] 6
[8] 47
[9] 14
The minimum value : 1
The maximum value : 52
The total is : 236
The average is : 23.6
Number of A's : 0
Number of B's : 0
Sorry, you DO NOT have a perfect exam score.
Please enter Y to continue and N to quit: n

Add a comment
Know the answer?
Add Answer to:
Write a program that instantiates an array of integers named scores. Let the size of the...
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
  • In Java* ​​​​​​​ Write a program that reads an arbitrary number of 20 integers that are...

    In Java* ​​​​​​​ Write a program that reads an arbitrary number of 20 integers that are in the range 0 to 100 inclusive. The program will ask a user to re-enter an integer if the user inputs a number outside of that range. The inputted integers must then be stored in a single dimensional array of size 20. Please create 3 methods: 1. Write a method public static int countEven(int[] inputArray) The method counts how many even numbers are in...

  • TestScores . SIZE: int //size of the array scores: int [ 1 estScores findMax ( )...

    TestScores . SIZE: int //size of the array scores: int [ 1 estScores findMax ( ) : int findMin ) int findScore (value: int): bool res(): int Write the constructor method. It fills the array with random number from 0-100. Find below the code to get your started 1. public TestScores () Random rand -new Random); for (int i-0 i<SIZE i+) socresi] -rand.nextInt (101); Finding the maximum value in an array. Write the method findMax. It returns the maximum value...

  • JAVA HELP: Directions Write a program that will create an array of random numbers and output...

    JAVA HELP: Directions Write a program that will create an array of random numbers and output the values. Then output the values in the array backwards. Here is my code, I am having a problem with the second method. import java.util.Scanner; import java.util.Random; public class ArrayBackwards { public static void main(String[] args) { genrate(); print(); } public static void generate() { Scanner scanner = new Scanner(System.in);    System.out.println("Seed:"); int seed = scanner.nextInt();    System.out.println("Length"); int length = scanner.nextInt(); Random random...

  • 14.8 Prog 8 Overload methods (find avg) Write a program to find the average of a...

    14.8 Prog 8 Overload methods (find avg) Write a program to find the average of a set numbers (assume that the numbers in the set is less than 20) using overload methods. The program first prompts the user to enter a character; if the character is 'I' or 'i', then invokes the appropriate methods to process integer data set; if the character is 'R' or 'r', then invokes the appropriate methods to process real number data set; if the inputted...

  • LAB: How many negative numbers Write a program that generates a list of integers, and outputs...

    LAB: How many negative numbers Write a program that generates a list of integers, and outputs those integers, and then prints the number of negative elements. Create a method (static void fillArray(int [] array)) that uses Random to generate 50 values (Random.nextInt()), put each value in the array (make sure to pass the array in to this method as an argument). Write another method (static int printAndCountNeg(int [] array)) that prints each element’s value and count the number of negative...

  • JAVA 1.Write a static method named getMaxEven(numbers) which takes an array of positive integers as a...

    JAVA 1.Write a static method named getMaxEven(numbers) which takes an array of positive integers as a parameter. This method calculates and returns the largest even number in the list. If there are no even numbers in the array, the method should return 0. You can assume that the array is not empty. For example: Test Result int[] values = {1, 4, 5, 9}; System.out.println(getMaxEven(values)); 4 System.out.println(getMaxEven(new int[]{1, 3, 5, 9})); 0 public static int --------------------------------------------------------------------------------- 2. Write a static method...

  • Create a program named IntegerFacts whose Main() method declares an array of 10 integers. Call a...

    Create a program named IntegerFacts whose Main() method declares an array of 10 integers. Call a method named FillArray to interactively fill the array with any number of values up to 10 or until a sentinel value (999) is entered. If an entry is not an integer, reprompt the user. Call a second method named Statistics that accepts out parameters for the highest value in the array, lowest value in the array, sum of the values in the array, and...

  • In Java Please Create A Program For The Following; Please Note: This program should be able...

    In Java Please Create A Program For The Following; Please Note: This program should be able accept changes to the values of constants ROWS and COLS when testing the codes. Switch2DRows Given a 2D array with ROWS rows and COLS columns of random numbers 0-9, re-order the rows such that the row with the highest row sum is switched with the first row. You can assume that 2D arrau represents a rectangular matrix (i.e. it is not ragged). Sample run:...

  • In Java Write a program that reads an arbitrary number of 25 integers that are positive...

    In Java Write a program that reads an arbitrary number of 25 integers that are positive and even. The program will ask the user to re-enter an integer if the user inputs a number that is odd or negative or zero. The inputted integers must then be stored in a two dimensional array of size 5 x 5. Please create 3 methods: 1. Write a method public static int sum2DArray( int [1] inputArray ) The method sums up all elements...

  • For the following C# program: Let’s add one more user defined method to the program. This...

    For the following C# program: Let’s add one more user defined method to the program. This method, called ReverseDump is to output the values in the array in revere order (please note that you are NOT to use the Array.Reverse method from the Array class). The approach is quite simple: your ReverseDump method will look very similar to the Dump method with the exception that the for loop will count backwards from num 1 to 0 . The method header...

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