Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    A little bit stuck creating a new object in a class.

    Hey all I was wondering if someone could help me out with a pretty simple Java program, I'm pretty sure most of the code I have is correct but at one point it is giving me an error of "cannot be resolved into variable". Can someone possibly take a look at my code?


    Where it says grossPay in "WeeklyPayroll(name,hourlyWage,hours,grossPay);" is where I am getting my error.
    Code:
    	Scanner keyboard = new Scanner(System.in);
    		System.out.print("Please enter an employee name for employee1: ");//Tom
    		String name = keyboard.nextLine();
    		System.out.print("Please enter weekly hours of working for employee1: ");//40
    		int hours = keyboard.nextInt();
    		System.out.print("Please enter hourly wage for employee1: ");//18
    		double hourlyWage = keyboard.nextDouble();
    		WeeklyPayroll employee1 = new WeeklyPayroll(name,hourlyWage,hours,grossPay);
    and here is the class WeeklyPayroll
    Code:
    	private String name;
    	private double hourlyWage;
    	private int hours;
    	private double grossPay;
    	
    	public WeeklyPayroll(){
    		name = "";
    		hourlyWage = 0.0;
    		hours = 0;
    		grossPay = 0.0;
    	}
    	
    	public WeeklyPayroll(String ininame, double inihourlyWage, int inihours, double inigrossPay){
    		name = ininame;
    		hourlyWage = inihourlyWage;
    		hours = inihours;
    		grossPay = inigrossPay;
    	}
    
    	public double getGrossPay(){
    		
    		double grossPay = 0.0;
    	 	   if(hours>40.0){  
    	 		   grossPay = (hours-40.0) * hourlyWage* 1.5+ 40.0 * hourlyWage; 
    	 	   }
    	 	   else{  
    	 		   grossPay = hourlyWage * hours;
    	 	   }
    	 	   
    	 	return grossPay;
    	}

    Thanks in advanced and I am just starting Java so all criticism is welcome. Sorry for being awful.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Is it complaining about WeeklyPayroll or about grossPay? I'm expecting that it is complaining about grossPay and not WeeklyPayroll.
    In the future make sure you post the actual error stack and not just a description of what it is.

  • #3
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I figured out my problem it was in the

    WeeklyPayroll employee1 = new WeeklyPayroll(name,hourlyWage,hours,grossPay);

    I didn't need the argument grossPay.


  •  

    Posting Permissions

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