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 09-15-2011, 05:57 AM   PM User | #1
wr3tched
New to the CF scene

 
Join Date: Sep 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
wr3tched is an unknown quantity at this point
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.
wr3tched is offline   Reply With Quote
Old 09-15-2011, 03:28 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
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
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.
Fou-Lu is offline   Reply With Quote
Old 09-15-2011, 09:01 PM   PM User | #3
wr3tched
New to the CF scene

 
Join Date: Sep 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
wr3tched is an unknown quantity at this point
I figured out my problem it was in the

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

I didn't need the argument grossPay.
wr3tched 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 12:09 PM.


Advertisement
Log in to turn off these ads.