我尽快在这段代码中得到帮助 [英] I need help in this code asap
问题描述
public void setSalary( double newSalary)
{
if (newSalary> = 0 。 0 )
{
Salary = new 薪资;
}
}
我的尝试:
本守则中的错误
薪水=新工资;
它一直说
错误:'('或'['预计
i继续把[]()放在这段代码中
没有什么改变我需要帮助
这是我正在做的代码
**************************** ***
public class 薪资 extends 员工
{
私有 double 薪水; // 年薪
public 薪水(字符串名称,字符串地址, int number,双薪水)
{
super (姓名,地址,号码);
setSalary(薪水);
}
public void mailCheck()
{
System.out.println( 在Salary类的邮件检查中);
System.out.println( 邮件检查到 + getName()+ with salary + salary);
}
public double getSalary()
{
返回工资;
}
public void setSalary( double newSalary)
{
if (newSalary> = 0 。 0 )
{
Salary = new 薪资;
}
}
public double computePay()
{
System.out.println( 计算 + getName()的工资薪水);
return salary / 52;
}
}
引用:它一直在说
错误:'('或'['期望
问题是你使用了错误的名字。
私人 double 薪水; // 年薪
public 薪资( 字符串名称,字符串地址, int 编号, double 薪水)
薪水
是变量
薪水
是函数名称
薪水= new 薪水;
你试图在函数名中保存一个值!
< BLOCKQUOTE>萨尔ary是班级
薪水是可变的
'='运算符在变量中赋值时使用。
薪水是班级名称。
班级名称不能用于变量。
所以工资=新工资;是无效代码。
如果你想将'私人双薪'改为newSalary。
使用以下代码。
salary = newSalary
错误:'('或'['预期表示新表达式构造函数需要'()'或'[]'
如果将代码更改为Salary = new Sarary();
发生其他错误工资不能是解决了一个变量。
如果你想创建新的Salary类。使用下面的代码。
薪资变量名=新薪水();
public void setSalary(double newSalary)
{
if(newSalary >= 0.0)
{
Salary = new Salary;
}
}
What I have tried:
Theres a error in this Code
Salary = new Salary;
it keeps saying
error: '(' or '[' expected
i keep putting [] () in this code
theres nothing that changes i need help
this is the code that im doing
*******************************
public class Salary extends Employee
{
private double salary;//Annual Salary
public Salary (String name, String address, int number , double salary)
{
super(name,address,number);
setSalary(salary);
}
public void mailCheck()
{
System.out.println("Within mailCheck of Salary class");
System.out.println("Mailing check to " + getName() + "with salary" + salary);
}
public double getSalary()
{
return salary;
}
public void setSalary(double newSalary)
{
if(newSalary >= 0.0)
{
Salary = new Salary;
}
}
public double computePay()
{
System.out.println("Computing Salary pay for" + getName());
return salary/52;
}
}
Quote:it keeps saying
error: '(' or '[' expected
The problem is that you use the wrong name.
private double salary;//Annual Salary public Salary (String name, String address, int number , double salary)
salary
is a variable
Salary
is a function name
Salary = new Salary;
you try to save a value in the function name !
Salary is Class
salary is variable
'=' operator using when assign new value in variable.
Salary is class name.
Class name couldn't using for variable.
So "Salary = new Salary;" is invalid code.
If you want change 'private double salary' to newSalary.
Using below code.
salary = newSalary
"error: '(' or '[' expected" means new expression constructor needs '()' or '[]'
If change code to "Salary = new Sarary();"
Other error occure "Salary cannot be resolved to a variable."
If you want create new Salary class. Using below code.
Salary variableName = new Salary();
这篇关于我尽快在这段代码中得到帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!