Eclipse is an integrated development environment (IDE), meaning, that along with
ID: 3910786 • Letter: E
Question
Eclipse is an integrated development environment (IDE), meaning, that along with text editing capabilities, it has all sorts of tools and features to make it easier and more efficient to program, especially in Java.
One nuance when programming is that different environments can have different behaviors without either one necessarily being wrong. For instance, a program may run as expected in Eclipse, but, if you run it in zyBooks, it throws an error. Very often the cause of such issues are related to an improper use of Scanner. That is, the environment of Eclipse (or even the command line) is masking an error in the use of Scanner that is not hidden in the zyBooks environment. The reason behind this is related to how standard input is handled in Eclipse versus zyBooks.
When used correctly, Scanner will work the same in Eclipse as in zyBooks. This program illustrates this issue and asks you to correct it. It may be useful to read through the CS200 Scanner Tutorial.
(1) Copy the following code into a new java file in Eclipse.
(2) Run the code in Eclipse.
(3) Try running the code in 1.16 zyBooks built-in programming window, using the same input that you did in (2). You can use this environment to test your code before submitting it to zyBooks.
(4) Try submitting the code. You should see that the 3 tests produce the same error you saw in (3).
(5) The code should run fine in (2), but give you errors in (3) and (4). Refactor the code so that it works in zyBooks just as it does in Eclipse.
Submission Instructions Deliverables EclipseVsZyBooks.java You must submit these file(s) Compile command javac EclipseVsZyBooks.java -Xlint:all-encoding utf-8 We will use this command to compile your code Submit your files below by dragging and dropping into the area or choosing a file on your hard driveExplanation / Answer
public class EclipseVsZyBooks {
public static void main(String[] args) {
System.out.println("Enter an integer: ");
int a = readInt();
System.out.println("Enter a second integer: ");
int b = readInt();
if(a == b)
System.out.println(a + " equals " + b);
else if (a < b)
System.out.println(a + " is less than " + b);
else
System.out.println(a + " is more than " + b);
}
public static int readInt() {
Scanner sc = new Scanner(System.in);
return Integer.parseInt(sc.nextLine());
}
}
public class EclipseVsZyBooks {
public static void main(String[] args) {
System.out.println("Enter an integer: ");
int a = readInt();
System.out.println("Enter a second integer: ");
int b = readInt();
if(a == b)
System.out.println(a + " equals " + b);
else if (a < b)
System.out.println(a + " is less than " + b);
else
System.out.println(a + " is more than " + b);
}
public static int readInt() {
Scanner sc = new Scanner(System.in);
return Integer.parseInt(sc.nextLine());
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.