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
How to play music out of your apple watch?
Travka [436]
It does not work that way....I thought the same thing. The sound will always come out of your iPhone
6 0
3 years ago
Identifying the problem is crucial when trying to solve a problem. There are several techniques that you can use to aide you in
erica [24]
Consensus Building is NOT a technique that you can use to help you in identifying a problem.
8 0
3 years ago
The WAN connections to your regional offices are unfortunately extremely slow for your users and they are complaining about file
Zanzabum

Answer: (B) Branch cache

Explanation:

  The branch cache is the process of cache the data from the given file and the wen server on the wide area network. In the WAN connection, the branch code is the type of functionality which basically allow the window to providing the remote user support in the network. The branch cache basically work on the two mode that are:

  • The distributed mode
  • The host mode

The branch cache is the one of the technology that intend the cache data for reducing the network traffic in the wide are network.

Therefore, Option (B) is correct.

5 0
3 years ago
Assuming that all of the table and column names are spelled correctly, what's wrong with the INSERT statement that follows?
Whitepunk [10]

Answer:

C. The number of items in the column list doesn't match the number in the VALUES list.

Explanation:

The INSERT INTO statement is used to insert new records in a table.

<u>Syntax is as follows:</u>

INSERT INTO table_name (column1, column2, column3, ...)

VALUES (value1, value2, value3, ...);

Each column item has to match with the values to be inserted in the same order.

In the question, there are 8 column items specified whereas there are only 7 values given to be inserted.

3 0
3 years ago
Write a program that helps a young student learn to make change. Use the random number generator to generate change amounts betw
erastovalidia [21]

Answer:

#include <iostream>

#include <stdlib.h>

using namespace std;

int main()

{

srand(time(0));

 

int coins = rand()%99 + 1;

int temp = coins;

cout<<"Enter the coins needed to make $0."<<coins<<"?"<<endl<<endl;

int a, b, c, d;

cout<<"Quarters? ";

cin>>a;

cout<<"Dimes? ";

cin>>b;

cout<<"Nickles? ";

cin>>c;

cout<<"Pennies? ";

cin>>d;

 

int quarters = coins/25;

 

coins = coins%25;

 

int dimes = coins/10;

 

coins = coins%10;

 

int nickles = coins/5;

coins = coins%5;

 

int pennies = coins/1;

 

if(((a*25) + (b*10) + (c*5) + (d*1))==temp)

{

cout<<"That's correct"<<endl;

 

if(a!=quarters || b!=dimes || c!=nickles || d!=pennies)

{

cout<<"The optimized solution is "<<endl;

}

}

else

{

cout<<"Not correct"<<endl;

cout<<"The solution is "<<endl;

 

}

 

cout<<"\tQuarters: "<<quarters<<endl;

cout<<"\tDimes: "<<dimes<<endl;

cout<<"\tNickles: "<<nickles<<endl;

cout<<"\tPennies: "<<pennies<<endl;

return 0;

}#include <iostream>

#include <stdlib.h>

using namespace std;

int main()

{

srand(time(0));

 

int coins = rand()%99 + 1;

int temp = coins;

cout<<"Enter the coins needed to make $0."<<coins<<"?"<<endl<<endl;

int a, b, c, d;

cout<<"Quarters? ";

cin>>a;

cout<<"Dimes? ";

cin>>b;

cout<<"Nickles? ";

cin>>c;

cout<<"Pennies? ";

cin>>d;

 

int quarters = coins/25;

 

coins = coins%25;

 

int dimes = coins/10;

 

coins = coins%10;

 

int nickles = coins/5;

coins = coins%5;

 

int pennies = coins/1;

 

if(((a*25) + (b*10) + (c*5) + (d*1))==temp)

{

cout<<"That's correct"<<endl;

 

if(a!=quarters || b!=dimes || c!=nickles || d!=pennies)

{

cout<<"The optimized solution is "<<endl;

}

}

else

{

cout<<"Not correct"<<endl;

cout<<"The solution is "<<endl;

 

}

 

cout<<"\tQuarters: "<<quarters<<endl;

cout<<"\tDimes: "<<dimes<<endl;

cout<<"\tNickles: "<<nickles<<endl;

cout<<"\tPennies: "<<pennies<<endl;

return 0;

}

Explanation:

  • Use the built-in rand function to generate a random coin.
  • Get all the required values for quarters, dimes, nickles and pennies and store them in variables.
  • Check if the coins give a value of temp, then answer is correct and the values of user will be added.
  • Optimum solution is displayed  If it does not matches with the optimum solution. Display that the answer is wrong along with solution.
6 0
2 years ago
Other questions:
  • A computer’s memory is composed of 8K words of 32 bits each. How many bits are required for memory addressing if the smallest ad
    10·1 answer
  • _____ separation strategies (e.g., attacking and sabotaging others) are used by those for whom co-cultural segregation is an imp
    5·1 answer
  • How can you efficiently restrict the read-only function of a requesting SNMP management station based on the IP address?
    14·1 answer
  • Quiz
    6·2 answers
  • Lucy has to move data from column A to column N in a worksheet. Which keys should she select to move data in the same worksheet?
    9·2 answers
  • An organization's Finance Director is convinced special malware is responsible for targeting and infecting the finance departmen
    13·1 answer
  • Write a program in qbasic to accept a character and check it is vowel or consonant​
    14·1 answer
  • Which online note-taking device allows students to clip a page from a website and reuse it later?
    13·2 answers
  • What is the role of computer in education sector?​
    13·1 answer
  • Use the drop-down menus to complete the statements about Search Folders.
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!