I need to access some data which is in an abstract class. Though you cannot inistialise an abstract class.
The task to do is gathering data from a textfile where data is in this format..
P Charles Galea 134
Where my class needs to check if the first letter is a P it do the stuff in the professors class and if it is an S it do the stuff in the Students class. The professor and student class inherits the SchoolMember abstract class which is follows.
and this class
Can please some1 help me correct the commemted part..? where i need to check if the first item in the textfile is a 'p' or an 's' and according to what it is do the specified method?
thank you
The task to do is gathering data from a textfile where data is in this format..
P Charles Galea 134
Where my class needs to check if the first letter is a P it do the stuff in the professors class and if it is an S it do the stuff in the Students class. The professor and student class inherits the SchoolMember abstract class which is follows.
Code:
public abstract class SchoolMember { //These are the attributes for a SchoolMember class String typeOfMember; String name; String surname; Integer score; public abstract boolean outstanding(String s); }
Code:
import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; /* This class is going to be used to parse the file * and gets data from this file to check if the student or the * professor is outstanding or not */ public class FileParser { public SchoolMember[] convert(String s) { FileReader f = null; BufferedReader buf = null; try { f = new FileReader(s); buf = new BufferedReader(f); String line = buf.readLine(); while (line != null) { String[] datum = line.split(" "); // Student stud = new Student(); // Professor prof = new Professor(); // if (SchoolMember.typeOfMember.equals("S") ) { // stud.outstanding(s); } // else if (SchoolMember.typeOfMember.equals("P")) { // prof.outstanding(s); // } } } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { try { if (buf != null) { buf.close(); } buf.close(); f.close(); } catch (IOException e) { // just ignore } } return null; } }
thank you
Comment