Java debugging in eclipse

package edu.ilstu;
import java.util.Scanner;
/**
* The following class has four independent debugging
* problems. Solve one at a time, uncommenting the next
* one only after the previous problem is working correctly.
*/
public class FindTheErrors {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
/*
* Problem 1 Debugging
*
* This problem is to read in your first name,
* last name, and current year and display them in
* a sentence to the console.
*/
String firstName = "";
String lastName = "";
String school = "";
int year = 0;
System.out.print("Enter your first name: ");
firstName = keyboard.nextLine();
System.out.print("Enter the current year: ");
year = keyboard.nextInt();
System.out.print("Enter your last name: ");
lastName = keyboard.nextLine();
System.out.println("You are " + firstName + " "
+ lastName + " and it is the year " + year);
keyboard.nextLine();
System.out.println("\n");
/*
* Problem 2 Debugging
*
* This problem is to assign a value to num2 based on
* the input value of num1. It should then print both
* numbers.
*/
// int num1 = 0;
// int num2 = 0;
//
// System.out.print("Enter a number - 1, 2, or 3: ");
// num1 = keyboard.nextInt();
//
// if (num1 == 1);
// num2 = 2;
// else if (num1 == 2);
// num2 = 3;
// else if (num1 == 3);
// num2 = 4;
//
// System.out.println("num1 = " + num1
// + " and num2 = " + num2);
//
// System.out.println("\n");
/*
* Problem 3
*
* This problem is to read the name of the course
* you are taking and display a statement showing the
* answer.
*/
// String courseName = "";
//
// System.out.print(
"Enter your course name (IT168 or IT177): ");
// courseName = keyboard.nextLine();
// if (courseName == IT168))
// System.out.println("You are taking IT168.");
// else if (courseName == IT177))
// System.out.println("You are taking IT177.");
// else
// System.out.println("Invalid input.");
//
// System.out.println("\n");
/*
* Problem 4
*
* This problem is to read a test grade from the
* keyboard and assign the appropriate letter grade.
*/
// int score = 0;
// char grade = 'Z';
//
// System.out.println("Enter your test grade (1-100): ");
// score = keyboard.nextInt();
//
// switch(score)
// {
// case (score > 60):
// grade = 'A';
// break;
// case (score > 70):
// grade = 'b';
// break;
// case (score > 80):
// grade = 'C';
// break;
// case (score > 90):
// grade = 'D';
// break;
// default:
// grade = 'F';
// }
//
// System.out.println("The score " + score
// + " will have a grade of " + grade + ".");
}
}
explainations are added in comments on lines which are altered.
fixed Java code -
package edu.ilstu;
import java.util.Scanner;
/**
* The following class has four independent debugging
* problems. Solve one at a time, uncommenting the next
* one only after the previous problem is working correctly.
*/
public class FindTheErrors {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
/*
* Problem 1 Debugging
*
* This problem is to read in your first name,
* last name, and current year and display them in
* a sentence to the console.
*/
String firstName = "";
String lastName = "";
String school = "";
int year = 0;
System.out.print("Enter your first name: ");
firstName = keyboard.nextLine();
System.out.print("Enter the current year: ");
year = keyboard.nextInt();
System.out.print("Enter your last name: ");
lastName = keyboard.next(); /*nextLine parses input until it finds
newline character('\n'),so the string left after reading by
nextInt(),
so it is reading what's left of previous line,(that's why it is
printing line without taking next input,
while next() parse the next valid string so it skips the previous
input and scans the next string of valid characters*/
System.out.println("You are " + firstName + " "
+ lastName + " and it is the year " + year);
keyboard.nextLine();
System.out.println("\n");
/*
* Problem 2 Debugging
*
* This problem is to assign a value to num2 based on
* the input value of num1. It should then print both
* numbers.
*/
int num1 = 0;
int num2 = 0;
System.out.print("Enter a number - 1, 2, or 3: ");
num1 = keyboard.nextInt();
if (num1 == 1) //removed the ';' as it terminates the if
condition here and would have any effect on further lines
num2 = 2;
else if (num1 == 2) //similarly removed ';'
num2 = 3;
else if (num1 == 3) //removed ';'
num2 = 4;
System.out.println("num1 = " + num1
+ " and num2 = " + num2);
System.out.println("\n");
/*
* Problem 3
*
* This problem is to read the name of the course
* you are taking and display a statement showing the
* answer.
*/
String courseName = "";
System.out.print("Enter your course name (IT168 or IT177):
");
courseName = keyboard.next(); //converted nextLine to next()
because of reason previously stated in problem 1
if (courseName.equals("IT168")) // the '==' operator is not valid
in case of strings, hence equals method is called to match
strings
System.out.println("You are taking IT168.");
else if (courseName.equals("IT177")) //same case
System.out.println("You are taking IT177.");
else
System.out.println("Invalid input.");
System.out.println("\n");
/*
* Problem 4
*
* This problem is to read a test grade from the
* keyboard and assign the appropriate letter grade.
*/
int score = 0;
char grade = 'Z';
System.out.println("Enter your test grade (1-100): ");
score = keyboard.nextInt();
// to convert the range of marks like(60-70) to single integers, we
are dividing it by 10.
switch((int)score/10) //to convert the range to single digit
{
case 6: //cases from 60 to 69
grade = 'D';
break;
case 7: //cases from 70 to 79
grade = 'C';
break;
case 8: //cases from 80-89
grade = 'B';
break;
case 9: //cases from 90-99
case 10: //case of 100
grade = 'A'; //this will be executed for both cases 9 and 10
break;
default:
grade = 'F'; //other cases (0-59)
}
System.out.println("The score " + score
+ " will have a grade of " + grade + ".");
}
}
output screenshot -

