1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Mamont248 [21]
3 years ago
10

Write an exception class named InvalidTestScore. Modify the TestScores class you wrote in Part I so that it throws an InvalidTes

tScore exception if any of the test scores in the array are invalid. Test your exception in a program (in a subclass located in the same file). Your program should prompt the user to enter the number of test scores, and then ask for each test score individually. Then, it should print the average of test scores. If the average method throws an InvalidTestScore exception, the main method should catch it and print "Invalid test score."
Computers and Technology
1 answer:
Elan Coil [88]3 years ago
8 0

Answer:

See Explaination

Explanation:

package testscores;

import java.util.ArrayList;

import java.util.List;

public class TestScores {

public List<Integer> scorearray=new ArrayList<>();

public TestScores(List<Integer> scores) throws InvalidTestScore{

this.scorearray=scores;

for(int i=0;i<scorearray.size();i++){

if(scorearray.get(i)>100 || scorearray.get(i)<0){

throw new InvalidTestScore(this.scorearray.get(i));

}

}

}

public double average(){

int tot=0;

for(int i=0;i<this.scorearray.size();i++){

tot=tot+this.scorearray.get(i);

}

return tot*(1.0)/(this.scorearray.size());

}

class InvalidTestScore extends Exception

{

private double amount;

public InvalidTestScore(int Score)

{

System.out.println("Invalid Score "+Score);

}

}

}

You might be interested in
In Tynker, it is not possible to create a/an __________.
xz_007 [3.2K]

Answer:

yes

Explanation:

7 0
2 years ago
Read 2 more answers
What are options in the Advanced tab in the Share Workbook dialog box? Check all that apply
madam [21]
Where are the options

7 0
3 years ago
Read 2 more answers
5 of 10
DaniilM [7]

Answer:

what

Explanation:

3 0
2 years ago
Write a method that takes a Regular Polygon as a parameter, sets its number of sides to a random integer between 10 and 20 inclu
Fantom [35]

Answer:

Answered below

Explanation:

//Program is written in Java programming language

Class RegularPolygon{

int sides = 0;

int length = 0;

}

public void randomize(RegularPolygon polygon){

int randomSides = (int) 10 + (Math.random() * 20);

double randomLength = 5 + (Math.random() * 11);

polygon.sides = randomSides;

polygon.length = randomLength;

}

8 0
3 years ago
Write a program that asks the user to input their first and last names. The first prompt should state:
VikaD [51]

first = input("Please input your first name: ")

last = input("Please input your last name: ")

print(last+", "+first)

I hope this helps!

8 0
2 years ago
Other questions:
  • What is the f(n) runtime of the following pseudocode: sum-0 for A = N/2 downto 1 for B-1 t increment sum by B Explain: exactly w
    13·1 answer
  • A machine is classified as a compound machine if it?
    8·2 answers
  • Consists of a drive letter (preceded by a drive name when necessary) and colon, to identify the storage device, and one or more
    5·1 answer
  • Which is considered to be the oldest form of social media? A. media-sharing sites B. location-based services C. social networkin
    5·1 answer
  • Consider the following code segment. for (int a = 0; a &lt; 10; a++) { for (int b = 10; b &gt; a; b--) { System.out.print("#");
    6·1 answer
  • Match the installation type to its description.
    9·1 answer
  • Design a function that checks if a keyword exists in a given keyword tree and returns true if so and returns false otherwise. Af
    13·2 answers
  • Special words are those words that start and end with the same letter. [14]
    12·1 answer
  • What is an operating system? What are the main functions of a modern general purpose operating system?
    7·1 answer
  • 2. Explain the difference between a JMP instruction and CALL instruction
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!