Question
Can someone help me with this java error. package departmentstorepkg; class Hourly extends Employee { private int hoursWorked; //----------------------------------------------------------------- // Sets up this hourly employee
Can someone help me with this java error.
package departmentstorepkg;
class Hourly extends Employee
{
private int hoursWorked;
//-----------------------------------------------------------------
// Sets up this hourly employee using the specified information.
//-----------------------------------------------------------------
public Hourly (String name, String address, String phone,
String socialSecurityNumber, double payRate)
{
super (name, address, phone, socialSecurityNumber, payRate);
hoursWorked = 0;
}
//-----------------------------------------------------------------
// Adds the specified number of hours to this employee's
// accumulated hours.
//-----------------------------------------------------------------
public void addHours (int moreHours)
{
hoursWorked += moreHours;
}
//-----------------------------------------------------------------
// Computes and returns the pay for this hourly employee.
//-----------------------------------------------------------------
public double pay ()
{
double payment = payRate * hoursWorked;
hoursWorked = 0;
return payment;
}
//-----------------------------------------------------------------
// Returns information about this hourly employee as a string.
//-----------------------------------------------------------------
public String toString ()
{
String result = super.toString();
result += " Current hours: " + hoursWorked;
return result;
}
}
package departmentstorepkg;
abstract class StaffMember
{
private String name;
private String address;
private String phone;
//-----------------------------------------------------------------
// Sets up a staff member using the specified information.
//-----------------------------------------------------------------
public StaffMember (String name, String address, String phone)
{
this.name = name;
this.address = address;
this.phone = phone;
}
//-----------------------------------------------------------------
// Returns a string including the basic employee information.
//-----------------------------------------------------------------
public String toString ()
{
String result = "Name: " + name + " ";
result += "Address: " + address + " ";
result += "Phone: " + phone;
return result;
}
//-----------------------------------------------------------------
// Derived classes must define the pay method for each employee
// type.
//-----------------------------------------------------------------
public abstract double pay();
// getters and setters (mutators) for the private data members of this abstract class
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
}
package departmentstorepkg;
public class DepartmentStoreTest {
public static void main(String[] args) {
// StaffMemberIO empIn = new StaffMemberIO ("./employees.txt");
// StaffMember sm = empIn.getNext();
// while (sm!=null) {
//
// System.out.println(sm);
//
// if(sm instanceof Executive)
// {
// System.out.println(" Executive");
// System.out.println(sm);
// }
// else if(sm instanceof Hourly)
// {
// System.out.println(" Hourly");
// System.out.println(sm);
// }
// else if(sm instanceof Employee)
// {
// System.out.println(" Employee");
// System.out.println(sm);
// }
// System.out.println();
// sm = empIn.getNext();
//
// }
System.out.println();
DepartmentStore store = new DepartmentStore("Allied Service Department Store");
System.out.println();
System.out.println();
DepartmentStore store1 = new DepartmentStore("Store");
System.out.println();
System.out.println("My store: " + store1.toString());
System.out.println("Here are the people in the store: ");
System.out.println("Testing print method in department store class");
store1.print();
System.out.println();
System.out.println("Testing printEmployees method in departmentStore class");
store1.printEmployees();
System.out.println();
System.out.println("Testing printExecutives method in departmentStore class");
store1.printExecutives();
System.out.println();
System.out.println("Testing printHourly method in departmentStore class");
store1.printHourly();
System.out.println();
System.out.println("Testing findEmployee method in departmentStore class");
System.out.println(store1.findEmployee("222-22-2222"));
System.out.println(store1.findEmployee("123-45-6789"));
System.out.println();
System.out.println("Testing removeEmployee method in departmentStore class");
System.out.println("using both removeEmployee(String ssn) and removeEmployee(Employee emp)");
Employee temp1 = store1.findEmployee("123-45-6789");
System.out.println(store1.findEmployee("123-45-6789"));
// using removeEmployee(Employee emp)
Employee temp2 = store1.findEmployee("323-23-5666");
System.out.println(store1.findEmployee("323-23-5666"));
System.out.println("adding employees back in");
System.out.println(store1.findEmployee("123-45-6789"));
System.out.println(store1.findEmployee("323-23-5666"));
System.out.println();
System.out.println("Testing return output for updateHours method in departmentStore class");
System.out.println(store1.updateHours("212-33-6978", 0));
System.out.println(store1.updateHours("222-22-2222", 20));
System.out.println();
System.out.println("Testing hourly hours update for updateHours method in departmentStore class");
System.out.println(store1.updateHours("212-33-6978", 20));
System.out.println(store1.updateHours("658-45-9234", 40));
store1.printHourly();
System.out.println();
System.out.println("Testing awardBonus method in Executive class");
((Executive)store1.findEmployee("123-45-6789")).awardBonus(1000.50);
((Executive)store1.findEmployee("623-34-2399")).awardBonus(1240.50);
((Executive)store1.findEmployee("345-67-8934")).awardBonus(1220.50);
store1.printExecutives();
}
}
package departmentstorepkg;
import java.util.ArrayList;
public class DepartmentStore
{
private static final int DEFAULT_SIZE = 10;
private StaffMember [] myEmployees;
private int myNumberEmployees;
private String myFileName;
private ArrayList empList;
public DepartmentStore(String filename)
{
myFileName = filename;
initialize( );
}
public void awardBonus(double amount){
}
public Employee findEmployee(Object object){
return null;
}
public boolean updateHours(String SSN, int hours){
boolean r = false;
if(findEmployee(SSN) instanceof Hourly)
{
((Hourly)findEmployee(SSN) ).addHours(hours);
r = true;
}
if (r){
return true;
}
else{
return false;
}
}
public void print(){
for(int i = 0; i
System.out.println(empList.get(i).toString());
}
}
public void printEmployees(){
for(int i = 0; i
if(empList.get(i)instanceof Hourly ){
}
else if (empList.get(i) instanceof Executive){
}
else{
System.out.println(empList.get(i).toString());
}
}
}
public void printExecutives(){
for(int i = 0; i
if(empList.get(i)instanceof Executive ){
System.out.println(empList.get(i).toString());
}
}
}
public void printExecutivesPay(){
for(int i = 0; i
if(empList.get(i)instanceof Executive ){
System.out.println(empList.get(i).toString());
}
}
}
public void printHourly(){
for(int i = 0; i
if(empList.get(i)instanceof Hourly){
System.out.println(empList.get(i).toString());
}
}
}
private void initialize( )
{
myEmployees = new StaffMember[DEFAULT_SIZE];
myNumberEmployees = 0;
StaffMemberIO empIO = new StaffMemberIO("employees.txt");
StaffMember t;
while(( t = empIO.getNext()) != null){
if(myNumberEmployees >= myEmployees.length)
resize();
myEmployees[myNumberEmployees] = t;
myNumberEmployees++;
}
}
private void resize( )
{
StaffMember [] temp = new StaffMember[2*myEmployees.length];
for (int i = 0; i
temp[i] = myEmployees[i];
myEmployees = temp;
}
}
package departmentstorepkg;
import java.io.*;
import java.util.*;
public class StaffMemberIO
{
private String myFileName;
private BufferedReader myInfile;
private Scanner scan;
public StaffMemberIO(String filename)
{
myFileName = filename;
openFile();
scan = new Scanner (myInfile);
}
public String toString( )
{
return "[" + myFileName + "]";
}
public StaffMember getNext( )
{
if (scan == null)
return null;
try
{
String typeStr = scan.nextLine();
char type = typeStr.charAt(0);
String name = scan.nextLine();
String address = scan.nextLine();
String phone = scan.nextLine();
String socialSecurity = scan.nextLine();
double pay = scan.nextDouble();
scan.nextLine();
switch (type)
{
case 'e': case 'E':
return new Employee(name, address, phone, socialSecurity, pay);
case 'x': case 'X':
return new Executive(name, address, phone, socialSecurity, pay);
case 'h': case 'H':
return new Hourly(name, address, phone, socialSecurity, pay);
}
return null;
}
catch (Exception e){
closeFile( );
return null;
}
}
private void closeFile( )
{
if (myInfile == null)
return;
try
{
myInfile.close( );
}
catch (IOException e) { }
}
private void openFile( )
{
myInfile = null;
try
{
FileReader fr = new FileReader(myFileName);
myInfile = new BufferedReader(fr);
}
catch (IOException e) {System.err.println("Didn't open " + myFileName);}
}
}
package departmentstorepkg;
class Employee extends StaffMember
{
protected String socialSecurityNumber;
protected double payRate;
//-----------------------------------------------------------------
// Sets up an employee with the specified information.
//-----------------------------------------------------------------
public Employee (String name, String address, String phone,
String socialSecurityNumber, double payRate)
{
super (name, address, phone);
this.socialSecurityNumber = socialSecurityNumber;
this.payRate = payRate;
}
//-----------------------------------------------------------------
// Returns information about an employee as a string.
//-----------------------------------------------------------------
public String toString ()
{
String result = super.toString();
result += " Social Security Number: " + socialSecurityNumber;
return result;
}
//-----------------------------------------------------------------
// Returns the pay rate for this employee.
//-----------------------------------------------------------------
public double pay ()
{
return payRate;
}
// getter and setter for local private data member
public String getSocialSecurityNumber() {
return socialSecurityNumber;
}
public void setSocialSecurityNumber(String socialSecurityNumber) {
this.socialSecurityNumber = socialSecurityNumber;
}
}
package departmentstorepkg;
class Executive extends Employee
{
private double bonus;
//-----------------------------------------------------------------
// Sets up an executive with the specified information.
//-----------------------------------------------------------------
public Executive (String name, String address, String phone,
String socialSecurityNumber, double payRate)
{
super (name, address, phone, socialSecurityNumber, payRate);
bonus = 0; // bonus has yet to be awarded
}
//-----------------------------------------------------------------
// Awards the specified bonus to this executive.
//-----------------------------------------------------------------
public void awardBonus (double execBonus)
{
bonus = execBonus;
}
//-----------------------------------------------------------------
// Computes and returns the pay for an executive, which is the
// regular employee payment plus a one-time bonus.
//-----------------------------------------------------------------
public double pay ()
{
double payment = super.pay() + bonus;
bonus = 0;
return payment;
}
}
employees.txt
x
Mary Jones
123 Main Line
555-0469
123-45-6789
1923.07
E
Joe Smith
3423 UCA Blvd
593-3243
323-23-5666
846.15
h
Alven Chipmonk
32 Hollywood Lane
233-3343
212-33-6978
7.40
x
John Dirk
2334 Hello Way
980-3323
623-34-2399
1732.32
x
Holly Henley
233 IH 10 West
877-7632
345-67-8934
1500.00
h
Doris Day
432 Blanco Road
766-3324
658-45-9234
8.85
My store: departmentstorepkg.DepartmentStore@340f438e Here are the people in the store: Testing print method in department store class Exception in thread "main" java. 1ang.Nul1PointerException at departmentstorepkg.Departmentstore.print (DepartmentStore java:44) at departmentstorepkg.DepartmentstoreTest.main (DepartmentStoreTest.java:45) My store: departmentstorepkg.DepartmentStore@340f438e Here are the people in the store: Testing print method in department store class Exception in thread "main" java. 1ang.Nul1PointerException at departmentstorepkg.Departmentstore.print (DepartmentStore java:44) at departmentstorepkg.DepartmentstoreTest.main (DepartmentStoreTest.java:45)Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started