Click here to Skip to main content
15,902,901 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
C#
package pay;
public class payment {
private String employeename;
private String payhours;
private String workhours;
private float tax;
private String absenthours;
private String paymonth;
public payment(String e,String p)
{
    setemployeename(e);
        setpayhours(p);
}
    payment() {
        throw new UnsupportedOperationException("Not yet implemented");
    }
public String getemployeename()
{
    return(employeename);
}
public String getpayhours()
{
    return(payhours);
}
public String setemployeement()
{
    return(employeename);
}
public String setpayhour()
{
    return(payhours);
}
public String paymonth()
{
    return (payhours*30);
}
    private void setEmployeename(String e) {
       throw new UnsupportedOperationException("Not yet implemented");
    }
    private void SetPayhours(String p) {
      throw new UnsupportedOperationException("Not yet implemented");
    
    }
}



package pay;
import java.util.Scanner;
public class Main {

    public static void main(String[] args) {
 String employeename;
 String payhours;
  Scanner input=new Scanner(System.in);
        System.out.println("Please enter the employeename:");
        employeename=input.nextLine();
        System.out.println("Please enter the payhours in a day:");
        payhours=input.nextLine();
       // paymentclass pay = new  paymentclass(employeename,payhours);
       payment mypayment = new payment();
      // System.out.printf("employeename is %s",employeename);
       System.out.printf("\npaymonth is %s",payhours);

    }

}


payrollcode:write employeename,hourspay,absentpay,tax and...
Posted
Updated 26-Jan-10 22:28pm
v4

Further to the previous answer, your variable types are wrong. In the class payment, the only string should be employeename, so define:
private String employeename;
private float payhours;
private float workhours;
private float tax;
private float absenthours;
private float paymonth;



I'm not going to give you any code, but I will give you some advice.

Comments are your friend and JavaDoc comments doubly so.

Your names make the code a little hard to read, may I suggest you follow the well established convention of class names beginning with a capital leter, variables and members with lower case, and all subsequent words with a capital; so Payment, employeeName, etc.

Next up, methods should be verb led, accessors are float getPayMonth() twinned with a setter setPayMonth(float).

In a constructor, you should try to avoid calling any member methods.

When accessing a member variable, scope it as this.payMonth, class variables as Payment.taxRate.

How does all this help? Look at your constructor alone and follow the above:

/**
/  The Payment class manages the payroll for
/  a single empoyee.
*/
public class Payment
{
  // member variables

  /**
  / Constructor for an instance of Payment.
  / Takes employee's name and hours
  */
  public Payment(String employeeName,
      float payHours)
  {
    this.employeeName = employeeName;
    this.payHours = payHours;
  }

  // other stuff
}


Now you can see what is happening. The more elegant the code the less chance of a problem because it is readable. Sounds 'stoopid' but after 20+ years, I've also found it's true.
 
Share this answer
 
v2
I'm guessing that multiplying a string by an integer is not what you want to do there. You probably want to convert pay hours to a numeric value before multiplying.

This is only a guess since you haven't explained what you actually want the code to do. That might be some information you wan to to include in your question next time, and please, use the body of the post to ask the question and the title to summarize.
 
Share this answer
 
C#
package pay;
public class payment {
    private String employeename;
    private String payhours;
    private String workhours;
    private float tax;
    private String absenthours;
    private String paymonth;
    public payment(String e,String p)
    {
        setEmployeename(e);
        SetPayhours(p);
    }
    payment() {
        //throw new UnsupportedOperationException("Not yet implemented");
        System.out.println("throw");
    }
    public String getemployeename()
    {
        return(employeename);
    }
    public String getpayhours()
    {
        return(payhours);
    }
    public String setemployeement()
    {
        return(employeename);
    }
    public String setpayhour()
    {
        return(payhours);
    }
    public String paymonth()
    {
        return Integer.toString((Integer.parseInt(payhours)*30));
    }
    private void setEmployeename(String e) {
        throw new UnsupportedOperationException("Not yet implemented");
    }
    private void SetPayhours(String p) {
        throw new UnsupportedOperationException("Not yet implemented");
    }

package pay;

import java.util.Scanner;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		String employeename;
		String payhours;
		Scanner input=new Scanner(System.in);
		System.out.println("Please enter the employeename:");
		employeename=input.nextLine();
		System.out.println("Please enter the payhours in a day:");
		payhours=input.nextLine();
		// paymentclass pay = new  paymentclass(employeename,payhours);
		payment mypayment = new payment();
		// System.out.printf("employeename is %s",employeename);
		System.out.printf("\npaymonth is %s",payhours);
	}

}
}
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900