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,...

  • Write a class named TestScores. The class constructor should accept an array test scores as its...

    Write a class named TestScores. The class constructor should accept an array test scores as its argument. The class should a method that returns the average of the test scores. If any test score is negative or greater than 100, the class should throw an IllegalArgumentException. Demonstrate this with an array of five items. This is JAVA program.

  • 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...

  • Write a class named TestScores. The class constructor should accept an array of test scores as...

    Write a class named TestScores. The class constructor should accept an array of test scores as its argument. The class should have a method that returns the average of the test scores. If any test score in the array is negative or greater than 100, the class should throw an IllegalArgumentException. Demonstrate the class in a program (create a Driver class in the same file). The program should ask the user to input the number of test scores to be...

  • 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...

  • Replace the fixed size array with a dynamic array Add a constructor that passes the size...

    Replace the fixed size array with a dynamic array Add a constructor that passes the size of the array as a parameter Add a function that copies a dynamic array parameter into this array. Add a copy constructor to intArray Add a function that displays the array to a arbitrary stream Derive intSortedArray from intArray Add functions that enter elements into the array in sorted order Override any base class functions that insert elements out of order. *Note: I NEED...

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