I'm working on a homework my OOP class and I just can't figure out this last part. The assignment calls for us to write five different classes with parent class StaffMember. I'm pretty sure I've that at the subclassess (Volunteer, HourlyEmployee and FullTimeEmployee) correct so I'm not going to post those here. I'm having problems with the StaffMemberParser class and how to use it to write the code for the driver class. The driver class should create the objects using the parser (split with "/") and store them in an ArrayList. I feel like I've tried everything and just need some help. The trouble spot is under case A. Additionally, under case D, the program is to search for a member ID and return found if it matches. I've got a couple of ideas on how to do this, but I don't think it will work until I get the first part. Without doing my homework for me, some pointers in the right direction would be very much appreciated. Thank you.
Here's the parser class...
public class StaffMemberParser {
public static StaffMember parseStringToMember(String lineToParse){
String type;
String fN;
String lN;
String iD;
double r = 0.0;
double b = 0.0;
int hW = 0;
String[] empInfo = lineToParse.split("/");
type = empInfo[0].toLowerCase();
fN = empInfo[1];
lN = empInfo[2];
iD = empInfo[3];
if (empInfo[0].toLowerCase() == "volunteer") {
System.out.println(empInfo[0].toLowerCase());
return new Volunteer(fN,lN,iD);
}
else if (empInfo[0].toLowerCase() == "fulltimeemployee"){
r= Double.parseDouble(empInfo[4]);
b = Double.parseDouble(empInfo[5]);
return new FullTimeEmployee(fN,lN,iD,r,b);
}
else if (empInfo[0].toLowerCase() == "hourlyemployee"){
r = Double.parseDouble(empInfo[4]);
hW = Integer.parseInt(empInfo[5]);
return new HourlyEmployee(fN,lN, iD,r,hW);
}
else{
System.out.println("Returned a null");
return null;
}
}
}
and here's the driver class....
import java.io.*; //to use InputStreamReader and BufferedReader
import java.util.*; //to use ArrayList
public class Assignment5
{
public static void main (String[] args)
{
char input1;
String inputInfo = new String();
String line = new String();
boolean found = false;
// ArrayList object is used to store member objects
ArrayList<StaffMember> memberList = new ArrayList();
try
{
printMenu(); // print out menu
// create a BufferedReader object to read input from a keyboard
InputStreamReader isr = new InputStreamReader (System.in);
BufferedReader stdin = new BufferedReader (isr);
do
{
System.out.println("What action would you like to perform?");
line = stdin.readLine().trim();
input1 = line.charAt(0);
input1 = Character.toUpperCase(input1);
if (line.length() == 1)
{
switch (input1)
{
case 'A': //Add Member
System.out.print("Please enter a member information to add:\n");
inputInfo = stdin.readLine().trim();
memberList.add(inputInfo);
memberList.parseStringToMember(inputInfo); <--error here
break;
case 'C': //Compute Pay
for (int i=0; i<memberList.size(); i++)
((StaffMember)memberList.get(i)).computePay();
System.out.print("pay computed\n");
break;
case 'D': //Search for Member
System.out.print("Please enter a memberID to search:\n");
inputInfo = stdin.readLine().trim();
if (found == true)
System.out.print("member found\n");
else
System.out.print("member not found\n");
break;
case 'L': //List Members
if (memberList.size()>0)
{for (int i=0; i<memberList.size(); i++)
System.out.println (memberList.get(i));
}
else
System.out.println ("no member\n");
break;
case 'Q': //Quit
break;
case '?': //Display Menu
printMenu();
break;
default:
System.out.print("Unknown action\n");
break;
}
}
else
{
System.out.print("Unknown action\n");
}
} while (input1 != 'Q'); // stop the loop when Q is read
}
catch (IOException exception)
{
System.out.println("IO Exception");
}
}
/** The method printMenu displays the menu to a user **/
public static void printMenu()
{
System.out.print("Choice\t\tAction\n" +
"------\t\t------\n" +
"A\t\tAdd Member\n" +
"C\t\tCompute Pay\n" +
"D\t\tSearch for Member\n" +
"L\t\tList Members\n" +
"Q\t\tQuit\n" +
"?\t\tDisplay Help\n\n");
}
}