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.

Answers

Answer 1

import java.util.Arrays;

public class TestScores {

   public static float getAverage(float arr[]){

       float total = 0;

       for (float x : arr){

           if (x < 0 || x > 100){

               throw new IllegalArgumentException();

           }

           else{

               total += x;

           }

           

       }

       return (total / arr.length);

   }

   

   public static void main(String [] args){

       float arr[] = {1,100,0,43,-1};

       System.out.println(getAverage(arr));

   }

}

In the main method we test our getAverage method with the arr array. You can replace the values in the arr array and test your own values. I hope this helps!

Answer 2

The code example of the implementation of the TestScores class in Java is shown below:

What is the class?

java

import java.util.Arrays;

public class TestScores {

   private int[] scores;

   public TestScores(int[] scores) {

       this.scores = scores;

   }

   public double getAverage() {

       int sum = 0;

       for (int score : scores) {

           if (score < 0 || score > 100) {

               throw new IllegalArgumentException("Invalid test score: " + score);

           }

           sum += score;

       }

       return (double) sum / scores.length;

   }

   public static void main(String[] args) {

       int[] scores = {85, 90, 92, 88, 95};

       TestScores testScores = new TestScores(scores);

       try {

           double average = testScores.getAverage();

           System.out.println("Average test score: " + average);

       } catch (IllegalArgumentException e) {

           System.out.println("Error: " + e.getMessage());

       }

   }

}

Read more about  class  here:

https://brainly.com/question/26580965

#SPJ2


Related Questions

A technology-literate knowledge worker: A. knows how and when to apply technology B. is a computer savvy worker C. knows all computer programming languages D. is knowledgeable about emerging technology

Answers

Answer:

A. knows how and when to apply technology

Explanation:

Technology can be defined as a branch of knowledge which typically involves the process of applying, creating and managing practical or scientific knowledge to solve problems and improve human life. Technologies are applied to many fields in the world such as medicine, information technology, cybersecurity, engineering, environmental etc.

A technology-literate knowledge worker knows how and when to apply technology. This ultimately implies that, someone who is well grounded or informed about a technology understands how and when to apply technology.

Basically, knowing how to use a technology simply means he or she understands the appropriate method or technique to be used in the application of a technology such as when solving a problem. Also, knowing when to use a technology means to know the appropriate time to use a particular technology without it having any repercussion or adverse effect.

Answer:

A

Explanation:

Think about it like this:

A literate person in writing doesn't just know letters, they know how to put them together. Now put that in terms of computers.

Given this instruction mix and the assumption that an arithmetic instruction requires 2 cycles, a load/store instruction takes 6 cycles, and a branch instruction takes 3 cycles, find the average CPI.

Answers

Answer:

2.6

Explanation:

I am assuming that for any given program, that 70% of it's executed instructions happen to be arithmetic, another 10% happen to be load/store, and finally, a 20% happen to be branch. If so, then I can say

Average CPI =

3Σi=1 Percentage of instructions * CPI

Average CPI = (0.7 * 2) + (0.1 * 6) + (0.2 * 3)

Average CPI = 1.4 + 0.6 + 0.6

Average CPI = 2.6

Python uses sequencing to
A) allow the code to run faster
B) carryt out a series of steps
C) let the computer pick the order of the steps
D) make the code easier to read
plz help this is exammmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm

Answers

Answer:

B: Carry out a series of steps

Explanation:

Sequences is a general term for ordered sets. It tells in a set order what the program needs to do

PogChamp

Answer:

b

Explanation:

In Python
Write a constructor with parameters self, num_mins and num_messages. num_mins and num_messages should have a default value of 0.

Sample output with one plan created with input: 200 300, one plan created with no input, and one plan created with input: 500
My plan... Mins: 200 Messages: 300
Dad's plan... Mins: 0 Messages: 0
Mom's plan... Mins: 500 Messages: 0

Answers

class Messaging:

   txt = ""

   first = 0

   second = 0

   def __init__(self, num_mins=0, num_messages=0):

       self.txt = input("Who's plan is this? ")

       self.first = num_mins

       self.second = num_messages

   def print_Something(self):

       print(f"{self.txt} Mins: {self.first} Messages: {self.second}")

obj = Messaging(100, 100)

