# Problem with Result

Page 1 of 1

## 1 Replies - 404 Views - Last Post: 19 June 2013 - 03:48 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=323273&amp;s=4cc595fb23b3e7d700c0b8847f6431b3&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 julieex33

Reputation: 0
• Posts: 1
• Joined: 19-June 13

# Problem with Result

Posted 19 June 2013 - 01:56 PM

```import java.util.*;
import java.text.DecimalFormat;
import java.text.DateFormat;

public class ProductionWorkerA extends Employee
{
// Constants for the day and night shifts.
public static final int DAY_SHIFT = 1;
public static final int NIGHT_SHIFT = 2;
private int shift;         // The employee's shift
private double payRate;    // The employee's pay rate

/**
This constructor initializes an object with a name,
employee number, hire date, shift, and pay rate
@param n The employee's name.
@param num The employee's number.
@param date The employee's hire date.
@param sh The employee's shift.
@param rate The employee's pay rate.
*/

public ProductionWorkerA(String n, String num, String date,
int sh, double rate)
{
super(n, num, date);
shift = sh;
payRate = rate;
}
/**
The no-arg constructor initializes an object with
null strings for name, employee number, and hire
date. The day shift is selected, and the pay rate
is set to 0.0.
*/

public ProductionWorkerA()
{
super();
shift = DAY_SHIFT;
payRate = 0.0;
}

/**
The setShift method sets the employee's shift.
@param s The employee's shift.
*/
public void setShift(int s)
{
shift = s;
}
/**
The setPayRate method sets the employee's pay rate.
@param p The employee's pay rate.
*/

public void setPayRate(double p)
{
payRate = p;
}
/**
The getShift method returns the employee's shift.
@return The employee's shift.
*/

public int getShift()
{
return shift;
}
/**
The getPayRate method returns the employee's pay rate.
@return The employee's pay rate.
*/

public double getPayRate()
{
return payRate;
}

/**
toString method
@return A reference to a String representation of
the object.
*/

public String toString()
{
DecimalFormat dollar = new DecimalFormat("#,##0.00");

String str = super.toString();

str += "\nShift: ";
if (shift == DAY_SHIFT)
str += "Day";
else if (shift == NIGHT_SHIFT)
str += "Night";
else
str += "INVALID SHIFT NUMBER";

str += ("\nHourly Pay Rate: \$" +
dollar.format(payRate));

return str;
}

}

```

```import java.util.*;
public class Employee
{
String name;             // Employee name
String employeeNumber;   // Employee number
String hireDate;         // Employee hire date

/**
This constructor initializes an object with a name,
employee number, and hire date.
@param n The employee's name.
@param e The employee's number.
@param h The employee's hire date.
*/

public Employee(String n, String e, String h)
{
name = n;
employeeNumber = e;
hireDate = h;
}
/**
The no-arg constructor initializes an object with
null strings for name, employee number, and hire
date.
*/

public Employee()
{
name = "";
employeeNumber = "";
hireDate = "";
}

/**
The setName method sets the employee's name.
@param n The employee's name.
*/
public void setName(String n)
{
name = n;
}

/**
The setEmployeeNumber method sets the employee's
number.
@param e The employee's number.
*/
public void setEmployeeNumber(String e)
{
if (isValidEmpNum(e))
{
employeeNumber = e;
}
else
{
employeeNumber = "";
}
}
/**
The setHireDate method sets the employee's
hire date.
@param h The employee's hire date.
*/
public void setHireDate(String h)
{
hireDate = h;
}
/**
The getName method returns the employee's name.
@return The employee's name.
*/
public String getName()
{
return name;
}
/**
The getEmployeeNumber method returns the
employee's number.
@return The employee's number.
*/
public String getEmployeeNumber()
{
return employeeNumber;
}
/**
The getHireDate method returns the
employee's hire date.
@return The employee's hire date.
*/

public String getHireDate()
{
return hireDate;
}
/**
isValidEmpNum is a private method that
determines whether a string is a valid
employee number.
@param e The string containing an employee
number.
@return true if e references a valid ID number,
false otherwise.
*/
private boolean isValidEmpNum(String e)
{
boolean status = true;

if (e.length() != 5)
status = false;
else
{
if ((!Character.isDigit(e.charAt(0)))  ||
(!Character.isDigit(e.charAt(1)))   ||
(!Character.isDigit(e.charAt(2)))   ||
(e.charAt(3) != '-')                ||
(!Character.isLetter(e.charAt(4)))  ||

//needs to check if between A and M
(!(e.charAt(4)>= 'A' && e.charAt(4)<= 'M')))
{
status = false;
}
}
return status;
}
/**
toString method
@return A reference to a String representation of
the object.
*/

public String toString()
{
String str = "Name: " + name + "\nEmployee Number: ";

if (employeeNumber == "")
{
str += "INVALID EMPLOYEE NUMBER";
}
else
{
str += employeeNumber;
}

str += ("\nHire Date: " + hireDate);
return str;
}
}

```

```import java.util.*;
import java.text.DecimalFormat;
import java.text.DateFormat;

/**
This program  uses the Production Worker class that extends the employee
class.
*/
public class ProductionWorkerDemo
{
public static void main(String[] args)
{
String name;             // Employee name
String employeeNumber;   // Employee number
String hireDate;         // Employee hire date
int shift;		  			 // Employee shift
double payRate;  			 // Employee pay

// Creates Scanner object
Scanner s = new Scanner(System.in);

// Gets the user's name.
name = s.nextLine();

// Gets the user's employee number.
employeeNumber = s.nextLine();

// Gets the user's hire date.
hireDate = s.nextLine();

// Gets the user's payrate.
payRate = s.nextDouble();

// Gets the user's shift.
shift = s.nextInt();

// Creates an Production worker object.
ProductionWorkerA pw =
new ProductionWorkerA();

System.out.println();
System.out.println("Name: " + pw.getName());
System.out.println("Employee Number: " + pw.getEmployeeNumber());
System.out.println("Hire Date: " + pw.getHireDate());
System.out.println("Pay Rate: " + pw.getPayRate());
System.out.println("Shift: " + pw.getShift());

}
}

```

-----------------------------------------------------------

when i run this program ::::

BOB
0624819
may 1 2013
45.00
1

Name:
Employee Number:
Hire Date:
Pay Rate: 0.0
Shift: 1

How does everything come blank.
Please i fix my code someone

Is This A Good Question/Topic? 0

## Replies To: Problem with Result

• Saucy!

Reputation: 6203
• Posts: 23,939
• Joined: 23-August 08

## Re: Problem with Result

Posted 19 June 2013 - 03:48 PM

Because you don't use the constructor that takes arguments, so the member variables of your class never get assigned anything but the defaults which are assigned in the no-args constructor.