home hardware prices news articles forums photos user reviews
Go Back   Tech Support Forums - TechIMO.com > PC Hardware and Tech > Webmastering and Programming
Ask a Tech Support Question (free)!

calculate salary problem

Reply
Get bargains at  »  Dealighted.com
 
Thread Tools Search this Thread
Currently Active Users: 2142
Discussions: 200,993, Posts: 2,379,914, Members: 246,362
Old April 6th, 2007, 01:27 PM   Digg it!   #1 (permalink)
Junior Member
 
Join Date: Mar 2007
Posts: 2
calculate salary problem

(File handling, Abstract class, class, inheritance, and polymorphism)
Among the people that a company employs are full-time and part-time workers. Consider a situation where we have a super class worker and the 2 subclasses part-time worker and full-time worker. Every worker has a name and a salary rate.

Weekday working hours
· For normal week days, a part-time worker gets paid the hourly wage for the actual number of hours worked, if the hours are at most 40. If the part time worker worked more than 40hrs, the excess is paid at time and a half.
· The full time worker gets paid the hourly wage for 40 hours, no matter what the actual number of hours worked.

Weekend working hours
· A part time worker is paid at time and a half for every hour worked.
· A full time worker is paid twice the regular rate every hour worked.

Develop a java program to calculate the total weekly wage for all the full time and part time workers employed by the company.

__________________________________________________ ___________________

I’ve already developed the

Worker class:

//Worker.java

public abstract class Worker
{
protected String name;

protected float salaryrate;


//get first name
public String getname()
{
return name;
}



public void setname(String n)
{
name = n;
}

//get salaryrate
public double getsalaryrate()
{
return salaryrate;
}

public void setsalaryrate(float s)
{
salaryrate = s;
}

public abstract float calculate(int x);
public abstract float calculate(int y, int z);


} //end class Worker

Full time worker subclass
// Fulltime.java
// Fulltime derived from Worker.

public final class Fulltime extends Worker
{
//default constructor
public Fulltime()
{
name = " ";
salaryrate = 0.0f;
}

// parameterised constructors for class Fulltime
public Fulltime (String n1, float salary)
{
name = n1;
salaryrate = salary;

}

//function calculating the total Salaryrate
public float calculate(int weekendhours)
{
return((40 * salaryrate) + (weekendhours * (salaryrate * 2)));

}

// get String representation of fulltime name
public String toString(int hr)
{
return(name + " \t" + calculate(hr));
}

/*public static void main(String[] args)
{
Fulltime f1 = new Fulltime("Jessica" , 100);
System.out.println(f1.toString(50));
}*/

}// end class

Part time worker subclass
// Parttime.java

public final class Parttime extends Worker
{
private float salary;
private int hours;

//default constructor
public Parttime()
{
name = " ";
salaryrate = 0.0f;

}
// parameterised constructors for class Parttime
public Parttime (String n1, float salary)
{
name = n1;
salaryrate = salary;
}

public float calculate(int x)
{
return 0;
}

//get parttimeworker pay
public float calculate(int weekhours, int weekendhours)
{
if (weekhours < 40)
return((float)((weekhours * salaryrate) + (weekendhours * (salaryrate * 1.5))));

else
return((float) (((weekhours - 40) * 1.5) + (weekhours * salaryrate) + (weekendhours * (salaryrate * 1.5))) );

}

public String toString(int hr1, int hr2 )
{
return(name + " \t" + calculate(hr1, hr2));
}
}

Textfile from where application will read data of workers
F Sandra Blues 9 7 6 8 7#5#2
;
F James Keys 8 6 7 9 5#6#4
;
F Bobby Louis 6 7 9 7 8#3#4
;
P Jessica Burns 8 4 6 2 3#6#5

P Nelly Oneil 5 6 4 3 9#2#2

F Erik Stifler 7 7 8 7 9#5#3
;
P Tracy Sterling 4 6 3 5 5#5#2

F John Tucker 10 8 9 7 8#5#4
;
F Kate Spencer 9 6 8 7 8#6#2
;
__________________________________________________ ______________

I now have to develop the Main application which will open the text file and read it. And will make the program run. But don’t know how to do it. Could anyone plz check my above coding if is gud and help me out with the Main application.
Thnks again,
Babe.
babe20 is offline   Reply With Quote
Old April 6th, 2007, 03:05 PM     #2 (permalink)
Caveat Emptor
 
Rootstonian's Avatar
 
