| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 496 人关注过本帖
标题:[讨论]这样写对不对呢!?
只看楼主 加入收藏
ada518618
Rank: 1
等 级:新手上路
帖 子:184
专家分:0
注 册:2006-3-27
收藏
 问题点数:0 回复次数:4 
[讨论]这样写对不对呢!?
//文件名为Employee.java
public class Employee
{
private String name;
private double salary;
private int dep_number;

public Employee (String n,double s)
{
name=n;
salary=s;
}
public void set_dep(int dep_num)
{
dep_number=dep_num;
}
public int show__depNo()
{
return dep_number;
}
public void setSalary(double s)
{
salary=s;
}
public void raiseSalary(double by_percent)
{
salary=salary*(1+by_percent);
}
public double getSalary()
{
return salary;
}
}
class Manager extends Employee
{
private String secretaryName;
private int dep_num;
public Manager(String n,double s,int dep_num)
{
super (n,s);
this.dep_num=dep_num;
}
public void setSecretary(String name)
{

secretaryName=name;
}
public String getSecretaryName()
{
return secretaryName;
}
}
class ManagerTest
{
public static void main(String args[])
{
Manager manager_1=new Manager("Annie",41000,2);
manager_1.setSecretaryName("Mariee");
manager_1.raiseSalary(0.01);
System.out.println("The manager's salary is "+manager_1.getSalary());
}
}
class ManagerWithOverWriTest
{
public static void main(String args[])
{
ManagerWithOverWri manager_1=new ManagerWithOverWri("Annie",4100,2);
manager_1.setSecretary("Mariee");
manager_1.raiseSalary(0.01);
System.out.println("The manager's salary is "+manager_1.getSalary());
}
}
要求输出结果为:
call raiseSalary method in Manager
The manager's secretary is Mariee
The manager's salary is 43460.0
不知道会不会又是书上的错误!?
麻烦大家帮我看一下啦!
2006-04-15 12:13
千里冰封
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:灌水之王
等 级:版主
威 望:155
帖 子:28477
专家分:59
注 册:2006-2-26
收藏
得分:0 
public class Employee
{
private String name;
private double salary;
private int dep_number;

public Employee (String n,double s)
{
name=n;
salary=s;
}
public void set_dep(int dep_num)
{
dep_number=dep_num;
}
public int show__depNo()
{
return dep_number;
}
public void setSalary(double s)
{
salary=s;
}
public void raiseSalary(double by_percent)
{
salary=salary*(1+by_percent);
}
public double getSalary()
{
return salary;
}
}
class Manager extends Employee
{
private String secretaryName;
private int dep_num;
public Manager(String n,double s,int dep_num)
{
super (n,s);
this.dep_num=dep_num;
}
public void setSecretary(String name)
{

secretaryName=name;
}
public String getSecretaryName()
{
return secretaryName;
}
}
class ManagerTest
{
public static void main(String args[])
{
Manager manager_1=new Manager("Annie",41000,2);
manager_1.setSecretaryName("Mariee");//你的方法名写错了
manager_1.raiseSalary(0.01);
System.out.println("The manager's salary is "+manager_1.getSalary());
}
}
class ManagerWithOverWriTest
{
public static void main(String args[])
{
ManagerWithOverWri manager_1=new ManagerWithOverWri("Annie",4100,2);//这是什么类
manager_1.setSecretary("Mariee");
manager_1.raiseSalary(0.01);
System.out.println("The manager's salary is "+manager_1.getSalary());
}
}
编译的时候,根据编译器的提示怎么会找不到错误呢??
应该相当容易找的,编译器会告诉你哪一行错了,你去这一行一个一个字的找,我就不相信找不出来

可惜不是你,陪我到最后
2006-04-15 13:17
ada518618
Rank: 1
等 级:新手上路
帖 子:184
专家分:0
注 册:2006-3-27
收藏
得分:0 


manager_1.setSecretaryName("Mariee");//
manager_1.setSecretaryName("Mariee");


Eclipse!尽管我现在不懂祢,可是我却对你情有独钟……
2006-04-15 13:38
ada518618
Rank: 1
等 级:新手上路
帖 子:184
专家分:0
注 册:2006-3-27
收藏
得分:0 

我的书太垃圾了!真的!已经错了8处了!我都不知道还该不该看了!
谢啦!斑竹!


Eclipse!尽管我现在不懂祢,可是我却对你情有独钟……
2006-04-15 13:43
千里冰封
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:灌水之王
等 级:版主
威 望:155
帖 子:28477
专家分:59
注 册:2006-2-26
收藏
得分:0 
千万不要太相信书,因为书也是人写的,并且打进去的时候就有可能会有大小写错误或者别的错误,特别是编程方面的书,错一个字母就运行不了了

可惜不是你,陪我到最后
2006-04-15 16:15
快速回复:[讨论]这样写对不对呢!?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019113 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved