Welcome to Gaia! ::


6,400 Points
  • Survivor 150
  • Somebody Likes You 100
  • Invisibility 100
TheAlmightyBeanDip
My IDE told me that I needed to replace the semicolon in
name = string;
salary = i;
and replace it with a comma. It's also telling me that in
private int salary;
private int bonus;
private String name;
"Syntax error on token 'String', strictfp expected". I do not know what that means.

Try this:

public class Employee
{

public Employee(String string, int i) {
}

private int salary = i;
private int bonus;
private String name = string;

//name = string;
//salary = i;

public String getName() {
return name;
}

public void setName(String param){
name = param;
}

public int getSalary() {
return salary;
}

public void addBonus(int i) {

}

public int getBonus() {
return bonus;
}

public void setSalary(int param) {
salary = param;
}

public int getSalary(int salary) {
return salary;
}

}
Kitten 4 Him
TheAlmightyBeanDip
My IDE told me that I needed to replace the semicolon in
name = string;
salary = i;
and replace it with a comma. It's also telling me that in
private int salary;
private int bonus;
private String name;
"Syntax error on token 'String', strictfp expected". I do not know what that means.

Try this:
private int salary = i; (-Watchpoint:Employee [access and modification] - salary)(i cannot be resolved)
private int bonus;
private String name = string; (string cannot be resolved)


Other error messages... It's like my IDE is cursed or something.

6,400 Points
  • Survivor 150
  • Somebody Likes You 100
  • Invisibility 100
You're missing a parenthesis:

