For some reason I get a syntax error that says, “Syntax error, insert “}” to complete ClassBody.” I checked every method, every statement to make sure I have complete opening and closing brackets, so I don’t know why this is happening. Can anybody tell me why I might be getting this issue?
Copying the code into another file doesn’t fix the problem, nor does going to Project > Clean.
import java.util.Scanner; public class jloneman_Numerology { private String[] report; private int day, month, year, num; public jloneman_Numerology() { introduction(); report = new String[9]; num = 0; } public void introduction() { System.out.println("Welcome to ACME Numerology Reports! We will " + "determine your specialnnumerology report based on your " + "birth date.n"); } public void getDate() { char slash1, slash2; do { System.out.print("Please enter your birth date (mm / dd / yyyy): "); Scanner in = new Scanner(System.in); String date = in.nextLine(); month = in.nextInt(); day = in.nextInt(); year = in.nextInt(); slash1 = date.charAt(3); slash2 = date.charAt(8); } while (validDate(slash1, slash2) == false); calcNum(); } public boolean validDate(char slash1, char slash2) { boolean isValid = true; // Check for valid month if (month < 1 || month > 12) { isValid = false; System.out.printf("Invalid month: %dn", month); } // Check for valid day if (day < 1 || day > 31) { isValid = false; System.out.printf("Invalid day: %dn", day); } // Check for months with 30 days, else 31 days = invalid if ((month == 4 || month == 6 || month == 9 || month == 11) && (day < 1 || day > 30)) { isValid = false; System.out.printf("Invalid day: %dn", day); } else if (day < 1 || day > 31) { isValid = false; System.out.printf("Invalid day: %dn", day); } // Check for valid year if (year < 1880 || year > 2280) { isValid = false; System.out.println("Please enter a valid year between 1880 and 2280."); } // Check for correct separating character if (slash1 != '/' || slash2 != '/') { isValid = false; System.out.println("Invalid separating character, please use forward slashes"); } if (leapYear() == true) { if (month == 2 && day > 29) { isValid = false; System.out.printf("Invalid day for 2/%d: %d", year, day); } } return isValid; } public boolean leapYear() { boolean isLeap; if (year % 4 == 0 && year % 400 != 0) isLeap = false; else isLeap = true; return isLeap; } public void calcNum() { // Separate each digit of the date and add to a single number // Test number for debugging num = 5; } public void printReport() { report[0] = ":1: "; report[1] = ":2: "; report[2] = ":3: "; report[3] = ":4: "; report[4] = ":5: "; report[5] = ":6: "; report[6] = ":7: "; report[7] = ":8: "; report[8] = ":9: "; System.out.println(report[num]); } } 78,0-1 Bot
Advertisement
Answer
Try removing (or commenting out) one method and see if the problem persists. If it does, remove or comment out an additional method, and so on, until the error disappears. Then restore everything but the last method.
If the error doesn’t reappear, the problem is probably in that last method.
If it does reappear, the problem is more subtle; perhaps a control character embedded in the code. Try copying and pasting the code into a text-only editor (so any control characters will be ignored, save it, and recompiling.