ITS320 week7 Cirtical thinking
· A screen snapshot of your Java source code (all file(s) shown separately) displayed in the IDE or Windows editor showing a successful compilation, if possible (only the beginning of the source file(s) are necessary).
· A listing of your entire source code file(s).
import java.util.InputMismatchException;
import java.util.Scanner;
/*
the driver class called Program5
* @author xyz
*/
public class Program5 {
public static void main(String[] args) {
// The driver class should instantiate a Verify object with a range of 10 to 100.
Verify verify = new Verify(10, 100);
//It should then do the following:
// Use a Scanner to read the user input as an int.
Scanner input = new Scanner(System.in);
int num = 0;
boolean good = true;
//You can ensure that an int was entered because the nextInt method
//in the validate class throws an InputMismatchException if any non digits are entered.
do {
good = true;
try {
//Prompt the user to input a number within the specified range.
System.out.print("Input a number between 10-100 inclusive: ");
num = input.nextInt();
} catch (InputMismatchException ex) {
input = new Scanner(System.in);
System.out.println("Please enter numeric integer value.");
good = false;
}
} while (!good);
try {
//Call the validate method to validate that the number is within the range.
verify.validate(num);
//print the value if it is within the range.
System.out.println("Number entered: " + num);
} catch (NumberNegativeException ex) {
//Print an appropriate error message if the value is not within the range,
System.out.println(ex.getMessage());
} catch (NumberLowException ex) {
//Print an appropriate error message if the value is not within the range,
System.out.println(ex.getMessage());
} catch (NumberHighException ex) {
//Print an appropriate error message if the value is not within the range,
System.out.println(ex.getMessage());
}
}
}
/*
a class called Verify that will be used to validate that a number is within a specified range
*/
public class Verify {
private int minimum;
private int maximum;
/**
* one constructor that has 2 int parameters.
* @param minimum - minimum number in the range
* @param maximum - maximum number in the range.
*/
public Verify(int minimum, int maximum) {
this.minimum = minimum;
this.maximum = maximum;
}
/**
* The validate method will have a single parameter of data type
* @param number - the number that is being validated.
*/
public void validate(int number) throws NumberNegativeException, NumberLowException, NumberHighException {
// If the value of the parameter is less than zero, the method should throw a NumberNegativeException
if (number < 0) {
throw new NumberNegativeException("Exception: Number is negative");
}
// If the value is less than the minimum value of the range, it should throw a NumberLowException.
if (number < minimum) {
throw new NumberLowException("Exception: Number is less than the minimum value of the range");
}
// If the value is greater than the maximum value of the range, it should throw a NumberHighException.
if (number > maximum) {
throw new NumberHighException("Exception: Number is greater than the maximum value of the range");
}
}
}
/*
NumberNegativeException should be subclassed from NumberLowException
*/
public class NumberNegativeException extends NumberLowException {
public NumberNegativeException(String msg) {
super(msg);
}
public NumberNegativeException() {
}
public String toString() {
return "NumberNegativeException";
}
}
/*
NumberLowException should be directly subclassed from the Exception class,
*/
public class NumberLowException extends Exception{
public NumberLowException(String msg) {
super(msg);
}
public NumberLowException() {
}
public String toString() {
return "NumberLowException";
}
}
/*
NumberHighException should be directly subclassed from the Exception class,
*/
public class NumberHighException extends Exception{
public NumberHighException() {
}
public NumberHighException(String msg) {
super(msg);
}
public String toString() {
return "NumberHighException";
}
}
public class BadDataException extends Exception {
// creates exception object with no message
// null message in superclass
public BadDataException() {
}
// str used for exception message
// explicitly invokes superclass constructor
public BadDataException(String str) {
super(str);
}
public String toString() {
return "BadDataException";
}
}
· A screen snapshot of all of your program's outputs for the specified values shown in the five Input/Ouput screens. Failure to show any of them will result in lost points.
12 years ago
Purchase the answer to view it

- jwood_crit_thinking_wk7.zip