Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-24-2011, 09:30 PM   PM User | #1
navya4u2004
New to the CF scene

 
Join Date: Jul 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
navya4u2004 is an unknown quantity at this point
New to Java. need help with hw...pls

Below instruction are part of my HW. and i'm stuck on this. I need to have new class created as mentioned below and out printed on console.
Output needs to look like in attached file. Attachment 10100

Create a Test class (in different file)to test the following functionality in its main method.
a. Declare a variable named currentEmployee of type Employee.
b. Create an Employee object with name Alice and the weekly wage rate 1000 and assign it to the above variable.
c. Print to the console the string representation of this object.
d. Using any of the loop constructs, iterate over the computePayStub of this object with the hours 10, 20, 30, 40, 50, and 60. Display the wages as shown in the sample below.
e. Create a Consultant object with name Bob and the hourly wage rate 100. Reassign the currentEmployee to this object.
f. Repeat the steps shown in c) and d) for this object.






In below file where i have created classes and implement the specified functionality.


package hw3.part2;
import javax.swing.JOptionPane;
import java.text.NumberFormat;


public class Employee {

//instance variables
private String name;
private int wageRate;
NumberFormat moneyFormatter=NumberFormat.getCurrencyInstance();

public Employee(){}

//single constructor
public Employee(String theName, int theWageRate){


name=theName;
wageRate=theWageRate;
}

public String getName() {
return name;
}

public void setName(String newName) {
this.name = newName;
}


public int getWageRate() {
return wageRate;
}

public void setWageRate(int newWageRate) {
this.wageRate = newWageRate;
}

//compute computePayStub
public double computePayStub(double hours)
{

double perHourRate=wageRate/40;
double weekleyWadge=0.0;


if (hours>=40){
weekleyWadge=(perHourRate*40);

}
else if (hours<40){
weekleyWadge=(perHourRate*hours);
}

return weekleyWadge;

}
public String toString (){
return "Employee: Alice";
}
}

//Create a derived class from the Employee class named Consultant

class consultant extends Employee{
public consultant()
{
}
public consultant(String theName,int theWageRate){
super (theName, theWageRate);

}

//Override computePayStub method
public double computePayStub(double hours){
double hourlyRate=getWageRate()/40;
double weekleyWadge=0.0;


if (hours>=40){
if (hours <=50){
weekleyWadge=((hourlyRate*hours)*1.5);
} else {
weekleyWadge=((hourlyRate*50)*1.5); }
}

else {
weekleyWadge=(hourlyRate*hours);}

return weekleyWadge; }

public String toString (){
return "Consultant: Bob";
}
}

Last edited by navya4u2004; 08-10-2011 at 03:47 AM..
navya4u2004 is offline   Reply With Quote
Old 07-25-2011, 01:34 AM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,639
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Okay, and where's the code that you have written to show what you have currently tried?
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:16 PM.


Advertisement
Log in to turn off these ads.