Results 1 to 4 of 4
  1. #1
    adney22 is offline Member
    Join Date
    Jun 2013
    Posts
    1
    Rep Power
    0

    Question Need some assistance

    I am trying to do a class assignment but I do not completely understand the whole adding a class and get call method. I can not get it to work, not really sure that I am doing it right at all. Have attacked the code if someone could help or show me an example of what to do. It would be appricated, thanks
    Attached Files Attached Files

  2. #2
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    892
    Rep Power
    2

    Default Re: Need some assistance

    You have a semi-colon after the method names. You should remove those. The proper way to create a method is:
    Java Code:
    public void doSomething() {
       
    }
    or for a method that returns a value:
    Java Code:
    public String getSomething() {
       return "something";
    }
    Next time don't attach code. Just put it in a [code][/code] block.

    Edit: found some more errors:
    1) setemployeename is not found. The method does not exist.
    2) setregularhours method wants a Double as parameter, you are giving it a String (via Employee constructor)
    3) in setName(String Name) method: this.Name does not exist. Name is anot a field of Employee.
    4) in sethourlyRate(Double rate) method: hourlyRate variable is not found. You probably want to use the Rate parameter.
    Last edited by SurfMan; 06-10-2013 at 11:18 AM.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: Need some assistance

    adney22, please go through the Forum Rules -- particularly the third paragraph.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: Need some assistance

    For the record this is the code in the attachment:
    Java Code:
    //Payroll3
    //This is a program to determine ones payroll amount by user inputing required information
    //David Adney
    //06/03/2013
    
    
    
    
    
    
    
    import java.text.NumberFormat;
    import java.util.Locale;
    import java.util.Scanner;
    
    public class Payroll3{
    
     public static void main( String[]args ){
    	   Scanner input= new Scanner(System.in);//allows program to input user info
    
           String Name;
           Double OtHours,RegularHours,Hours;
        System.out.printf( "Please enter employees name: \n\t Or enter Quit \n" );//Promt user for info
      while (!(Name=input.nextLine()).equalsIgnoreCase("Quit")){//begins loop so that user can continue to use program untill quit is entered
        System.out.println( "Please enter amount of total hours worked: \n\n");
    	Double TotalHours= input.nextDouble ();
            if (TotalHours<=0){//prompts users if the input was invaild
    	        System.out.println( "Please enter a number that is greater than 0 \n");
    	        TotalHours= input.nextDouble ();}
            if (TotalHours<=40){//sets regular hours if no overtime is done
    			RegularHours=TotalHours;}
            if (TotalHours>40);{//if there was overtime hours,sets regular hours at 40 and overtime hours at what is input for overtime
    			OtHours=(TotalHours-40);
                RegularHours=(TotalHours-OtHours);}
                System.out.println( "Please enter the employees hourly rate: \n");
    	        Double Rate= input.nextDouble ();
    	    if (Rate<=0){//prompts user if invaild input is made
    			System.out.println( "Please enter a horly rate that is greater than 0 \n");
    			Rate=input.nextDouble ();}
            Double RegularPay=(RegularHours*Rate);
    	    Double OtPay=(1.5*Rate*OtHours);
    	    Double GrossPay= (RegularPay+OtPay);
    	    Double Taxes= (GrossPay*.12);
    	    Double NetPay= (GrossPay-Taxes);
          if (TotalHours<=40){//activates portion of program if there is no overtime hours worked
                System.out.println();
                System.out.printf("Employees name: %s\n",Name);
           NumberFormat nf=NumberFormat.getCurrencyInstance(Locale.US);
                System.out.println("Hourly Rate: " + nf.format(Rate));
                System.out.printf("Total Hours Worked: %.2f\n\n",TotalHours);
                System.out.println("GrossPay is: " + nf.format(GrossPay));
                System.out.println("Federal Taxes: " + nf.format(Taxes));
                System.out.println("NetPay is: " + nf.format(NetPay));}
    	    if (TotalHours>40){//activates portion of program to handle overtime hours, and also displays info
    	        System.out.println();
    	        System.out.printf( "Employees name: %s\n",Name);
    	   NumberFormat nf=NumberFormat.getCurrencyInstance(Locale.US);
        	    System.out.println("Hourly Rate: " + nf.format(Rate));
    	        System.out.printf("Total Hours Worked: %.2f\n" + "Regular Hours Worked: %.2f\n" + "Overtime Hours Worked: %.2f\n\n",TotalHours,RegularHours,OtHours);
    	        System.out.println("Regular Pay is: " + nf.format(RegularPay) + "\n" + "Overtime Pay is: " + nf.format(OtPay) + "\n" + "GrossPay is: " + nf.format(GrossPay) + "\n" + "Federal Taxes: " + nf.format(Taxes) + "\n" + "NetPay: " + nf.format(NetPay) + "\n");}
                System.out.println( "Please enter employees name:  \n\t Or enter Quit \n");
        Name=input.nextLine();
    }//end while loop
    }
    }//end of program
    
    
     class Employee {
          private String employeeName;
          private Double Rate;
          private Double regularHours;
          private Double otHours;
    
    
       public Employee(String employeeName, String hourlyRate, String regularHours, String otHours);{
      		setemployeeName(employeeName);
      		sethourlyRate(Rate);
      		setregularHours(regularHours);
      }
    
             public String getemployeeName();{
      			return this.employeename;}
      		 public void setName(String Name);{
      			this.Name=emloyeeName;}
      	    public double gethourlyRate();{
      		   			return this.Rate; }
      	   public void sethourlyRate(Double Rate);{
      				this.Rate=hourlyRate; }
      		public double getregularHours();{
      				return this.regularHours;}
      		public void setregularHours(Double regularHours); {
      				this.regularHours=regularHours; }
      		public double getotHours(); {
      				return this.otHours; }
      		public void setotHours(Double otHours); {
      				this.otHours=otHours; }
    
    		}
    In future, please post the code. Refer to the Guide For New Members and BB Code List - Java Programming Forum - Learn Java Programming for guidance.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. In need of assistance!
    By Arete in forum New To Java
    Replies: 4
    Last Post: 01-26-2012, 01:40 AM
  2. Assistance about this.
    By Syfer in forum Advanced Java
    Replies: 38
    Last Post: 06-21-2010, 05:59 PM
  3. Game assistance.
    By Sean_J in forum New To Java
    Replies: 2
    Last Post: 03-16-2010, 04:05 PM
  4. Looking for assistance
    By s_dawg101 in forum New To Java
    Replies: 32
    Last Post: 11-04-2009, 02:49 AM
  5. In need of some assistance
    By Boer84 in forum New To Java
    Replies: 2
    Last Post: 07-08-2008, 04:14 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •