java - Error with VariableDeclartorID expected after this token -
i following message on line "private reader = new bufferedreader(new filereader(deleterecord));":
syntax error on token "reader", variabledeclartorid expected after token
code:
import java.io.bufferedwriter; import java.io.bufferedreader; import java.io.file; import java.io.filereader; import java.io.filewriter; import java.io.printwriter; import java.util.scanner; public class examgradesmethods { private static int exammark = 0; private static int menu = 0; private static string firstname = ""; private static string firstnamedelete = ""; private static string lastname = ""; private static string lastnamedelete = ""; private static string unit = ""; private static string entry = ""; private static string firstcap = ""; private static string surcap = ""; private static scanner scan = new scanner(system.in); private static bufferedreader reader = null; private filewriter grades = new filewriter("gradeenter.txt",true); private bufferedwriter bw = new bufferedwriter(grades); private printwriter out = new printwriter(bw); private reader = new bufferedreader(new filereader(deleterecord)); private static file deleterecord = new file("gradeenter.txt"); public static void menuactions() { system.out.println("menu: "); system.out.println("1) enter student grade(s)"); system.out.println("2) view student grade(s)"); system.out.println("3) delete grade(s)"); system.out.println("4) exit"); menu = scan.nextint(); switch(menu) { case 1: entergrades(); break; case 2: viewgrades(); break; case 3: deletegrades(); break; case 4: exitprogram(); break; default: menuactions(); } } public static void entergrades() { system.out.print("please enter student first name: "); firstname = scan.next(); while(!firstname.matches("[-a-za-z]*")) { system.out.print("please enter valid first name: "); firstname = scan.next(); } firstcap = firstname.substring(0,1).touppercase() + firstname.substring(1); system.out.print("please enter student surname: "); lastname = scan.next(); while(!lastname.matches("[-a-za-z]*")) { system.out.print("please enter valid surname: "); lastname = scan.next(); } surcap = lastname.substring(0,1).touppercase() + lastname.substring(1); system.out.print("please select subject unit: "); unit = scan.next(); system.out.print("please enter student mark: "); while (!scan.hasnextint()) { system.out.print("please enter valid mark: "); scan.next(); } exammark = scan.nextint(); if (exammark < 40) { system.out.println("failed"); } else if (exammark >= 40 && exammark <= 49) { system.out.println("3rd"); } else if (exammark >= 50 && exammark <= 59) { system.out.println("2/2"); } else if (exammark >= 60 && exammark <= 69) { system.out.println("2/1"); } else if (exammark >= 70 && exammark <= 100) { system.out.println("1st"); } else { system.out.println("invalid mark"); } entry = (firstcap + " " + surcap + ", " + unit + ", " + exammark); // out.println(entry); menuactions(); } public static void viewgrades() { int =1; string line; while ((line = reader.readline()) != null) { system.out.println(i + ") " + line); i++; } menuactions(); } public static void deletegrades(){ int = 1; string line; file tempfile = new file("mytempfile.txt"); bufferedwriter writer = new bufferedwriter(new filewriter(tempfile)); system.out.println("current entries stored: "); =1; while ((line = reader.readline()) != null) { system.out.println(i + ") " + line); i++; } scanner scanner = new scanner(system.in); system.out.print("to delete, please enter student's first name: "); firstnamedelete = scanner.nextline(); system.out.print("now, please enter student's surname: "); lastnamedelete = scanner.nextline(); reader.close(); reader = new bufferedreader(new filereader(deleterecord)); string currentline = reader.readline(); while(currentline != null) { if(!currentline.contains(firstnamedelete) && !currentline.contains(lastnamedelete)) { writer.write(currentline); writer.newline(); } currentline = reader.readline(); } system.out.print("if name matches, deleted "); reader.close(); writer.close(); deleterecord.delete(); tempfile.renameto(deleterecord); } public static void exitprogram(){ system.out.println("thanks using 'gradeenter' "); system.exit(0); // sure want exit gui? } public static void main(string[] args) throws exception { system.out.println("welcome 'gradeenter' program! "); menuactions(); } }
i have looked around , cant find on issue. if can help, i'd grateful. thanks
reader
requires type in declaration, variable deleterecord
used before declared - statement defines reader
throws checked exception need placed in code block rather class block
public class examgradesmethods { ... private void readrecords() throws filenotfoundexception { file deleterecord = new file("gradeenter.txt"); bufferedreader reader = new bufferedreader(new filereader(deleterecord)); ... } }
read: variables
Comments
Post a Comment