Question

I keep getting an Error after I ask the user for test scores. What is missing?...

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;
for(int i=0;i<scores.length;i++)
sum+=scores[i];
return sum/scores.length;
}
public static void main(String[] args) {
// TODO code application logic here
Scanner keyboard=new Scanner(System.in);

System.out.println("How many test scores are there?");
int length=keyboard.nextInt();
double scores[]=new double[length];
for(int i=0;i<scores.length;i++){
System.out.println("Enter an test score:");
scores[i]=keyboard.nextDouble();
}

try{
TestScores score=new TestScores(scores);
System.out.println("The Average is: "+ score.getAverage());
}
catch(IllegalArgumentException e){
System.out.println("Invaild:"+e.getMessage());
}
}
}

public class InvaildTestScores extends IllegalArgumentException {
public InvaildTestScores(String error){
super("All the numbers need to be between 0-100 only.");
}
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1
Change statement 
scores = new double[scores.length];
to 
scores = new double[score.length];

Note: Please comment if you have any doubts below บุ。u hau e anu/ doubts

Please up vote the solution if it helped. Thanks!

Add a comment
Know the answer?
Add Answer to:
I keep getting an Error after I ask the user for test scores. What is missing?...
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
  • import java.util.Scanner; public class TriangleMaker {    public static void main(String[] args) {        //...

    import java.util.Scanner; public class TriangleMaker {    public static void main(String[] args) {        // TODO Auto-generated method stub        System.out.println("Welcome to the Triangle Maker! Enter the size of the triangle.");        Scanner keyboard = new Scanner(System.in);    int size = keyboard.nextInt();    for (int i = 1; i <= size; i++)    {    for (int j = 0; j < i; j++)    {    System.out.print("*");    }    System.out.println();    }    for (int...

  • What would be the output if 1, 2, 3, and -1 were entered and please walk...

    What would be the output if 1, 2, 3, and -1 were entered and please walk me through the process. import java.util.Scanner; public class Practice1 { public static void main(String[] args) { int count = 0; int sum = 0; Scanner keyboard = new Scanner(System.in); System.out.println("Enter integers or -1 to quit"); int anInt = keyboard.nextInt(); while(anInt != -1) { anInt = keyboard.nextInt(); sum += anInt; count++; } anInt = keyboard.nextInt(); sum += anInt; count++; } }

  • I have this program: It passes on certain test cases. The Demo five has the %.1f...

    I have this program: It passes on certain test cases. The Demo five has the %.1f to cut down the number to one decimal place. But I get a failed attempt such as: Enter length: \n Enter width: \n You entered: 87.3, 2.0, and 174.7\n -- Rectangle info --\n Length: 87.34\n Width: 2.0\n Area: 174.68\n And I know it is because the length and area both have 2 decimal places. Could you help me fix this? Thank you. Program Content:...

  • This is the assignment..... Write a class DataSet that stores a number of values of type...

    This is the assignment..... Write a class DataSet that stores a number of values of type double. Provide a constructor public DataSet(int maxNumberOfValues) and a method public void addValue(double value) that add a value provided there is still room. Provide methods to compute the sum, average, maximum and minimum value. ​This is what I have, its suppose to be using arrays also the double smallest = Double.MAX_VALUE; and double largest = Double.MIN_VALUE;​ are there so I don't need to create...

  • Complete the following Java class. In this class, inside the main() method, user first enters the...

    Complete the following Java class. In this class, inside the main() method, user first enters the name of the students in a while loop. Then, in an enhanced for loop, and by using the method getScores(), user enters the grades of each student. Finally, the list of the students and their final scores will be printed out using a for loop. Using the comments provided, complete the code in methods finalScore(), minimum(), and sum(). import java.util.Scanner; import java.util.ArrayList; public class...

  • make this program run import java.util.Scanner; public class PetDemo { public static void main (String []...

    make this program run import java.util.Scanner; public class PetDemo { public static void main (String [] args) { Pet yourPet = new Pet ("Jane Doe"); System.out.println ("My records on your pet are inaccurate."); System.out.println ("Here is what they currently say:"); yourPet.writeOutput (); Scanner keyboard = new Scanner (System.in); System.out.println ("Please enter the correct pet name:"); String correctName = keyboard.nextLine (); yourPet.setName (correctName); System.out.println ("Please enter the correct pet age:"); int correctAge = keyboard.nextInt (); yourPet.setAge (correctAge); System.out.println ("Please enter the...

  • I am creating a program where a user will enter in a price amount. And then...

    I am creating a program where a user will enter in a price amount. And then the program will determine how many 20, 10, 5, 1, etc.. they get back. I keep getting "error: unexpected type" in my findValue method. Not too sure why I am getting this. There also might be more bugs in there that I am not aware of because it wont compile. Any help is appreciated. Here is my code: import java.util.Scanner; public class prac1 {...

  • I am currently doing homework for my java class and i am getting an error in...

    I am currently doing homework for my java class and i am getting an error in my code. import java.util.Scanner; import java.util.Random; public class contact {       public static void main(String[] args) {        Random Rand = new Random();        Scanner sc = new Scanner(System.in);        System.out.println("welcome to the contact application");        System.out.println();               int die1;        int die2;        int Total;               String choice = "y";...

  • Need Help ASAP!! Below is my code and i am getting error in (public interface stack)...

    Need Help ASAP!! Below is my code and i am getting error in (public interface stack) and in StackImplementation class. Please help me fix it. Please provide a solution so i can fix the error. thank you.... package mazeGame; import java.io.*; import java.util.*; public class mazeGame {    static String[][]maze;    public static void main(String[] args)    {    maze=new String[30][30];    maze=fillArray("mazefile.txt");    }    public static String[][]fillArray(String file)    {    maze = new String[30][30];       try{...

  • I keep getting the compilation error: pass the filename from command line arguement... Can you please...

    I keep getting the compilation error: pass the filename from command line arguement... Can you please tell me what im doing wrong? here is the code: import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class ShipDemo { public static void main(String[] args) { String companyName; int num_ships, total_passengers=0, total_tonnage=0; Ship[] shipInventory; try { if(args.length == 1) { File file = new File(args[0]); Scanner fileScan = new Scanner(file); companyName = fileScan.nextLine(); num_ships = fileScan.nextInt(); shipInventory = new Ship[num_ships]; int n=0; String type,name;...

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
ADVERTISEMENT