obj.print_Something()

If you want to change what's printed to the console, just manipulate the values in Messaging(). Leave them blank for 0.

A computer program checks to see if the user of a software program has clicked on a photo. This is an example of a requirement that can be evaluated in
a string statement.
a goto statement.
a global statement.
a conditional statement.

Answers

Answer:

A conditional statement

Explanation:

I just took the review and got it right

Answer:

A conditional statement

Explanation:

I took the test

A computer provides each process with 65,536 bytes of physical address space divided into page-frames of 4096 bytes. A particular program has a text size of 32,768 bytes, a data size of 16,386 bytes, and a stack size of 15,870 bytes. Will this program fit in the address space?

Answers

Answer:

No, we require 17 pages but we have only 16 pages available

Explanation:

As computer provide allocated address space is 65,536 which is 2∧16 bytes and page size is 4096 bytes which is 2^12 bytes.

Therefore, the number that can be formed with each 4096 bytes are 16 pages (2^16 / 2^12 = 2^4).

That program text size is 32,768 bytes which is equal to 8 pages (32768/4096 = 8).

The data of the program require 16386 bytes which is equal to 5 pages (16386/4096 = 4.005) and the stack of that program require 4 pages (15870/4096 = 3.875).

Therefore, the program requires 17 pages but have only 16 pages that's why it doesn't fit in address space.

Write the HTML code to make the text "Learn Magic" link to a page called "magic-tricks.html”.

Answers

Answer:

The answer to this question is given below in the explanation section.

Explanation:

The below code is written in HTML

************************************************************************************************

 <!DOCTYPE html>

<!--html start from here and this is comment line -->

<html lang="en-US">  

<body> <!--html body start from here -->

<!-- a link attribute is given below that links another file (magic-tricks)  in the same folder -->  

<p><a href="magic-tricks.html">Learn Magic</a></p>

</body><!--html body end at here -->

</html>

<!--html end at here and this is comment line -->

*************************************************************************************************

When you run this code, it is neccessary     for you to create another html file in same folder and named it "magic-tricks". When you will run the code into any browser and link "learn magic" will appear, as you will click on it "magic-tricks.html" file will get open.

     

write a C recursion function that can determine if a given number is a prime number. Must use recursion. g

Answers

A number is classified as a prime if it is greater than one and is divisible only by one and by itself. Only natural numbers are classified as prime. Before knowing more about the prime number, it is important to remember some rules of divisibility, which help in the identification of which numbers are not prime.

Code:

#include <stdio.h>

int prime_number(int, int);  

int main()

{

   int num, tmp;

   printf("Input any integer number: ");

   scanf("%d", &num);

   tmp = prime_number(num, num / 2);

   if (tmp == 1)

   {

       printf("%d is a prime number\n", num);

   }

   else

   {

       printf("%d is not a prime number\n", num);

   }

   return 0;

}

 

int prime_number(int num, int i)

{

   if (i == 1)

   {

       return 1;

   }

   else

   {

      if (num % i == 0)

      {

        return 0;

      }

      else

      {

        return prime_number(num, i - 1);

      }        

   }

}

Write a program that asks the user for a string of lowercase letters and numbers. The program should evaluate the string and report the number of vowels ('a', 'e', 'i', 'o', 'u') and numbers ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9') in the string.

Answers

Answer:

Follows are the code to this question:

def vowel(x):#defining a method vowel that accept a parameter

   return(x=='a' or x=='e' or x=='i' or x=='o' or x=='u')#return char value

def number(x):#defining a method number that accept a parameter

   return(x=='0' or x=='1' or x=='2' or x=='3' or x=='4' or x=='5' or x=='6' or x=='7' or x=='8' or x=='9')#return number value

def main():#defining main method

   s=input("Enter a string: ")#defining string variable

   v=0#defining integer variable

   n=0#defining integer variable

   for f in s:#defining for loop for count value

       if vowel(f):#defining if to check vowel

           v=v+1#count vowel value

       elif number(f):#defining elif for count number

           n=n+1#count number value

   print("Total vowels: ",v)#print vowels value

   print("Total numbers: ",n)#print numbers value

main()

Output:

Enter a string: 678qeaft

Total vowels:  2

Total numbers:  3

Explanation:

