Create a DataEntryException class whose getMessage() method returns information about invalid integer data. Write a program named GetIDAndAge that continually prompts the user for an ID number and an age until a terminal 0 is entered for both. If the ID and age are both valid, display the message ID and Age OK.
Throw a DataEntryException if the ID is not in the range of valid ID numbers (0 through 999), or if the age is not in the range of valid ages (0 through 119). Catch any DataEntryException or InputMismatchException that is thrown, and display the message Invalid age or ID - DataEntryException - \, where \ is the value of the invalid input. For example:
Enter ID 1000 Enter age 40 Invalid age or ID - DataEntryEx
CODE:
public class DataEntryException extends Exception {
public DataEntryException(int num) {
}
}
---------------------
import java.util.*;
public class GetIDAndAge {
public static void main(String[] args) {
int id;
int age;
final int QUIT = 0;
int returnVal = QUIT + 1;
Scanner keyboard = new Scanner(System.in);
while (returnVal != QUIT) {
// Write your code here
}
}
public static int check(int idNum, int ageNum) throws
DataEntryException {
// Write your code here
}
public static void showStatus(String msg) {
// Write your code here
}
}
Note: Could you plz go through this code and let me
know if u need any changes in this.Thank You
_________________
// DataEntryException.java
public class DataEntryException extends Exception {
public DataEntryException(int num) {
System.out.println("Invalid age or
ID - DataEntryEx");
}
}
_________________________
// GetIDAndAge.java
import java.util.*;
public class GetIDAndAge {
public static void main(String[] args) {
int id;
int age;
final int QUIT = 0;
int returnVal = QUIT + 1;
Scanner keyboard = new
Scanner(System.in);
while (returnVal != QUIT) {
try {
System.out.print("Enter ID :");
id=keyboard.nextInt();
System.out.print("Enter age :");
age=keyboard.nextInt();
returnVal=check(id,age);
}
catch (DataEntryException e)
{
}
}
}
public static int check(int idNum, int ageNum) throws
DataEntryException {
int status=1;
if(idNum>0 &&
ageNum>0)
{
showStatus("ID
and Age OK");
status=0;
}
else if(idNum<0)
{
throw new
DataEntryException(idNum);
}
else if(ageNum<0)
{
throw new
DataEntryException(ageNum);
}
else
{
status=0;
}
return status;
}
public static void showStatus(String msg) {
System.out.println(msg);
}
}
___________________________
Output:
Enter ID :-56677
Enter age :45
Invalid age or ID - DataEntryEx
Enter ID :2455
Enter age :-45
Invalid age or ID - DataEntryEx
Enter ID :1000
Enter age :40
ID and Age OK
______________.Thank You
Create a DataEntryException class whose getMessage() method returns information about invalid integer data. Write a program...
Hello, How can I make the program print out "Invalid data!!" and nothing else if the file has a grade that is not an A, B, C, D, E, or F or a percentage below zero? I need this done by tomorrow if possible please. The program should sort a file containing data about students like this for five columns: one for last name, one for first name, one for student ID, one for student grade percentage, one for student...
(To be written in Java code) Create a class named CollegeCourse that includes the following data fields: dept (String) - holds the department (for example, ENG) id (int) - the course number (for example, 101) credits (double) - the credits (for example, 3) price (double) - the fee for the course (for example, $360). All of the fields are required as arguments to the constructor, except for the fee, which is calculated at $120 per credit hour. Include a display()...
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...
A. Create a CollegeCourse class. The class contains fields for the course ID (for example, CIS 210), credit hours (for example, 3), and a letter grade (for example, A). Include get and set methods for each field. Create a Student class containing an ID number and an array of five CollegeCourse objects. Create a get and set method for the Student ID number. Also create a get method that returns one of the Student’s CollegeCourses; the method takes an integer...
Help! Not sure how to create this java program to run efficiently. Current code and assignment attached. Assignment :Write a class Movies.java that reads in a movie list file (movies.txt). The file must contain the following fields: name, genre, and time. Provide the user with the options to sort on each field. Allow the user to continue to sort the list until they enter the exit option. ---------------------------------------------------------- import java.util.*; import java.io.*; public class Movies { String movieTitle; String movieGenre;...
A. Create a CollegeCourse class. The class contains fields for the course ID (for example, CIS 210), credit hours (for example, 3), and a letter grade (for example, A). Include get and set methods for each field. Create a Student class containing an ID number and an array of five CollegeCourse objects. Create a get and set method for the Student ID number. Also create a get method that returns one of the Student’s CollegeCourses; the method takes an integer...
A. Create a CollegeCourse class. The class contains fields for the course ID (for example, CIS 210), credit hours (for example, 3), and a letter grade (for example, A). Include get and set methods for each field. Create a Student class containing an ID number and an array of five CollegeCourse objects. Create a get and set method for the Student ID number. Also create a get method that returns one of the Student’s CollegeCourses; the method takes an integer...
Java 1. Create an application named NumbersDemo whose main() method holds two integer variables. Assign values to the variables. In turn, pass each value to methods named displayTwiceTheNumber(), displayNumberPlusFive(), and displayNumberSquared(). Create each method to perform the task its name implies. 2. Modify the NumbersDemo class to accept the values of the two integers from a user at the keyboard. This is the base code given: public class NumbersDemo { public static void main (String args[]) { // Write your...
(How do I remove the STATIC ArrayList from the public class Accounts, and move it to the MAIN?) import java.util.ArrayList; import java.util.Scanner; public class Accounts { static ArrayList<String> accounts = new ArrayList<>(); static Scanner scanner = new Scanner(System.in); public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int option = 0; do { System.out.println("0->quit\n1->add\n2->overwirte\n3->remove\n4->display"); System.out.println("Enter your option"); option = scanner.nextInt(); if (option == 0) { break; } else if (option == 1) { add(); } else...
JAVA HELP: Directions Write a program that will create an array of random numbers and output the values. Then output the values in the array backwards. Here is my code, I am having a problem with the second method. import java.util.Scanner; import java.util.Random; public class ArrayBackwards { public static void main(String[] args) { genrate(); print(); } public static void generate() { Scanner scanner = new Scanner(System.in); System.out.println("Seed:"); int seed = scanner.nextInt(); System.out.println("Length"); int length = scanner.nextInt(); Random random...