Join Date: Mar 2005
Location: Out of my mind
Posts: 3,242
Send a message via AIM to Rootstonian
I'm a business programmer, COBOL, SQL/SQR etc. I know C++ quite well and JAVA is pretty close. Your worker class and methods "look" ok.

I would have written "main" first; but that's just the way I code. I always call it my "driver" and then branch-out from there. It's just easier that way. I then code "skeleton" methods/functions off that....for example:

"got first record"
"in calculate part time pay"
"data is P Jessica Burns 8 4 6 2 3#6#5"

Then it's just a matter of doing the math on the data.

You'll get it; your code seems clean enough from your post! GOOD LUCK



Search the net of get a book on JAVA and I'm sure it'll guide you in opening and processing files.
Rootstonian is offline   Reply With Quote
Old April 8th, 2007, 11:50 PM     #3 (permalink)
Super F@D Folder
 
Join Date: Jun 2004
Posts: 5,083
Send a message via AIM to sr71000
Code:
 public float calculate(int weekhours, int weekendhours)
{
if (weekhours < 40)
return((float)((weekhours * salaryrate) + (weekendhours * (salaryrate * 1.5))));

else
return((float) (((weekhours - 40) * 1.5) + (weekhours * salaryrate) + (weekendhours * (salaryrate * 1.5))) );

}
this method is wrong..in particular in your else statement. Remember if they go over 40 (for example 50) hours....you pay 40 at regular and the rest at time and a half. you're first calculating anything over 40 and paying time and a half. Then your taking ALL their weekday hours and paying regular. assign numbers to your variable and do it out on paper. I think you'll quickly find your error

/edit. oh yea...your top if statement should be <=. It won't make a difference with the output...but as far as logic goes is they work 40 hours (40 = 40) you should still be picking the first option.

I code like you do babe. Start at the top and work my way down piece by piece until i get to the core (the main). Then go from there! Honestly make another class for file io so you can test that by itself...once that's done then implement the main method!!

/edit again. Just wanted to say much better question this time! This kinda stuff we don't mind helping with . Good to see you didn't take what i said the wrong way and leave. Look forward to working on some fun programming problems with ya Good luck with it and post back if you need more help/advice!

Last edited by sr71000 : April 9th, 2007 at 12:12 AM.
sr71000 is offline   Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Similar Threads
Thread Thread Starter Forum Replies Last Post
Average Salary krotch General Tech Discussion 7 February 14th, 2007 12:33 AM
Negotiating a salary. usslindstrom IMO Community 16 August 21st, 2006 12:53 AM
Salary Chart maface IMO Community 21 June 3rd, 2006 02:21 PM
how to calculate binary? Creatures Webmastering and Programming 15 March 24th, 2003 03:04 PM
Programmer Salary? brandon184 Certification and Education 28 September 3rd, 2002 04:33 AM


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Most Active Discussions
Is It Just Me? (3085)
Foxconn Blackops x48 MoBo (5)
Charges against non-tippers dropped.. (20)
Health Care Rationing (14)
Delete an OS (17)
Nvidia GTX 260 problem (12)
Laptop with wireless problem. (12)
Wireless Televisions. (12)
windows vista security holes (19)
CPU fan stops spinning randomly (11)
Regular Build (11)
[F@H SPAM 11/16/09] ! 1/2 months to.. (41)
Point and Shoot Camera Suggestions. (8)
windows 7 problem (7)
Recent Discussions
Intel 5100 AGN issues fixed yet? (28)
Nvidia GTX 260 problem (12)
Foxconn Blackops x48 MoBo (5)
[F@H SPAM 11/16/09] ! 1/2 months to r.. (41)
Print spooler problem (17)
Q9650 vs. Q9550 (2)
Desktop Calendar Application (2)
Looking for new motherboard (1)
soundmon.exe (8)
Jedi Academy Problem (3)
Can a page file be "too big".. (1)
Point and Shoot Camera Suggestions. (8)
Size after cutting 700Mb file is 2.5 .. (0)
Delete an OS (17)
windows vista security holes (19)
updating BIOS via winflash, claims fi.. (1)
New Server Configuration Suggestions (0)
cheap gaming laptop? (12)
Unallocated Space (2)
help me pls laptop just stopped worki.. (1)
C# + LINQ Help (7)
Dynex DX E-402 (3)
EVGA 9800 gtx help with finding a goo.. (12)
Multiple Restarts Required at Boot (5)
cell phone won't work (0)


All times are GMT -4. The time now is 10:26 AM.
TechIMO Copyright 2009 All Enthusiast, Inc.



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28