In the above program code, three methods, "vowel, number and main" is defined, in which "vowel and number" accept an x variable in its parameter and return a value with their respective name.

Inside the main method a string variable "s" is defined that accepts a string value and defines an "n and v" integer variable, and in the for loop, it calls the above methods to use the integer variable to count string and number value and print its calculated value.

4. What is the output of the following code snippet? void prevnext(int a, int& prv, int nxt) { prv = a - 1; nxt = a + 1; } int main() { int a = 100; int b = 0;

Answers

Answer:

Previous = 99, Next = 101

Explanation:

Given that a = 100

Previous says that it's formula is a - 1, where a = 100.

Therefore, previous code would show in its output as 100 - 1. 100 - 1 = 99.

Thus, the output of previous code will be 99

Like with previous, Next says that it's formula is a + 1, where a = 100.

Therefore, the next code would show in its output as 100 + 1. 100 + 1 = 101

Thus, the output of previous code will be 101

I hope that's explanatory enough. Thanks.

What is a ribbon or ribbions in Microsoft Word?

Answers

A set of toolbars at the top of the window. Design to help you quickly find the commands.
A set of toolbar at the top of the window.

Write a program that computes value of the following arithmetic expression for values of x and y entered by the user: 5.4xy - 12.3y 18.23x - 8.23

Answers

Answer:

Explanation:

The following code is written in Java and first asks the user to enter the values for X and Y, it then saves those values in two different variables and uses them in the arithmetic expression given in the question and solves it. The answer is saved to the variable named result and displayed on the window.

class brainly{

   public static void main(String[] args)

       {

           Scanner in = new Scanner(System.in);

           System.out.println("Enter value for x");

           double valueX = in.nextDouble();

           System.out.println("Enter value for y");

           double valueY = in.nextDouble();

           double result = (5.4 * valueX * valueY) - (12.3 * valueY * 18.23 * valueX) - 8.23;

           System.out.println(result);

       }

   }

Write a Python function to get the first half of a specified string of even length. Suppose the input string is "Python" ,after calling the function, we should see the output "Pyt"

Answers

In python:

def get_even(txt):

   return txt[0:int((len(txt) / 2))]

We can test our function with the following code:

print(get_even("Python")) This returns "Pyt" in the console.

I hope this helps!

Answer:

c

Explanation:

Please define identity theft

Answers

the action or crime of stealing.

Answer:

Identity theft is the deliberate use of someone else's identity, usually as a method to gain a financial advantage or obtain credit and other benefits in the other person's name, and perhaps to the other person's disadvantage or loss

Explanation:

Question #4
Multiple Select
Which of the following statements are true regarding abstraction? Select 3 options.

O Creating a model must occur before abstraction.

O Refinement is the opposite of abstraction.

O Abstraction provides a way to see a complex situation more clearly.

O The level of abstraction needed depends on the situation and your goals.

O Abstraction is a process where details are added to further define the problem.

Answers

Answer:

B: the level of abstraction needed depends on the situation and your goals

C: refinement is the oppostie of abstraction

E: abstraction provides a way to see a complex situtation more clearly

Explanation:

I just completed the assignemnet and was checking it while I made this answer.

Which type of programming language translates all lines of code together and then executes them at once?

Compiled
Interpreted
Machine
Python

Answers

Answer:

Compiled

Explanation:

Doors and windows are important compositional elements that impact the facade of a building True False​

Answers

Answer:

true

Explanation:

Consider a 16 GByte memory (16G locations each holding one byte). What is the number of address lines (N)?

Answers

Answer:

Number of address lines (N) = 34

Explanation:

16G locations each holding 1 byte

           byte

1g    1 - 1 - 1 - 1 - 1 - 1 - 1 - 1

2g

3g

.

.

.

16g

note that; 1 byte = 8 bit

therefore for 16G location, address line(N) will be:

since it is known that [tex]2^{N}[/tex] = 16G   ,and   1 gigabyte = [tex]2^{30}[/tex] byte

∴ 16G = 16 × [tex]2^{30}[/tex]

          = 2⁴ × 2³⁰

          = 2³⁴

since [tex]2^{N}[/tex] = 16G

∴    [tex]2^{N}[/tex] = 2³⁴

N = 34

Which arithmetic operation is used by a signed binary comparator to determine if two operands are equal

Answers

Answer:

Equality Operators

Explanation:

The equality operators, which are often written as "equal (==), and not-equal (!=)" are technically used by a signed binary comparator to determine if two operands are equal or not equal. They produce 1 in a situation where both operands have equal value, and 0 if they do not have equal value.

Hence, in this case, the correct answer is Equality Operators.

Which type of evidence should victims collect to help officials catch cyber bullies ?

-home addresses
-birthdays
-social media
-usernames user
-passwords

Answers

Answer:

Social media

Explanation:

Social media and usernames user so that they can find them without any problem : D

8. Write a function that takes a 2D array as an input and outputs all values greater than 20 into a column array. Use logical indexing array

Answers

Answer:

Follows are the code to this question:

#include<stdio.h>//defining header file

int main()//defining main method

{

  int d[2][2];//defining 2D array

  int i, j;//defining integer variable

  printf("Enter values: \n");//print message

  for(i=0; i<2; i++)//defining for loop for input column value

  {

     for(j=0;j<2;j++)//defining for loop for input row value  

     {

        scanf("%d", &d[i][j]);//input values

     }

  }

  printf("value which is greater than 20: \n ");//print message

  for(i=0; i<2; i++)//defining for loop for print  column value  

  {

     for(j=0;j<2;j++)//defining for loop for print row value

     {

         if(d[i][j]>20)//defining if block that check value is greater then 20

         {

              printf("%d ", d[i][j]);//print values

         }

      }

     printf("\n");//use print for line break

  }

  return 0;

}

Output:

Enter values:  

44

12

11

55

value which is greater than 20:  

44  

55  

Explanation:

In the above-given code, a 2D array "d" and two integer variable "i and j" are defined, in which two for loop are used for input value from the user end.

After accepting the value from the user end, and again use the two for loop, in which, if block is defined, that checks array value is greater than 20 and print its values.

Write a function password_check() that takes as input two strings newpassword and oldpassword, and accepts the new password (i.e., returns True) if newpassword is different from oldpassword and newpassword is at least 6 letters long. If the new password fails the check, your functions should return False

Answers

In python:

def password_check(newpassword, oldpassword):

   return True if newpassword != oldpassword and len(newpassword) >= 6 else False

Just for clarification, that return statement is on one line. I hope this helps!

Some systems automatically delete all user files when a user logs off or a job terminates, unless the user explicitly requests that they be kept. Other systems keep all files unless the user explicitly deletes them. Discuss the relative merits of each approach.

Answers

Answer:

Follows are the Scenario to this question:

Explanation:

Scenario 1:

Removing files trying to follow patient problems is effectively preserving a lot of bandwidth unless defined. Because the device doesn't allow unnecessary data to also be saved, and All system storage is also protected.

Its system efficiency also is increased as its device erases data which are not needed around the same time.

Scenario 2:

It is possible that its consumer unintentionally keeps forgetting to save information, and in that case, the user may lose a lot. Everything is therefore deleted before ensuring its customer.

Its machine may also be closed down due to varying any or even all model calibration, so that storage capacity helps to restore as the backup is still preserved.

PLEASE HURRY!!!
Look at the image below!

Answers

The value of category will be normal because the if statement is false and the first elif statement is false but the second elif statement is true.

Assistive Technologies: You have just purchased a new computer and, because of a visual impairment, you are having trouble reading the information on the screen. What are your next steps

Answers

Answer:

The definition has been mentioned below and according to the situation described.

Explanation:

If you already have recently purchased a new device and also have a visual disability condition, you increasing considering utilizing a few available assistive resources, such as screen readers, magnifiers, huge-print keyboards, as well as applications and resources for navigating assistance.  These resources are explicitly available for those instances often come pre-installed in a device window throughout today's context.

what are the commonly used computer categories.

Answers

Answer:

PCs (Personal Computers) with Microsoft Windows

Explanation:

i used google. hope this helped!!!

PLEASE HURRY!!!
Look at the image below!

Answers

Answer:

If the user enters 162.5, the output will be 162.5

Explanation:

Please click thanks button hun

Data mining is an integral part of knowledge discovery in database (KDD), which is the overall process of converting ____ into _____. a. primary data / secondary data b. input data / output data c. raw data / useful information d. input data / data fusion

Answers

Answer:

c. raw data / useful information

Explanation:

Data mining can be described as the cat of converting raw data into useful information.

In simple terms it can be defined as the process of extracting usable data from a much larger set or data(raw). This is done through the use of various softwares that support the process.

Through data mining patterns, anomalies, correlations etc are found in the data which is then used in the prediction of likely outcomes.

Which physical activity can you perform at the office to avoid strain?
A.
blink your eyes often
B.
cycling
C.
physiotherapy
D.
resting for long hours

Answers

D. Because otherwise you work yourself overtime which is unhealthy for the body :D

Answer:

ill say eyes because straining your eyes hurts so a

Explanation:

Lauren and her parents reviewed the lesson information on how to stay safe online. When Lauren told her parents that she had been using the password "Computer1” for all of her online accounts, her mother suggested that she change it.

Why did Lauren’s mother suggest she change her password?

It could be easily guessed.
It contained personal information.
It contained only one number.
It contained too many letters.

Answers

it could be easily guessed , the first one

Answer:

A): it could easily be guessed

