Results 1 to 5 of 5
- 11-26-2008, 09:47 PM #1
Member
- Join Date
- Nov 2008
- Posts
- 2
- Rep Power
- 0
Please help me this is simple bit of code
I am using BlueJ for this
My Person Class THIS WORKS FINE, THE BIT THAT I DONT KNOW WHAT TO CHANGE TO IS COLOURED IN ORANGE AND THE BIT IN BLUE NEEDS A BODY OF CODE
ANY HELP MUCH APPRECIATED
/**
* This is the class Person.
*
* @author (************************)
* @version (1.0)
*/
public class Person
/**
* Instance variables of person, the attributes of the class.
*/
{
protected Date dateOfBirth;
//private int age; //Removed
protected String name;
protected String gender;
protected static int counter;
/**
* Constructors for objects of class Person
*/
public Person(String nme, char sex, Date dob) //int howOld removed
{
name = nme;
setGender(sex);
dateOfBirth = new Date(dob);
counter++;
}
public Person(Person other)
{
name = other.name;
dateOfBirth = other.dateOfBirth;
gender = other.gender;
}
/**
* Methods of the class person
*/
public static int count()
{
return counter;
}
public void setGender(char sex)
{
if (sex == 'm' || sex == 'M')
gender = "male";
else if (sex == 'f' || sex == 'F')
gender = "female";
else gender = "unknown";
}
/**
*Removed
*
//public void incAge()
//{
//age += 1;
//}
public void setAge(int howOld)
{
age = howOld;
}
*
*/
public void setName (String nme)
{
name = nme;
}
public String toString()
{
return "Name: " + name + " Age: "
+ dateOfBirth + " Gender : " + gender; //Changed to dateOfBirth from age
}
public String getName()
{
return name;
}
public String getGender()
{
return gender;
}
/**
*Removed
public int getAge()
{
return age;
}
*/
public Date getdateOfBirth()
{
return dateOfBirth;
}
public boolean sameGender (Person other)
{
return gender.equals(other.gender);
}
public boolean isOlderThan (Person other)
{
return dateOfBirth.earlierThan (other.dateOfBirth);
}
public boolean isFemale()
{
if ( this.gender.equals("Female"))
{
return true;
}
else
{
return false;
}
}
public boolean equals (Person other)
{
return name.equals(other.name) && dateOfBirth == other.dateOfBirth && //Changed to dateOfBirth from age
gender.equals(other.gender);
}
/**
* Accessors to compare age to another person
*/
public boolean isOlderTthan (Person other)
{
return dateOfBirth.earlierThan (other.dateOfBirth); //Changed to dateOfBirth from age < other.age
}
/**
* Transformers that will copy a persons details
*/
public void copy (Person other)
{
name = other.name;
dateOfBirth = other.dateOfBirth; //Changed to dateOfBirth
gender = other.gender;
}
}
.
.
.
.
.
.
THE EMPLOYEE CLASS
/**
* This is the class Employee.
* @author (***************************)
* @version (1.0)
*/
public class Employee extends Person
/**
* Instance variables of Employee, the attributes of the class.
*/
{
private Date dateStarted;
private float salary;
private int id;
/**
* Constructors for objects of class Employee
*/
public Employee(String nme, char sex, Date dob, int number, Date start)
{
super(nme,sex,dob);
id = number;
dateStarted = new Date(start);
salary = 0.0f;
}
/**
* Methods of the class Employee
*/
public boolean equals (Employee other)
{
return super.equals(other) && id == other.id && salary == other.salary &&
dateStarted.equals(other.dateStarted);
}
public void setSalary(float salary);
{
??? //NEED NEW CODE HERE ALSO FOR THIS PART TO WORK NOT SURE WHAT TO DO
}
public Employee (Employee other)
{
this(other.salary,other.id,other.dateStarted);
}
THE BIT IN ORANGE NEEDS TO BE CHANGED TO WORK ( Cannot find symbol - Constructor Employeee (float, int, Date)
public void copy (Employee other)
{
dateStarted.copy(other.dateStarted); // QUESTION 4 Not changed Dont know what to do
salary = other.salary;
id = other.id;
}
public String toString()
{
return "Employee Number: "+ id + "salary " + salary + "Started: " + dateStarted.toString();
}
public Date getDateStarted()
{
return dateStarted;
}
}
-
for this code here:
The this(...) call here is nothing more than a call to your other Employee constructor, and it has to match that constructor exactly. Thus if the first parameter in the other constructor is a String, the first parameter in your this(...) call must be a String too.Java Code:public Employee (Employee other) { this(other.salary,other.id,other.dateStarted); }
So take a very close look at your Employee constructor, especially all the parameters used and the variable types for the parameters, and use these same paramters when calling this(...).
-
for the second problem, understand that a "setter" method, a method that has setXXX in it, is used to update a class's instance fields with the parameter passed. For example if I have a class like so:
and I wanted to change myValue, I'd do something like this:Java Code:class Fubar() { int myValue; }
Notice that I use "this" on the left side to tell the compiler that I want the class's instance myValue on the left of the assignment, the one held by the class (by "this") and the parameter myValue on the right of the assignment.Java Code:public void setMyValue(int myValue) { this.myValue = myValue; }
- 11-27-2008, 02:03 AM #4
Member
- Join Date
- Nov 2008
- Posts
- 2
- Rep Power
- 0
this has helpped alot thank you very much.
-
Similar Threads
-
A simple Java source code viewer
By Java Tip in forum SWTReplies: 0Last Post: 07-11-2008, 04:34 PM -
Peculiarty in code of simple program...
By Kreuz14 in forum New To JavaReplies: 4Last Post: 01-23-2008, 03:27 AM -
simple problem - code wont compile
By dirtycash in forum New To JavaReplies: 1Last Post: 11-20-2007, 05:49 PM -
simple code
By elizabeth in forum New To JavaReplies: 1Last Post: 08-07-2007, 06:49 PM -
problem with a simple java code
By boy22 in forum New To JavaReplies: 2Last Post: 08-03-2007, 02:46 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks