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 counted,
and then each individual test score. It should then make an array
of those scores,
create a TestScore object, and print the average of the
scores.
If an IllegalArgumentException is thrown, the main method should
catch it, print "Test scores must have a value less than 100 and
greater than 0." and terminate the program.
Coding
import java.util.Scanner;
class TestScore {//second class
float avg=0;
TestScore(int num[]) {//constrctor run
for(int i=0; i<num.length;i++)
{
if (num[i] < 0)
{
throw new IllegalArgumentException
("value must be non-negative");
}
if (num[i] >100)
{
throw new IllegalArgumentException
("value must Less than 100");
}
this.avg=this.avg+num[i];
}
this.avg=this.avg/num.length;
}
void TestScore_method() {//display it method
System.out.println(this.avg);
}
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
System.out.println("enter number of elements");
int n=s.nextInt();
int arr[]=new int[n];
System.out.println("enter elements");
for(int i=0;i<n;i++){//for reading array
arr[i]=s.nextInt();
}
TestScore my = new TestScore(arr);//make object of TestScore
my.TestScore_method();//call method TestScore
}
}
if you still have any Problem regarding this question please comment and if you like my code please appreciate me by thumbs up thank you.........
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 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.
--C++-- --spc16-7.cpp-- // Chapter 16, Programming Challenge 7: TestScores class #include <iostream> #include "TestScores.h" #include "NegativeScore.h" using namespace std; int main() { // Constant for the number of test scores const int NUM_SCORES = 5; try { // Create an array of valid scores. int myScores[NUM_SCORES] = { 88, 90, 93, 87, 99 }; // Create a TestScores object. //TestScores myTestScores(myScores, NUM_SCORES); // optional constructor TestScores myTestScores(myScores);...
Write a class named DartSector. The constructor should accept a sector number and position {Single, Double, Treble, Outer & Inner} represented with the integers 1 – 5 respectively. The class should have 3 methods: • getSectorColor – method should return the pocket’s color (as a String) • singleThrow – method should generate 2 random numbers; one in the range (1..20) and another (1..5); and return the score for the throw. • throwThree – method should generate 3 sets of random...
I keep getting an Error after I ask the user for test scores. What is missing? package testscores; import java.util.Scanner; public class TestScores { /** * @param args the command line arguments */ private double[] scores; public TestScores(double[] score) throws IllegalArgumentException { scores = new double[scores.length]; for (int i = 0; i < scores.length; i++) { if (score[i] < 0 || score[i] > 100){ throw new IllegalArgumentException(); } scores[i]=score[i]; } } public double getAverage() { int sum=0;...
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...
REQUIREMENTS: Problem Description: Create a Dynamic 2D Array Class. This class should overload the Call Operator () for the following behaviors: Return (modifiable) Lvalue element for a non-const object Return (read-only) Rvalue element for a const object Return a copy of the data values for row Return a copy of all the data as a 1D vector Create a TestScores Class which uses a Dynamic 2D Array object as an internal data structure. This class should have the following behaviors:...
put everything together in an object-oriented manner! create a class named PositiveNumberStatistics that has the following: A private double 1D array instance variable named numbers. A constructor that takes one parameter, a 1D double array. The constructor should throw an IllegalArgumentException with the message "Array length of zero" if the parameter has a length of 0. If the exception is not thrown, the constructor should create the numbers array and copy every element from the parameter into the numbers instance...
#ifndef STUDENTTESTSCORES_H #define STUDENTTESTSCORES_H #include <string> using namespace std; const double DEFAULT_SCORE = 0.0; class StudentTestScores { private: string studentName; // The student's name double *testScores; // Points to array of test scores int numTestScores; // Number of test scores // Private member function to create an // array of test scores. void createTestScoresArray(int size) { numTestScores = size; testScores = new double[size]; for (int i = 0; i < size; i++) testScores[i] = DEFAULT_SCORE; } public: // Constructor StudentTestScores(string...
Write a complete C++ program that reads students names and their test scores from an input text file. The program should output each student’s name followed by the test scores and the relevant grade in an output text file. It should also find and display on screen the highest/lowest test score and the name of the students having the highest/lowest test score, average and variance of all test scores. Student data obtained from the input text file should be stored...
In C++, please do not google Problem Description: Create a Dynamic 2D Array Class. This class should overload the Call Operator () for the following behaviors: Return (modifiable) Lvalue element for a non-const object Return (read-only) Rvalue element for a const object Return a copy of the data values for row Return a copy of all the data as a 1D vector Create a TestScores Class which uses a Dynamic 2D Array object as an internal data structure. This class...