Explanation:

I got it right thanks to the other person! give them brainiest, please!

Other Questions
"How does the INTERNETwork? O CelluarO ip AdressO Twisted PairO Fiber OpticO Server stion 1/2 Which of the following is a physical property?A. The boiling point o a certain alcohol is 78 degrees CelsiusB. Diamond is very hardC. Sugar ferments to form alcoholD. A metal wire conducts an electric current NEED HELP! Will give brainest! You dont have to answer all the questions just the ones you know What was President Kennedy's reason for initiating U.S. military involvement in Vietnam? (4 points)Group of answer choicesto stop North Vietnam from spreading communism to Laos, Cambodia, and Thailandto reunify North and South Vietnam as a democratic nationto protect French possessions in Indochinato prevent the Vietcong from overthrowing the South Vietnamese government PLEASE HELP Which of the following is reused many times during photosynthesis? Question 13 options:ATPFADH2 ChlorophyllAll of the above solve 2x^3-23= y when x=1 A 100-g bullet is fired from a rifle having a barrel 0.600 m long. Choose the origin to be at the location where the bullet begins to move. Then the force (in newtons) exerted by the expanding gas on the bullet is 15 000 1 10 000x 2 25 000x 2 , where x is in meters. (a) Determine the work done by the gas on the bullet as the bullet travels the length of the barrel. (b) What If? If the barrel is 1.00 m long, how much work is done, and (c) how does this value compare with the work calculated in part (a)? A bag contains 5 quarters, 2 dimes, and 4 pennies. What is the probability of picking a quarter or a dime? Which sentence uses the verb voice that emphasizes the action rather than the actor?The tango is being taught to the children.The audience laughed at the slapstick comedy.The class sang in a recital for the parents.Lisa knows the results of her test but won't tell us. Find g(3) when g(x)= -2x +3.ur answer 0.725, 1/4, 30% From least to greatest Determine which equation below has a solution of x = 2.A. X + 9 = 14 - 3xB. -4x + 3 = 8x - 21C. 3x - 6 = 2x + 4D. 18x - 32 = -23x 6 David's friend Julie has joined him to go shopping for things for his new apartment. For each sentence, provide theproper form and placement for the adjectives within parentheses.MODLE: David regrette les excursions(ennuyeux, long) -David regrette les longues excursions ennuyeuses.Please help?! Which of the following is not an important component of filling out your fitness log ? PLS HELP! I WILL THE FIRST GOOD ANSWER BRAINLIEST!Imagine inventing a new holiday or celebration. What would you call it? When would it be celebrated? Why would you make it a holiday or a celebration? (1 paragraph) A line has a slope of -3 and a y-intercept of 3.What is the x-intercept of the line? How did the Justinian code make the Byzantine empire more powerful Give the ordered pair coordinate of any point. in quadrant 2 1. The time between arrivals of taxis at a busy intersection is exponentially distributed with a mean of 10 minutes. a. What is the probability that you wait longer than one hour for a taxi Does any absolute value expression with a value of O have more than one solution?Yes, it has more than one solutionNo, it only has one solution.