Question

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

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

Java code

============================================================================================

package sat;

import java.util.*;

public class TestScores {
   int SIZE=10;
   int []scores;
  

   public TestScores() {
       Random rand=new Random();
       scores =new int[SIZE];
       for(int i=0;i<SIZE;i++)
       {
           scores[i]=rand.nextInt(101);
       }
   }
   int findMax()
   {
       int max=scores[0];
  
       int i;
       for(i=1;i<scores.length;i++)
       {
           if(max<scores[i])
           {
               max=scores[i];
           }
       }
      
       return max;
   }
  
   int findMin()
   {
       int min=scores[0];
  
   int i;
   for(i=1;i<scores.length;i++)
   {
       if(min>scores[i])
       {
           min=scores[i];
       }
   }
  
   return min;
      
   }
  
   int countScores()
   {
       int sum=0;
       for(int i=0;i<scores.length;i++)
       {
           if(scores[i]>=90)
               sum++;
       }
       return sum;
   }
   boolean findScore(int key)
   {
       boolean b=false;
       for(int i=0;i<scores.length;i++)
       {
           if(scores[i]==key)
           {
               b=true;
               break;
           }
       }
       return b;
   }

   public static void main(String[] args) {
       // TODO Auto-generated method stub
       Scanner sc=new Scanner(System.in);
       //System.out.print("Enter number of elements in array: ");
       //SIZE=sc.nextInt();
       TestScores ob=new TestScores();
       System.out.println("maximum value is: "+ob.findMax());
       System.out.println("minimum value is: "+ob.findMin());
       System.out.println("Number of exams whoes score is greater or equal to 90 is: "+ob.countScores());
       System.out.println("Enter value to search: ");
       int k=sc.nextInt();
       if(ob.findScore(k))
       {
           System.out.println(k+" found in the array");
       }
       else
       {
           System.out.println(k+" not found in the array");
       }
   }
  

}

============================================================================================

Output

Java sat/src/sat/Testscoresjawa - Eclipse Eile Edit Source Refattor Navigate Search Project Run岦indow Help 0 k Access Java 초

Add a comment
Know the answer?
Add Answer to:
TestScores . SIZE: int //size of the array scores: int [ 1 estScores findMax ( )...
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
  • 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...

  • a. Write a function named findmax() that finds and displays the maximum values in a two...

    a. Write a function named findmax() that finds and displays the maximum values in a two dimensional array of integers. The array should be declared as a 10 row by 20 column array of integers in main() and populated with random numbers between 0 and 100. b. Modify the function written above so that it also displays the row and column numbers of the element with the maximum value. I have this so far, and but it's only finding the...

  • Problem 1 1. Consider the following function (K is the size of array A and L...

    Problem 1 1. Consider the following function (K is the size of array A and L is the size of array B) bool func (int A[], int K, int B[], int L, int start) { if (L > K-start) return false; for (int i =0; i < L; i++) { if(A[start+i] != B[i]) return false } return true; } What are the input and output variables to this function. Trace it for the following call: int F[] = {1, 3,...

  • 1. Write a complete program based on public static int lastIndexOf (int[] array, int value) {...

    1. Write a complete program based on public static int lastIndexOf (int[] array, int value) { for (int i = array.length - 1; i >= 0; i--) { if (array [i] == value) { return i; } } return -1; write a method called lastindexof that accepts an array of integers and an integer value as its parameters and returns the last index at which the value occurs in the array. the method should return -1 if the value is...

  • In class Recursion problems bool anyNegative(int al , int size) This function returns true if there...

    In class Recursion problems bool anyNegative(int al , int size) This function returns true if there are any negative numbers in the array, grity false otherwise. int firstNegative(int al I, int size) This function returns the position of the first negative number in the array & EAO If there are no negative numbers it returns int countNegative(int al I, int size) This function returns the number of negative numbers in the array a. 12 bst Stringsint indexO bout Strings nt...

  • Hello, I need a c program called int* create_random_array(int n) that returns a random array of...

    Hello, I need a c program called int* create_random_array(int n) that returns a random array of size an. Alternatively, you can initialize a pointer to an array (called Rand) and write a function called void(create_array(int * Rand, int n) which assigns an array of size n to Rand. Note: Plese utilize rand(fi) and srand() from stdlib.h for this code

  • Q.1. Create a C++ class template called ArrayCalc, to perform a series of mathematical operations on...

    Q.1. Create a C++ class template called ArrayCalc, to perform a series of mathematical operations on an array. These mathematical operations are calculating the minimum, maximum, sum and average values of the array. The ArrayCalc class template accepts one type parameter, which can be defined as: template <class T>. This allows ArrayCalc to carry out operations for different array data types. ArrayCalc has the following public methods, described here in pseudo code: i. void FindMin(inArrayData[], inArraySize, SoutMinVal); (This function accepts...

  • howthe   output   of   the   following   4   program segments (a)    const int SIZE=8;    int values[SIZE]...

    howthe   output   of   the   following   4   program segments (a)    const int SIZE=8;    int values[SIZE] = {10, 10, 14, 16, 6, 25, 5, 8};    int index;    index=0;    res = values[index];    for (int j=1; j<SIZE; j++)    {        if (values[j] > res)        {            res = values[j];            index = j;        cout << index << res << endl;        }    }    cout <<...

  • . In the method main, prompt the user for a non-negative integer and store it in...

    . In the method main, prompt the user for a non-negative integer and store it in an int variable num (Data validation is not required for the lab). Create an int array whose size equals num+10. Initialize the array with random integers between 0 and 50 (including 0 and excluding 50). Hint: See Topic 4 Decision Structures and File IO slides page 42 for how to generate a random integer between 0 (inclusive) and bound (exclusive) by using bound in...

  • In C++ Write a function int * return_matches(int a[], int & size,TEST t) which returns an...

    In C++ Write a function int * return_matches(int a[], int & size,TEST t) which returns an array (allocated off of the heap in the function) containing only the elements of array a that pass the “test” t. The function iterates through all the elements of a, and constructs a new array containing all the elements that pass the test. When the parameter corresponding to “size” is passed in (by reference), it contains the size of the array a. In the...

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