Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Bartleby Related Questions Icon
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();
}
Transcribed Image Text:ValidatorString.java x
Validator.java X
ValidatorNumeric.java X
| 9280 P b
mainValidatorA3.java x
Source
History
1
// ValidatorString.java
2 import java.util.Scanner;
3
4
8
9
10
11
12
13
14
15
16
17
19
20
21
public class ValidatorString implements Validator {
private Scanner scanner;
private String prompt;
private String[] choices;
public ValidatorString(String prompt) {
this.scanner = new Scanner (source: System.in);
this.prompt = prompt;
public ValidatorString(String prompt, String... choices) {
this.scanner = new Scanner (source: System.in);
}
25
}
26
18
30
31
35
36
9=わ22±2927282232223223322-239427344
this.prompt
prompt;
this.choices = choices;
public String getRequiredString() {
String input;
do {
System.out.print (s: prompt);
input = scanner.nextLine().trim();
while (input.isEmpty());
return input;
public String getChoiceString() {
String input;
boolean validChoice;
do {
System.out.print (s: prompt);
input = scanner.nextLine().trim();
validChoice = false;
for (String choice: choices) {
if (input.equalsIgnoreCase (anotherString: choice)) {
validChoice = true;
break;
}
}
40
41
45
}
46
}
if (!validChoice) {
}
System.out.println(x: "Invalid choice. Please try again.");
while (!validChoice);
return input;
Expert Solution
Check MarkThis question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
bartleby
Step by stepSolved in 4 steps with 5 images
Knowledge Booster
Background pattern image
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.Similar questions
- Discussion: chapter 4 Pick a method of debugging/error catching and explain how it works and give a real world example of how it works.arrow_forwardpublic static void printIt(int value) { if(value 0) { } System.out.println("Play a paladin"); System.out.println("Play a white mage"); }else { } }else if (value < 15) { System.out.println("Play a black mage"); System.out.println("Play a monk"); } else { public static void main(String[] args) { printit (5); printit (10); printit (15); Play a black mage Play a white mage (nothing/they are all printed) Play a paladin Play a monkarrow_forwardComplete the isExact Reverse() method in Reverse.java as follows: The method takes two Strings x and y as parameters and returns a boolean. The method determines if the String x is the exact reverse of the String y. If x is the exact reverse of y, the method returns true, otherwise, the method returns false. Other than uncommenting the code, do not modify the main method in Reverse.java. Sample runs provided below. Argument String x "ba" "desserts" "apple" "regal" "war" "pal" Argument String y "stressed" "apple" "lager" "raw" "slap" Return Value false true false true true falsearrow_forward
- Fix all logic and syntax errors. Results Circle statistics area is 498.75924968391547 diameter is 25.2 // Some circle statistics public class DebugFour2 { public static void main(String args[]) { double radius = 12.6; System.out.println("Circle statistics"); double area = java.Math.PI * radius * radius; System.out.println("area is " + area); double diameter = 2 - radius; System.out.println("diameter is + diameter); } }arrow_forwardTASK 5. Methods Overloading. Review Methods, Implement the following code, test it with different input, make sure it runs without errors.arrow_forwardpublic class Turn{public static void main(String[] args){// Different initial values will be used for testingint x = 1; int y = 1; // Turn the arrow by 90 degrees System.out.print("x:", y + 90);System.out.println(x);System.out.print("y: ", x - 1 );System.out.println(y); // Turn the arrow again System.out.print("x:", y - 1);System.out.println(x);System.out.print("y: ",x + 90);System.out.println(y);}}arrow_forward
- using System; class Program{ // Define PrintBoard method public static void PrintBoard() { Console.WriteLine(" X | | "); Console.WriteLine(" | | "); Console.WriteLine(" | O | "); Console.WriteLine(); } public static void Main(string[] args) { PrintBoard(); // Call PrintBoard method PrintBoard(); // Call it again PrintBoard(); // And again! }} This program is really simple and basic to print a tic tac toe board for the user to eventually play the computer in C#. How can it be modified a little bit to print the board and have each tile labeled with a number to identify the space? I'm a beginner and would like to take this step by step in modifying the code. Thank you!arrow_forwardTASK 1. Variables. Review variables, Implement the following code, make sure it runs without errors. Change Summation Integers problem to Finding the minimum problem.arrow_forwardusing System;public static class Lab3_2{public static void Main(){// declare the variables and constantsconst double FLAT = 1.25;double weight;double cost, pricePerKg = 0;// Input the weightConsole.Write("Enter a positive weight of the package => ");weight = Convert.ToDouble(Console.ReadLine());// Determine the cost per kilogramif (weight <= 0)Console.WriteLine("*** Invalid weight");else if (weight < 1)pricePerKg = 0.25;else if (weight <= 3.5)pricePerKg = 0.5;else (weight > 3.5)pricePerKg = 1.0;// Compute the cost to send the packageif (weight > 0)cost = weight * pricePerKg + FLAT;elsecost = 0;// Output the resultsConsole.WriteLine("The cost to send the package is {0:C}",cost);Console.ReadLine();}} Remove the error from the given program and run it for input weight 2.5.arrow_forward
- Examine this code and determine what happens when it is run: 1 public class Test { int x; 2 3 public Test(String t){ System.out.println("Test"); } public static void main(String[] args) { Test test = new Test ("boo"); System.out.println(test.x); } 4 5 6 7 8 10 } The program has a compile error because Test does not have a default constructor. The program has a compile error because System.out.println method cannot be invoked from the constructor. ) The program runs successfully and prints out: Test O The program has a compile error because you cannot create an object from the class that defines the object.arrow_forwardimport java.util.Scanner;/** This program calculates the geometric and harmonic progression for a number entered by the user.*/public class Progression{ public static void main(String[] args) { Scanner keyboard = new Scanner (System.in); System.out.println("This program will calculate " + "the geometric and harmonic " + "progression for the number " + "you enter."); System.out.print("Enter an integer that is " + "greater than or equal to 1: "); int input = keyboard.nextInt(); // Match the method calls with the methods you write int geomAnswer = geometricRecursive(input); double harmAnswer = harmonicRecursive(input); System.out.println("Using recursion:"); System.out.println("The geometric progression of " + input + " is " + geomAnswer); System.out.println("The harmonic progression of " +...arrow_forwardpublic class Course{String name;String dept;int number;public Course (String n, String d, int n){name = n;dept = d;number = n;}public String toString(){return "Course " + name + " in " + dept + " #: " + number;}public static void main (String [] args){Scanner in = new Scanner(System.in);add 10 lines using the scanner and saving them as strings The input for each line will be entered a String, a space, another String, and an int. Parse the input string into those three items and make an instance of Course. Add the new Course instance to a generic ArrayList of Course. print out each Course in the ArrayList.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Text book imageDatabase System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationText book imageStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONText book imageDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- Text book imageC How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONText book imageDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningText book imageProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education