Study Guides (400,000)
US (230,000)
Rutgers (3,000)
4:18 (70)
Midterm

# 01:198:111 Study Guide - Midterm Guide: Debugging, Hypotenuse

Department
Computer Science
Course Code
01:198:111
Professor
GUNAWARDENA
Study Guide
Midterm

This preview shows half of the first page. to view the full 3 pages of the document.
CS111 Midterm 1 Review
Program Debugging
Debug the following program (it should be able to run and function as expected). Look for type
errors, syntax errors, and logical errors. The class must be in a file named FaultyProgram.java:
public class faultyProgram{
public static Void main(String args)
int pi = 3.14;
System.out.println("This is a test program!");
System.out.println("1: Compute volume of sphere");
System.out.println("2: Compute area of circle");
Systemout.println("3: Compute hypotenuse of triangle");
if(option = 1){
System.out.println("Volume of sphere with radius " + radius + " is: " + volume);
}else if(option == 2){
System.out.println("Area of circle with a radius of " + radius + "is: " + area);
}else if(option = 3){
System.out.println("Please enter a, or 0 if unknown (double): ");
System.out.println("Please enter b, or 0 if unknown (double): ");
System.out.println("Please enter c, or 0 if unknown (double): ");
if(a == 0){
a = Math.sqrt(Math.pow(c, 2) - Math.pow(b, 2));
System.out.println("a: " + a + ", b:" + b + ", c: " + c);
}else if(b == 0){
b = Math.sqrt(Math.pow(c, 2) - Math.pow(a, 2));
System.out.println("a: " + a + ", b:" + b + ", c: " + c);
}else if(c == 0){
c = Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2));
System.out.println("a: " + a + ", b:" + b + ", c: " + c);
}else{
System.out.println("None of the sides are unknown! Uh-oh!");
}
}else{
System.out.println("Invalid number entered!");
}
}
1
Please submit any questions or corrections to joseph.a.boyle@rutgers.edu