Fix all errors to make the code compile and complete. //MainValidatorA3 public class MainA3 { public static void main(String[] args) { System.out.println("Welcome to the Validation Tester application"); // Int Test System.out.println("Int Test"); ValidatorNumeric intValidator = new ValidatorNumeric("Enter an integer between -100 and 100: ", -100, 100); int num = intValidator.getIntWithinRange(); System.out.println("You entered: " + num + "\n"); // Double Test System.out.println("Double Test"); ValidatorNumeric doubleValidator = new ValidatorNumeric("Enter a double value: "); double dbl = doubleValidator.getDoubleWithinRange(); System.out.println("You entered: " + dbl + "\n"); // Required String Test System.out.println("Required String Test:"); ValidatorString stringValidator = new ValidatorString("Enter a required string: "); String requiredString = stringValidator.getRequiredString(); System.out.println("\nYou entered: " + requiredString + "\n"); // String Choice Test System.out.println("String Choice Test"); ValidatorString choiceValidator = new ValidatorString("Select one (x/y): ", "x", "y"); String choice = choiceValidator.getChoiceString(); System.out.println("You entered: " + choice); System.out.println("\nAll Done!"); } } //ValidatorNumeric import java.util.Scanner; class ValidatorNumeric { private String prompt; private int minInt, maxInt; private double minDouble, maxDouble; public ValidatorNumeric() {} public ValidatorNumeric(String prompt, int min, int max) { this.prompt = prompt; this.minInt = min; this.maxInt = max; } public ValidatorNumeric(String prompt, double min, double max) { this.prompt = prompt; this.minDouble = min; this.maxDouble = max; } public int getInt() { Scanner scanner = new Scanner(System.in); System.out.print(prompt); while (!scanner.hasNextInt()) { System.out.println("Error! Invalid integer value. Try again."); System.out.print(prompt); scanner.next(); } return scanner.nextInt(); } public int getIntWithinRange() { int num; do { num = getInt(); if (num < minInt) { System.out.println("Error! Number must be greater than " + (minInt - 1)); } else if (num > maxInt) { System.out.println("Error! Number must be less than " + (maxInt + 1)); } } while (num < minInt || num > maxInt); return num; } public double getDouble() { Scanner scanner = new Scanner(System.in); System.out.print(prompt); while (!scanner.hasNextDouble()) { System.out.println("Error! Invalid decimal value. Try again."); System.out.print(prompt); scanner.next(); } return scanner.nextDouble(); } public double getDoubleWithinRange() { double num; do { num = getDouble(); if (num < minDouble) { System.out.println("Error! Number must be greater than " + minDouble); } else if (num > maxDouble) { System.out.println("Error! Number must be less than " + maxDouble); } } while (num < minDouble || num > maxDouble); return num; } } Validator.Java // Validator.java import java.util.Scanner; public interface Validator { String getRequiredString(); String getChoiceString(); }
Fix all errors to make the code compile and complete. //MainValidatorA3 public class MainA3 { public static void main(String[] args) { System.out.println("Welcome to the Validation Tester application"); // Int Test System.out.println("Int Test"); ValidatorNumeric intValidator = new ValidatorNumeric("Enter an integer between -100 and 100: ", -100, 100); int num = intValidator.getIntWithinRange(); System.out.println("You entered: " + num + "\n"); // Double Test System.out.println("Double Test"); ValidatorNumeric doubleValidator = new ValidatorNumeric("Enter a double value: "); double dbl = doubleValidator.getDoubleWithinRange(); System.out.println("You entered: " + dbl + "\n"); // Required String Test System.out.println("Required String Test:"); ValidatorString stringValidator = new ValidatorString("Enter a required string: "); String requiredString = stringValidator.getRequiredString(); System.out.println("\nYou entered: " + requiredString + "\n"); // String Choice Test System.out.println("String Choice Test"); ValidatorString choiceValidator = new ValidatorString("Select one (x/y): ", "x", "y"); String choice = choiceValidator.getChoiceString(); System.out.println("You entered: " + choice); System.out.println("\nAll Done!"); } } //ValidatorNumeric import java.util.Scanner; class ValidatorNumeric { private String prompt; private int minInt, maxInt; private double minDouble, maxDouble; public ValidatorNumeric() {} public ValidatorNumeric(String prompt, int min, int max) { this.prompt = prompt; this.minInt = min; this.maxInt = max; } public ValidatorNumeric(String prompt, double min, double max) { this.prompt = prompt; this.minDouble = min; this.maxDouble = max; } public int getInt() { Scanner scanner = new Scanner(System.in); System.out.print(prompt); while (!scanner.hasNextInt()) { System.out.println("Error! Invalid integer value. Try again."); System.out.print(prompt); scanner.next(); } return scanner.nextInt(); } public int getIntWithinRange() { int num; do { num = getInt(); if (num < minInt) { System.out.println("Error! Number must be greater than " + (minInt - 1)); } else if (num > maxInt) { System.out.println("Error! Number must be less than " + (maxInt + 1)); } } while (num < minInt || num > maxInt); return num; } public double getDouble() { Scanner scanner = new Scanner(System.in); System.out.print(prompt); while (!scanner.hasNextDouble()) { System.out.println("Error! Invalid decimal value. Try again."); System.out.print(prompt); scanner.next(); } return scanner.nextDouble(); } public double getDoubleWithinRange() { double num; do { num = getDouble(); if (num < minDouble) { System.out.println("Error! Number must be greater than " + minDouble); } else if (num > maxDouble) { System.out.println("Error! Number must be less than " + maxDouble); } } while (num < minDouble || num > maxDouble); return num; } } Validator.Java // Validator.java import java.util.Scanner; public interface Validator { String getRequiredString(); String getChoiceString(); }
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
Fix all errors to make the code compile and complete.
//MainValidatorA3
public class MainA3 {
public static void main(String[] args) {
System.out.println("Welcome to the Validation Tester application");
// Int Test
System.out.println("Int Test");
ValidatorNumeric intValidator = new ValidatorNumeric("Enter an integer between -100 and 100: ", -100, 100);
int num = intValidator.getIntWithinRange();
System.out.println("You entered: " + num + "\n");
// Double Test
System.out.println("Double Test");
ValidatorNumeric doubleValidator = new ValidatorNumeric("Enter a double value: ");
double dbl = doubleValidator.getDoubleWithinRange();
System.out.println("You entered: " + dbl + "\n");
// Required String Test
System.out.println("Required String Test:");
ValidatorString stringValidator = new ValidatorString("Enter a required string: ");
String requiredString = stringValidator.getRequiredString();
System.out.println("\nYou entered: " + requiredString + "\n");
// String Choice Test
System.out.println("String Choice Test");
ValidatorString choiceValidator = new ValidatorString("Select one (x/y): ", "x", "y");
String choice = choiceValidator.getChoiceString();
System.out.println("You entered: " + choice);
System.out.println("\nAll Done!");
}
}
//ValidatorNumeric
import java.util.Scanner;
class ValidatorNumeric {
private String prompt;
private int minInt, maxInt;
private double minDouble, maxDouble;
public ValidatorNumeric() {}
public ValidatorNumeric(String prompt, int min, int max) {
this.prompt = prompt;
this.minInt = min;
this.maxInt = max;
}
public ValidatorNumeric(String prompt, double min, double max) {
this.prompt = prompt;
this.minDouble = min;
this.maxDouble = max;
}
public int getInt() {
Scanner scanner = new Scanner(System.in);
System.out.print(prompt);
while (!scanner.hasNextInt()) {
System.out.println("Error! Invalid integer value. Try again.");
System.out.print(prompt);
scanner.next();
}
return scanner.nextInt();
}
public int getIntWithinRange() {
int num;
do {
num = getInt();
if (num < minInt) {
System.out.println("Error! Number must be greater than " + (minInt - 1));
} else if (num > maxInt) {
System.out.println("Error! Number must be less than " + (maxInt + 1));
}
} while (num < minInt || num > maxInt);
return num;
}
public double getDouble() {
Scanner scanner = new Scanner(System.in);
System.out.print(prompt);
while (!scanner.hasNextDouble()) {
System.out.println("Error! Invalid decimal value. Try again.");
System.out.print(prompt);
scanner.next();
}
return scanner.nextDouble();
}
public double getDoubleWithinRange() {
double num;
do {
num = getDouble();
if (num < minDouble) {
System.out.println("Error! Number must be greater than " + minDouble);
} else if (num > maxDouble) {
System.out.println("Error! Number must be less than " + maxDouble);
}
} while (num < minDouble || num > maxDouble);
return num;
}
}
Validator.Java
// Validator.java
import java.util.Scanner;
public interface Validator {
String getRequiredString();
String getChoiceString();
}
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 4 steps with 5 images
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education