Quote:
public class TestEmployee
{

public static void main(String[] arg)
{
System.out.println("Yetiware Computers: Payroll" wink ;

System.out.println();

System.out.println("*--------Employee--------*" wink ;

Employee e1 = new Employee("Jed Dye", 65000);
System.out.println("Employee name : " + e1.getName());
System.out.println("Salary before bonus: $" + e1.getSalary());
e1.addBonus(1500));
System.out.println("Bonus amount : $" + e1.getBonus());
System.out.println("Salary after bonus : $" + e1.getSalary());

System.out.println();

System.out.println("*--------Employee--------*" wink ;

Employee e2 = new Employee("Ginger Rayle", 48750);
System.out.println("Employee name: : " + e2.getName());
System.out.println("Salary before bonus: $" + e2.getSalary());
e2.addBonus(1125));
System.out.println("Bonus amount : $" + e2.getBonus());
System.out.println("Salary after bonus : $" + e2.getSalary());

System.out.println();
System.out.println("-Payroll Report Complete-" wink ;

}
}

8,950 Points
  • Gaian 50
  • Member 100
  • Contributor 150
Kitten 4 Him
First of all ... never EVER capitalize the first letter of a value. You only capitalize the name of a class. (Bonus should be bonus)

2nd - the way you have assigned your salary, bonus, and name are backwards in your Employee class. It should be:

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


The same goes for addBonus (when it's completed) and setSalary. Assignment goes from right to left.

For example:

int i;

i = 30;

i is now 30. It doesn't work if you have
30 = i;


The assignment is probably your main issue. Make a back-up copy of your work and try that. smile


EDIT: Is your compiler not throwing up any errors??? Check those as well. They are good indicators as to where to look.


I'm pretty sure you've got that backwards. This code is correct.
public void setName(String name) {
this.name = name;
}


This code is incorrect (and would accomplish absolutely nothing).
public void setName(String name) {
name = this.name;
}


this.name <-- is the 'name' property of the current instance of the object.
name <-- is the value being passed into the method.

name = this.name; <-- This would set the 'name' parameter to the value of the the current instance's 'name' property. When the function exits, 'name' is popped off the stack and the change is lost anyways.

this.name = name; <-- This would set the current instance's 'name' property to the value just passed into the function (which is probably what he wanted to do).

Edit:
@TheAlmightyBeanDip: can you post your current source on Pastebin plz?
Kitten 4 Him
You're missing a parenthesis:

Quote:
public class TestEmployee
{

public static void main(String[] arg)
{
System.out.println("Yetiware Computers: Payroll" wink ;

System.out.println();

System.out.println("*--------Employee--------*" wink ;

Employee e1 = new Employee("Jed Dye", 65000);
System.out.println("Employee name : " + e1.getName());
System.out.println("Salary before bonus: $" + e1.getSalary());
e1.addBonus(1500));
System.out.println("Bonus amount : $" + e1.getBonus());
System.out.println("Salary after bonus : $" + e1.getSalary());

System.out.println();

System.out.println("*--------Employee--------*" wink ;

Employee e2 = new Employee("Ginger Rayle", 48750);
System.out.println("Employee name: : " + e2.getName());
System.out.println("Salary before bonus: $" + e2.getSalary());
e2.addBonus(1125));
System.out.println("Bonus amount : $" + e2.getBonus());
System.out.println("Salary after bonus : $" + e2.getSalary());

System.out.println();
System.out.println("-Payroll Report Complete-" wink ;

}
}


It's telling me to delete those, and even when I choose to ignore it and run with what you're saying, it won't run the program. It's viewing your revisions as errors...

6,400 Points
  • Survivor 150
  • Somebody Likes You 100
  • Invisibility 100
To avoid confusion on the part of the user, the resolution (for that) is to change the parameter to something else.

then:

name = parameter;


would work.

8,950 Points
  • Gaian 50
  • Member 100
  • Contributor 150
TheAlmightyBeanDip
Kitten 4 Him
You're missing a parenthesis:

Quote:
public class TestEmployee
{

public static void main(String[] arg)
{
System.out.println("Yetiware Computers: Payroll" wink ;

System.out.println();

System.out.println("*--------Employee--------*" wink ;

Employee e1 = new Employee("Jed Dye", 65000);
System.out.println("Employee name : " + e1.getName());
System.out.println("Salary before bonus: $" + e1.getSalary());
e1.addBonus(1500));
System.out.println("Bonus amount : $" + e1.getBonus());
System.out.println("Salary after bonus : $" + e1.getSalary());

System.out.println();

System.out.println("*--------Employee--------*" wink ;

Employee e2 = new Employee("Ginger Rayle", 48750);
System.out.println("Employee name: : " + e2.getName());
System.out.println("Salary before bonus: $" + e2.getSalary());
e2.addBonus(1125));
System.out.println("Bonus amount : $" + e2.getBonus());
System.out.println("Salary after bonus : $" + e2.getSalary());

System.out.println();
System.out.println("-Payroll Report Complete-" wink ;

}
}


It's telling me to delete those, and even when I choose to ignore it and run with what you're saying, it won't run the program. It's viewing your revisions as errors...
That's because they are errors. I don't think Kitten 4 Him is giving you the best advice.

6,400 Points
  • Survivor 150
  • Somebody Likes You 100
  • Invisibility 100
TheAlmightyBeanDip
It's telling me to delete those, and even when I choose to ignore it and run with what you're saying, it won't run the program. It's viewing your revisions as errors...

I misread the post and thought your e2.addBonus() call was part of the println. Please undo.

8,950 Points
  • Gaian 50
  • Member 100
  • Contributor 150
Kitten 4 Him
To avoid confusion on the part of the user, the resolution (for that) is to change the parameter to something else.

then:

name = parameter;


would work.
Yes, but the idiom is widespread and exists for a good reason. Javadoc.

8,950 Points
  • Gaian 50
  • Member 100
  • Contributor 150
Please use Pastebin. Gaia's broken code tags ******** up the formatting...

6,400 Points
  • Survivor 150
  • Somebody Likes You 100
  • Invisibility 100
public class Employee
{

private int salary;
private int bonus;
private String name;

public Employee(String string, int i) {
name = string;
salary = i;
}

public String getName() {
return name;
}

public void setName(String param){
name = param;
}

public int getSalary() {
return salary;
}

public void addBonus(int i) {

}

public int getBonus() {
return bonus;
}

public void setSalary(int param) {
salary = param;
}

public int getSalary() {
return salary;
}

}




public class TestEmployee
{

public static void main(String[] arg)
{
System.out.println("Yetiware Computers: Payroll")

System.out.println()

System.out.println("*--------Employee--------*")

Employee e1 = new Employee("Jed Dye", 65000)
System.out.println("Employee name : " + e1.getName())
System.out.println("Salary before bonus: $" + e1.getSalary())
e1.addBonus(1500)
System.out.println("Bonus amount : $" + e1.getBonus())
System.out.println("Salary after bonus : $" + e1.getSalary())

System.out.println()

System.out.println("*--------Employee--------*")

Employee e2 = new Employee("Ginger Rayle", 48750)
System.out.println("Employee name: : " + e2.getName())
System.out.println("Salary before bonus: $" + e2.getSalary())
e2.addBonus(1125)
System.out.println("Bonus amount : $" + e2.getBonus())
System.out.println("Salary after bonus : $" + e2.getSalary())

System.out.println()
System.out.println("-Payroll Report Complete-")

}
}
Kitten 4 Him
To avoid confusion on the part of the user, the resolution (for that) is to change the parameter to something else.

then:

name = parameter;


would work.


So I need to change the things inside the parenthesis of "public Employee(String string, int i)"?

6,400 Points
  • Survivor 150
  • Somebody Likes You 100
  • Invisibility 100
TheAlmightyBeanDip
Kitten 4 Him
To avoid confusion on the part of the user, the resolution (for that) is to change the parameter to something else.

then:

name = parameter;


would work.


So I need to change the things inside the parenthesis of "public Employee(String string, int i)"?

Ignore my comment to previous Gaians.

Look at the code I provided. Do you see what's different in the top section of mine from yours?

Your method public Employee(String string, int i) did nothing and came before your private variables.

I moved the variables to be before this method. This method is also where the variables will be set. Try it again.
Kitten 4 Him
TheAlmightyBeanDip
Kitten 4 Him
To avoid confusion on the part of the user, the resolution (for that) is to change the parameter to something else.

then:

name = parameter;


would work.


So I need to change the things inside the parenthesis of "public Employee(String string, int i)"?

Ignore my comment to previous Gaians.

Look at the code I provided. Do you see what's different in the top section of mind from yours?

Your method public Employee(String string, int i) did nothing and came before your private variables.

I moved the variables to be before this method. This method is also where the variables will be set. Try it again.


Wow it works a bit this time! The bonus doesn't come up however, and is still viewed as $0, while everything else works fine.

8,950 Points
  • Gaian 50
  • Member 100
  • Contributor 150
TheAlmightyBeanDip
Kitten 4 Him
TheAlmightyBeanDip
Kitten 4 Him
To avoid confusion on the part of the user, the resolution (for that) is to change the parameter to something else.

then:

name = parameter;


would work.


So I need to change the things inside the parenthesis of "public Employee(String string, int i)"?

Ignore my comment to previous Gaians.

Look at the code I provided. Do you see what's different in the top section of mind from yours?

Your method public Employee(String string, int i) did nothing and came before your private variables.

I moved the variables to be before this method. This method is also where the variables will be set. Try it again.


Wow it works a bit this time! The bonus doesn't come up however, and is still viewed as $0, while everything else works fine.
Pastebin...plz?

Quick Reply

Submit
Manage Your Items
Other Stuff
Get GCash
Offers
Get Items
More Items
Where Everyone Hangs Out
Other Community Areas
Virtual Spaces
Fun Stuff
Gaia's Games
Mini-Games
Play with GCash
Play with Platinum