修复我尝试过的代码,但xd很难 [英] Fix the code I tried but xd its hard

查看:114
本文介绍了修复我尝试过的代码,但xd很难的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

本规范中的许多错误(薪水)我需要帮助



  public   class 薪资 extends 员工
{
private double salary; // 年薪
public 薪资(字符串名称,字符串地址, int 编号, int double 薪水)
{
super (姓名,地址,号码);
setSalary(薪水);
}
public void mailCheck()
{
System.out println( 在Salary类的邮件检查中);
System.out println( 邮件检查到 + getName()+ 薪水 +薪水);
}
public double getSalary()
{
返回工资;
}
public void setSalary( double newSalary)
{
if (newSalary> = 0 0
{
Salary = new 薪资;
}
}
public double computePay()
{
System.out.println( 计算 + getName()的工资薪水);
return salary / 52;
}
}





我的尝试:



它给了我一个头疼的代码XD

解决方案

首先查看错误消息,然后是行参考:可能第一个错误就在这一行:

 public Salary(String name,String address,int number,int double salary)

什么是 int double double 是一个浮点数, int 不是 - 你可以;只是将它们组合起来并希望系统找出你的意思!

拿出 int 类型,这应该删除一些错误。

 public Salary(String name,String address,int number,double salary)

接下来我能看到的是这一行:

系统.out println(在工资类的mailCheck中); 

你在 out println之间有空格。你觉得他们之间应该怎么样?



在每一行都抱怨并仔细阅读 - 此刻我怀疑你正在阅读你的意思写而不是你实际做的。这很容易做到 - 我一直这样做 - 但你必须弄清楚编译器正在讨论的内容,并记住一个错误可能导致其他错误,因为编译器对你写的意思感到困惑。 / BLOCKQUOTE>

Theres Many Errors in this Code (Salary) i need help

public class Salary extends Employee
{
	private double salary;//Annual Salary
	public Salary (String name, String address, int number , int 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;
	}
}



What I have tried:

it gives me a head ache in this Code XD

解决方案

Start by looking at the error messages, and the lines they refer to: probably the first error is on this line:

public Salary (String name, String address, int number , int double salary)

What is an int double? A double is a floating point number, an int is not - you can;t just combine them and hope the system works out what you meant!
Take out the int type and that should remove some errors.

public Salary (String name, String address, int number , double salary)

Then the next I can see is this line:

System.out println("Within mailCheck of Salary class");

Where you have a space between out and println. What do you think should be between them?

LOok at each line it is complaining about and read it carefully - at the moment I suspect you are reading what you meant to write instead of what you actually did. That's easy to do - I do it all the time - but you have to work out what the compiler is talking about, and remember that one error can cause others because the compiler gets "confused" as to what you did mean to write.


这篇关于修复我尝试过的代码,但xd很难的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