Question

Write an application that displays a series of at least five student ID numbers (that you...

Write an application that displays a series of at least five student ID numbers (that you have stored in an array) and asks the user to enter a numeric test score for the student. Create a ScoreException class, and throw a ScoreException for the class if the user does not enter a valid score (less than or equal to 100). Catch the ScoreException, display the message Score over 100, and then store a 0 for the student’s score. At the end of the application, display all the student IDs and scores.

====================================================================================

public class ScoreException extends Exception {
public ScoreException(String s) {
}
}
===============================================================================

import java.util.*;
public class TestScore {
public static void main(String args[]) throws Exception {
Scanner input = new Scanner(System.in);
int[] ids = {1234, 2345, 3456, 4567, 5678};
int[] scores = {0, 0, 0, 0, 0};
String scoreString = new String();
final int HIGHLIMIT = 100;
String inString, outString = "";
for (int x = 0; x < ids.length; ++x) {
System.out.println("Enter score for student id number: " + ids[x]);
inString = input.next();
scores[x] = Integer.parseInt(inString);
// Write your code here
}
for (int x = 0; x < ids.length; ++x)
outString = outString + "ID #" + ids[x] + " Score " +
scores[x] + "\n";
System.out.println(outString);
}
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1
ScoreException

public class ScoreException extends Exception {
    public ScoreException(String s) {
        // calling super class with message
        super(s);
    }
}

TestScore.java

import java.util.*;

public class TestScore {
    public static void main(String args[]) {
        Scanner input = new Scanner(System.in);
        int[] ids = {1234, 2345, 3456, 4567, 5678};
        int[] scores = {0, 0, 0, 0, 0};
        final int HIGHLIMIT = 100;
        for (int x = 0; x < ids.length; x++) {
            System.out.println("Enter score for student id number: " + ids[x]);
            // directly scanning int variable
            int temp = input.nextInt();
            try {
                // comparing score for outer bond and throwing score exception
                if (temp < 0)
                    throw new ScoreException("Score below 0");
                if (temp > HIGHLIMIT)
                    throw new ScoreException("Score over 100");
            } catch (ScoreException e) {
                System.err.println(e.getMessage());
                // resetting to 0 if less than o or greater than 100
                temp = 0;
            }
            // adding score to array
            scores[x] = temp;
        }
        System.out.println();
        String outString = "";
        for (int x = 0; x < ids.length; x++)
            outString = outString + "ID #" + ids[x] + " Score " +
                    scores[x] + "\n";
        System.out.println(outString);
    }
}

// OUT

Please do let me know if u have any concern...

Add a comment
Know the answer?
Add Answer to:
Write an application that displays a series of at least five student ID numbers (that you...
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
  • Write an application that displays a series of at least five student ID numbers (that you...

    Write an application that displays a series of at least five student ID numbers (that you have stored in an array) and asks the user to enter a numeric test score for the student. Create a ScoreException class, and throw a ScoreException for the class if the user does not enter a valid score (less than or equal to 100 or greater than 0). Catch the ScoreException and then prompt the user to re-enter the score. At the end of...

  • You will create a class to keep student's information: name, student ID, and grade. The program...

    You will create a class to keep student's information: name, student ID, and grade. The program will have the following functionality: - The record is persistent, that is, the whole registry should be saved on file upon exiting the program, and after any major change. - The program should provide the option to create a new entry with a student's name, ID, and grade. - There should be an option to lookup a student from his student ID (this will...

  • I need to add a method high school student, I couldn't connect high school student to...

    I need to add a method high school student, I couldn't connect high school student to student please help!!! package chapter.pkg9; import java.util.ArrayList; import java.util.Scanner; public class Main { public static Student student; public static ArrayList<Student> students; public static HighSchoolStudent highStudent; public static void main(String[] args) { int choice; Scanner scanner = new Scanner(System.in); students = new ArrayList<>(); while (true) { displayMenu(); choice = scanner.nextInt(); switch (choice) { case 1: addCollegeStudent(); break; case 2: addHighSchoolStudent(); case 3: deleteStudent(); break; case...

  • Step 4: Add code that discards any extra entries at the propmt that asks if you...

    Step 4: Add code that discards any extra entries at the propmt that asks if you want to enter another score. Notes from professor: For Step 4, add a loop that will validate the response for the prompt question:       "Enter another test score? (y/n): " This loop must only accept the single letters of ‘y’ or ‘n’ (upper case is okay). I suggest that you put this loop inside the loop that already determines if the program should collect...

  • 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;...

  • Write a JAVA program that prompts the user for student grades and displays the highest and...

    Write a JAVA program that prompts the user for student grades and displays the highest and lowest grades in the class. The user should enter a character to stop providing values. Starter code: import java.util.Scanner; public class MaxMinGrades{   public static void main(String[] args){     Scanner input = new Scanner(System.in);     System.out.println("Enter as many student grades as you like. Enter a character to stop.");     double grade = input.nextDouble();     double minGrade = Double.MAX_VALUE;     double maxGrade = Double.MIN_VALUE;     while (Character.isDigit(grade)) {       if (grade == 0)...

  • FOR JAVA: Summary: Create a program that adds students to the class list (see below). The...

    FOR JAVA: Summary: Create a program that adds students to the class list (see below). The solution should be named Roster402_v2.java. Allow the user to control the number of students added to the roster. Ask if the user would like to see their new roster to confirm additions. If yes, then display contents of the file, if no, end the program. ------------------------------------------------------------------------------------- List of student names and IDs for class (this will be your separate text file): Jones, Jim,45 Hicks,...

  • Could you help me pleas , this is my code I want change it to insert...

    Could you help me pleas , this is my code I want change it to insert student by user , and i have problem when i want append name it just one time i can't append or present more one. >>>>>>>>>>>>>>>>>>>. import java.util.Iterator; import java.util.Scanner; public class studentDLLTest { static int getChoice() { Scanner in = new Scanner(System.in); int choice; do { System.out.print("\nYour choice? : "); choice = in.nextInt(); } while (choice < 1 || choice > 9); return choice;...

  • you created an application named QuartsToGallonsInteractive that accepts a number of quarts from a user and...

    you created an application named QuartsToGallonsInteractive that accepts a number of quarts from a user and converts the value to gallons. Now, add exception-handling capabilities to this program and continuously reprompt the user while any nonnumeric value is entered. // QuartsToGallonsInteractive.java import java.util.Scanner; class QuartsToGallonsInteractive {    public static void main(String[] args)    {       final int QUARTS_IN_GALLON = 4;       int quartsNeeded = 18;       int gallonsNeeded;       int extraQuartsNeeded;       Scanner input = new Scanner(System.in);       System.out.print("Enter quarts...

  • using Data Structures using Java. Modify it to make the ADT resizable. For this ADT, the...

    using Data Structures using Java. Modify it to make the ADT resizable. For this ADT, the MAX_SIZE will not be final, but rather will be increased whenever an new item needs to be added and the array is full (ie. size==MAX_SIZE). Whenever the array needs to grow, add the lesser of: (i) half the current size, or; (ii) 50 additional. Have your ADT report its old and new maximum size whenever the resize operation is called by printing “ADT resized...

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