| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 661 人关注过本帖
标题:[求助]本人做C#时,遇到一点小问题,请大家帮帮忙!
取消只看楼主 加入收藏
kr1983
Rank: 1
等 级:新手上路
帖 子:21
专家分:0
注 册:2005-5-22
收藏
 问题点数:0 回复次数:3 
[求助]本人做C#时,遇到一点小问题,请大家帮帮忙!

本题中带两个参数的构造函数要求接受一个雇员所需的所有字段作为参数,并在其中调用CreateNewEmpolyee()方法。我的问题是不会在这个构造函数中调用CreateNewEmpolyee()方法,因为这个方法内的参数我怎么也传不进去!请大家帮忙,谢谢! using System;

class zuoYe1 { int EmployeeNo; int DaysPresent=3; string EmployeeName; string Department; string Designation; double HRA; double PF=5; double Salary; double EmployeeBasic;

public zuoYe1() { Department="SoftWare"; }

public zuoYe1(int eNo2,string eName2,string depart2,string design2) { this.CreateNewEmployee(int eNo2,string eName2,string depart2,string design2); //这里就是 我出错的地方,参数不知怎么传 }

public void CreateNewEmployee(int eNo,string eName,string depart,string design) { EmployeeNo=eNo; EmployeeName=eName; Department=depart; Designation=design; switch(Designation) { case("Manager"): EmployeeBasic=10000; HRA=2000; break; case("System Analyst"): EmployeeBasic=8000; HRA=1500; break; case("Project Leader"): EmployeeBasic=6000; HRA=1000; break; case("Programmer"): EmployeeBasic=5000; HRA=500; break; default: Console.WriteLine("您输入有错误,请重输!"); break; } }

public void ShowEmpInfo(int eNo) { Console.WriteLine("您的雇员号是:{0},您的姓名是:{1},您的部门是:{2},您的职位是:{3}",EmployeeNo,EmployeeName,Department,Designation); }

public void ShowEmpInfo(int eNo,int dPresent) { Salary=((EmployeeBasic/30)*DaysPresent)+((HRA/30)*DaysPresent)-PF; Console.WriteLine("您的雇员号是:{0},基本工资是:{1},HRA是:{2},工资是: {3}",EmployeeNo,EmployeeBasic,HRA,Salary); }

public static void Main(String[] args) { zuoYe1 zy1=new zuoYe1(001,"梅青","市场部","Project Leader"); zy1.ShowEmpInfo(001); zy1.ShowEmpInfo(001,25); //zuoYe1 zy2=new zuoYe1(); //zy2.CreateNewEmployee(002,"李伟","开发部","System Analyst"); //zy2.ShowEmpInfo(002); //zy2.ShowEmpInfo(002,30); } }

[此贴子已经被goodgoodstudy于2005-8-11 21:09:58编辑过]

2005-08-11 20:58
kr1983
Rank: 1
等 级:新手上路
帖 子:21
专家分:0
注 册:2005-5-22
收藏
得分:0 
不好意思,我再编辑一下!
2005-08-11 21:06
kr1983
Rank: 1
等 级:新手上路
帖 子:21
专家分:0
注 册:2005-5-22
收藏
得分:0 

using System;

class zuoYe1 { int EmployeeNo; int DaysPresent; string EmployeeName; string Department; string Designation; int EmployeeBasic; int HRA; int PF=2; int Salary;

public zuoYe1() { Department="Software"; }

public zuoYe1(int eNo,string eName,string depart,string design) { //呵呵,问题早上被我解决了,我把构造的参数传给几个变量,然后再把这几个变量传给CreateNewEmployee方法做参数,然后就对了。还是要谢谢大家的回复! int EmployeeNo2=eNo; string EmployeeName2=eName; string Department2=depart; string Designation2=design; this.CreateNewEmployee(EmployeeNo2,EmployeeName2,Department2,Designation2); }

houyunqing:好晕啊,最好还是别这样,降低效率~ public void CreateNewEmployee(int eNo,string eName,string depart,string design) { EmployeeNo=eNo; EmployeeName=eName; Department=depart; Designation=design; switch(Designation) { case("Manager"): EmployeeBasic=10000; HRA=2000; break; case("Project Leader"): EmployeeBasic=6000; HRA=1000; break; case("System Analyst"): EmployeeBasic=8000; HRA=1500; break; case("Programmer"): EmployeeBasic=5000; HRA=500; break; default: Console.WriteLine("您输入错误,请重输!"); break; } } public void ShowInfo(int eNo2) { Console.WriteLine("雇员号:{0},姓名:{1},部门:{2},职位:{3}",EmployeeNo,EmployeeName,Department,Designation); }

public void ShowInfo(int eNo2,int dutyDay) { DaysPresent=dutyDay; Salary=((EmployeeBasic/30)*DaysPresent)+((HRA/30)*DaysPresent)-PF; Console.WriteLine("雇员号:{0},基本工资:{1},HRA:{2},工资:{3}",EmployeeNo,EmployeeBasic,HRA,Salary); }

public static void Main() { zuoYe1 zy1=new zuoYe1(001,"老丈","开发部","Manager"); zy1.ShowInfo(001); } }

[此贴子已经被houyunqing于2005-8-13 10:03:54编辑过]

2005-08-12 19:29
kr1983
Rank: 1
等 级:新手上路
帖 子:21
专家分:0
注 册:2005-5-22
收藏
得分:0 
是的,我会继续打好基础,谢谢提醒了,哈!
2005-08-16 15:41
快速回复:[求助]本人做C#时,遇到一点小问题,请大家帮帮忙!
数据加载中...
 
   



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

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