PLEASE HELP DEBUG THE FOLLOWING JAVA PROGRAM
// Program displays some facts about a string
public class DebugSeven3
{
public static void main(String[] args)
{
String quote =
"Honesty is the first
chapter in the book of wisdom. - Thomas Jefferson";
System.out.println("index.of('f')
is: " + indexOf('f'));
System.out.println("index.of('x')
is: " + indexOf('x'));
System.out.println("char.At(5) is: "
+ charAt(5));
System.out.println("endsWith(\"daughter\") is: " +
quote.endswith("daughter"));
System.out.println("endsWith(\"son\") is: " +
quote.endswith("son"));
System.out.println("replace('e',
'*') is: " + quote.replace('e', 'M'));
}
}
The are 5 compilation and 4 logical errors in the code.
The compilation errors that are generated by the code are as follows:

These errors are generated due to the syntactical errors in the code.
There are 3 logical errors in the code as well. Each of the statements contain a logical error:
System.out.println("index.of('f') is: " + indexOf('f'));
System.out.println("index.of('x') is: " +indexOf('x'));
System.out.println("charAt(5) is: " +charAt(5));
System.out.println("replace('e', '*') is: " + quote.replace('e', 'M'));
The explanation of each error and their corresponding corrections are as follows:
1.
The following statement contains a logical as well as a syntactical error:
System.out.println("index.of('f') is: " + indexOf('f'));
Explanation:
Syntactical error:
The method, indexOf(), is a method of the String class and must be called by an object of the String class. Since, there is no method defined in the scope of the program that has the name indexOf(), the program throws an error.
Logical Error:
There is also a logical error in the statement. The statement that is printed onto the console is index.of(‘f’) which states as if the method of() is being called by the variable index.
Correction:
Use the String object defined in the program to call the method indexOf().
Correct the logical error by removing the ‘.’ in between the "" and capitalizing the o in the statement.
Since, the only string defined in the program is quote, the corrected statement is therefore as follows:
System.out.println("indexof('f') is: " + quote.indexOf('f'));
2.
The following statement contains a logical as well as a syntactical error:
System.out.println("index.of('x') is: " +indexOf('x'));
Explanation:
Correction:
Use the String object defined in the program to call the method indexOf(). Since, the only string defined in the program is quote, the corrected statement is therefore as follows:
Correct the logical error by removing the ‘.’ in between the "" and capitalizing the o in the statement.
System.out.println("indexOf('x') is: " + quote.indexOf('x'));
3.
Error:
The following statement contains a logical as well as a syntactical error:
System.out.println("char.At(5) is: " + charAt(5))
Explanation:
Correction:
Use the String object defined in the program to call the method indexOf(). Since, the only string defined in the program is quote, the corrected statement is therefore as follows:
Correct the logical error by removing the ‘.’ in between the "" and capitalizing the a in the statement.
System.out.println("charAt(5) is: " + quote.charAt(5));
4.
Error:
The following statement contains a syntactical error:
System.out.println("endsWith(\"daughter\") is: " + quote.endswith("daughter"));
Explanation:
There is no method named endswith in the string class. The correct name of the method is endsWith().
Correction:
Correct the name of the method to obtain the following the statement:
System.out.println("endsWith(\"daughter\") is: " + quote.endsWith("daughter"));
5.
Error:
The following statement contains a syntactical error:
System.out.println("endsWith(\"son\") is: " + quote.endswith("son"));
Explanation:
There is no method named endswith in the string class. The correct name of the method is endsWith().
Correction:
Correct the name of the method to obtain the following the statement:
System.out.println("endsWith(\"son\") is: " + quote.endsWith("son"));
6.
The following statement contains a logical error:
System.out.println("replace('e', '*') is: " + quote.replace('e', 'M'));
Error:
Correction:
Correct the statement by correcting the call to the replace method. The correct statement is therefore as follows:
System.out.println("replace('e', '*') is: " + quote.replace('e', '*'));
The corrected code is therefore as follows:
Code Screenshots:

Sample Output:

Code to Copy:
// Program displays some facts about a string
public class DebugSeven3
{
public static void main(String[] args)
{
String quote =
"Honesty is the first chapter in the book of wisdom. - Thomas Jefferson";
System.out.println("indexof('f') is: " + quote.indexOf('f'));
System.out.println("indexOf('x') is: " + quote.indexOf('x'));
System.out.println("charAt(5) is: " + quote.charAt(5));
System.out.println("endsWith(\"daughter\") is: " + quote.endsWith("daughter"));
System.out.println("endsWith(\"son\") is: " + quote.endsWith("son"));
System.out.println("replace('e', '*') is: " + quote.replace('e', '*'));
}
}
PLEASE HELP DEBUG THE FOLLOWING JAVA PROGRAM // Program displays some facts about a string public...
What display is produced by the execution of this JAVA program if we make the following call f(0,0). Please explain your answer public class function { static void f(int x){ System.out.println(1); } static void f(double x){ System.out.println(2); } static void f(char x){ System.out.println(3); } static void f(long x){ System.out.println(4); } public static void main(String[] args) { } }
Debugging exercise Programmer Began programming the following program, but made some mistakes. Please debug: class Student{ private int id; private String name; private String city; Student(String name, String city){ this.name = name; this.city = city; } Student(int id, String place){ this.id = id; this.place =name; } void Student(int id, String name, String city){ this.id = id; this.name = name; this.city =...
1) Consider the following Java program: 1 public class HelloWorld { 2 // My first program! 3 public static void main(String[] args) { 4 System.out.println("Hello, World!"); 5 } 6 } What is on line 1? a. a variable declaration b. a statement c. a method (subroutine) definition d. a comment e. a class definition 2) Which one of the following does NOT describe an array? a. It can be used in a for-each loop. b. It has a numbered sequence...
2016 points output of following Java Program? public class Base { public final void show() { . System.out.println("Base::show() called"); public class Derived extends Base { public void show() { System.out.println("Derived::show() called"); } e lor rested in order public class Main { ects from and public static void main(String[] args) { Base b = new Derived(); b.show();
Filename(s): ReformatCode. java Public class: ReformatCode Package-visible class(es): none Write a program that reformats Java source code from the next-line brace style to the end-of-line brace style. The program is invoked from the command line with the input Java source code file as args [0] and the name of the file to save the formatted code in as args [1]. The original file is left untouched. The program makes no other changes the source code, including whitespace. For example, the...
(Process a string) Write a program that prompts the user to enter a string and displays its length and its first character. java StringLength Enter a string:Does quantum determinacy have anything to with whether human cognition is deterministic? The string is of length 88 and the first character is D import java.util.Scanner; class StringLength{ public static void main (String args[]){ Scanner input = new Scanner(System.in); System.out.println("Enter a string:"); String ans = input.nextLine(); System.out.println("The string...
Java Any help is appreciated 8.What is the output of the following program? import java.io.*; public class Q8 { public static void main (String [] args)throws IOException { RandomAccessFile file = new RandomAccessFile (new File ("Q8.txt"), "rw"); double x = 100.00 ; file.writeDouble(x); file.writeDouble(x+10); file.writeDouble(x+20); file.seek(8); System.out.println(file.readDouble()); System.out.println(file.getFilePointer()); } } -------------------------------------------- Output 110.00 16 My Question: why is this the output?
Complete the following Java program by writing the missing methods. public class 02 { public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.println("Enter a number: int n = scan.nextInt(); if (isOdd (n)) { //Print n to 1 System.out.println("Print all numbers from "+n+" to 1"); printNumToOne (n); } else { System.out.println(n + " is //End of main()
Help with a question in Java: What is the output from the following program? public class Methods2 { public static void main(String[] args) { for (int i = 0; i < 3; i++) { for (int j = 0; j <= i; j++){ System.out.print(fun(i, j) + "\t"); } System.out.println(); } } static long fun(int n, int k) { long p = 1; while (k > 0){ p *= n; } return p; } }
Write a JAVA program that prompts the user for student grades and displays the highest and lowest grades in the class. The user should enter a character to stop providing values. Starter code: import java.util.Scanner; public class MaxMinGrades{ public static void main(String[] args){ Scanner input = new Scanner(System.in); System.out.println("Enter as many student grades as you like. Enter a character to stop."); double grade = input.nextDouble(); double minGrade = Double.MAX_VALUE; double maxGrade = Double.MIN_VALUE; while (Character.isDigit(grade)) { if (grade == 0)...