Java debugging in eclipse package edu.ilstu; import java.util.Scanner; /** * The following class has four independent...
DEBUGGING. JAVA. Identify the errors in the following. There are no logical errors in this one just syntax issues. //start import java.util.Scanner; public class NumbersDemo { public static void main (String args[]) { Scanner kb = new Scanner(System.in); int num1, num2; System.out.print("Enter an integer >> "); num1 = kb.nextInt(); System.out.print("Enter another integer >> "); num2 = kb.nextDouble(); displayTwiceTheNumber(num1); displayNumberPlusFive(num1); displayNumberSquared(num1) displayTwiceTheNumber(num2); displayNumberPlusFive(num2); displayNumberSquared(num2); } ...
Java // Topic 2c // Program reserves airline seats. import java.util.Scanner public class Plane { // checks customers in and assigns them a boarding pass // To the human user, Seats 1 to 2 are for First Class passengers and Seats 3 to 5 are for Economy Class passengers // public void reserveSeats() { int counter = 0; int section = 0; int choice = 0; String eatRest = ""; //to hold junk in input buffer String inName = ""; ...
Why isnt my MyCalender.java working? class MyCalender.java : package calenderapp; import java.util.Scanner; public class MyCalender { MyDate myDate; Day day; enum Day { Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday } public static void main(String[] args) { Scanner sc= new Scanner(System.in); System.out.println("Enter date below :"); System.out.println("Enter day :"); int day = sc.nextInt(); System.out.println("Enter Month :"); int month = sc.nextInt(); System.out.println("Enter year :"); int year = sc.nextInt(); MyDate md = new MyDate(day, month, year); if(!md.isDateValid()){ System.out.println("\n Invalid date . Try...
make this program run import java.util.Scanner; public class PetDemo { public static void main (String [] args) { Pet yourPet = new Pet ("Jane Doe"); System.out.println ("My records on your pet are inaccurate."); System.out.println ("Here is what they currently say:"); yourPet.writeOutput (); Scanner keyboard = new Scanner (System.in); System.out.println ("Please enter the correct pet name:"); String correctName = keyboard.nextLine (); yourPet.setName (correctName); System.out.println ("Please enter the correct pet age:"); int correctAge = keyboard.nextInt (); yourPet.setAge (correctAge); System.out.println ("Please enter the...
This is the contents of Lab11.java
import java.util.Scanner;
import java.io.*;
public class Lab11
{
public static void main(String args[]) throws IOException {
Scanner inFile = new Scanner(new File(args[0]));
Scanner keyboard = new Scanner(System.in);
TwoDArray array = new TwoDArray(inFile);
inFile.close();
int numRows = array.getNumRows();
int numCols = array.getNumCols();
int choice;
do {
System.out.println();
System.out.println("\t1. Find the number of rows in the 2D
array");
System.out.println("\t2. Find the number of columns in the 2D
array");
System.out.println("\t3. Find the sum of elements...
Language Java Step 1: Design a class called Student. The Student class should contain the following data: firstName lastName studentID totalCredits gpa Your class should implement the “sets” and “gets” for the class. Include methods: equals, compareTo, toString. Change the toString method (from class) to put each member variable on a new line. Step 2: Write a driver program to test that Student works correctly. Test is with 3 students as given in class. Step 3: Write a “registration” program...
package bigIntegerPackage; import java.util.Scanner; public class BigIntMathTesterOne { private static Scanner keyboard = new Scanner(System.in); /* * * @param args */ public static void main(String[] args) { /** * Sample valid input and resulting output * "44444444445555555555666666666677777777770000000000" * stores ["4","4","4","4","4","4","4","4","4","4","5","5","5","5","5","5","5","5","5","5","6","6","6","6","6","6","6'<'6","6","6","7","7","7","7","7","7","7","7","7","7","0","0","0","0","0","0","0","0","0","0"] in ArrayList and sets the value to positive *returns string "44444444445555555555666666666677777777770000000000" * "100000" stores ["1","0","0","0","0","0"] in ArrayList and sets the value to positive *returns string "100000" *"+0" stores ["0"] in ArrayList and sets...
Professionally and thoroughly comment on this code. //BinarySearchTree.java package Project.bst; //imports required import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Scanner; class BSTTreeNode{ BSTTreeNode left, right; String data; public BSTTreeNode(){ left = null; right = null; data = null; } public BSTTreeNode(String n){ left = null; right = null; data = n; } public void setLeft(BSTTreeNode n){ left = n; } public void setRight(BSTTreeNode n){ ...
FOR JAVA: Summary: Create a program that adds students to the class list (see below). The solution should be named Roster402_v2.java. Allow the user to control the number of students added to the roster. Ask if the user would like to see their new roster to confirm additions. If yes, then display contents of the file, if no, end the program. ------------------------------------------------------------------------------------- List of student names and IDs for class (this will be your separate text file): Jones, Jim,45 Hicks,...
Evaluateeg
EvaluateInFix.java:
import java.util.Stack;
import java.util.Scanner;
public class EvaluateInfix
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
System.out.println("This program an inFix Expression: ");
System.out.print("Enter an inFix Expression that you want to
evaluate (or enter ! to exit): ");
String aString = keyboard.nextLine();
while (!aString.equals("!"))
{
System.out.println (evaluateinFix(aString));
System.out.print("Enter an inFix Expression that you
want to evaluate (or enter ! to exit): ");
aString = keyboard.nextLine();
} // end while...