问题描述
我有3种方法但我得到2个错误
错误1(方法''calculatePay''没有重载需要0个参数)
错误2(方法''DisplayPaySlip''没有重载需要0个参数)
I have 3 methods but i get 2 errors
Error1(No overload for method ''calculatePay'' takes 0 arguments)
Error2(No overload for method ''DisplayPaySlip'' takes 0 arguments)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Prac4_s208050509_
{
class Program
{
private static string message;
static void Main(string[] args)
{
string calc;
getDetails();
calc= calculatePay();
Console.WriteLine(calc);
DisplayPaySlip();
// Console.WriteLine(message);
// Console.ReadLine();
}
public static void getDetails()
{
string fullName;
string employeeNumber;
double noOfHoursWorked;
double hourlyRate;
//I've set the hourlyRate to 50 for there was no default hourly rate given
int count;
Console.WriteLine("Please enter the number of employees");
count = int.Parse(Console.ReadLine());
for(int i =0;i<= count;i++)
{
Console.Write("Please enter your full name:");
fullName = Console.ReadLine();
Console.Write("Please enter your employee number:");
employeeNumber = Console.ReadLine();
Console.Write("Please enter the amount of hours worked:");
noOfHoursWorked = double.Parse(Console.ReadLine());
Console.Write("Please enter your hourly rate:");
hourlyRate = double.Parse(Console.ReadLine());
// count++;
}
//hourlyRate ;
}
public static void calculatePay(ref double hourlyRate,ref double noOfHoursWorked)
{
//double overtime;
double weeklyPay;
if (noOfHoursWorked <= 40)
{
weeklyPay = noOfHoursWorked * hourlyRate;
Console.WriteLine("Weeekly Pay:",weeklyPay);
Console.ReadLine();
}
else
{
weeklyPay = (hourlyRate * 1.5)*noOfHoursWorked;
Console.WriteLine("Overtime Pay",weeklyPay);
Console.ReadLine();
}
}
public static void DisplayPaySlip( string fullName, double noOfHoursWorked, string employeeNumber,string hourlyRate, double weeklyPay)
{
string message;
message="Employee Number"+employeeNumber;
message += "Full Name"+fullName;
message += "Hours Worked"+noOfHoursWorked;
message += "Hourly Rate"+hourlyRate;
message += "Weekly Pay"+weeklyPay;
Console.WriteLine(message);
Console.ReadLine();
}
}
}
推荐答案
calc= calculatePay();
...
public static void calculatePay(ref double hourlyRate,ref double noOfHoursWorked)
和
And
DisplayPaySlip();
...
public static void DisplayPaySlip( string fullName, double noOfHoursWorked, string employeeNumber,string hourlyRate, double weeklyPay)
你已经声明了moth方法来获取参数,但是在调用方法时你没有提供它们。由于参数对于完成该方法的工作非常重要,因此在调用方法时,需要找到它们并提供它们!我也非常确定你想要从CalculatePay方法中返回一个值,而不是返回一个void - 并且没有充分的理由让你的参数 ref
不要(也不应该)改变它们。
You have declared moth methods to take parameters, but you are not supplying them when you call the methods. Since the parameters look pretty important to doing the job the method is intended to do, tyou need to find them and supply them when you call the methods! I''m also pretty sure you want to return a value from teh CalculatePay method, rather than return a void - and there is no good reason for making the parameters ref
since you don''t (and shouldn''t) change them.
double rate = 15.0;
double hours = 48.0;
calc = calculatePay(ref rate, ref hours);
DiaplyPaySlip("Joe Blogs", 48, "666", "15.0", calc);
BTW:为什么是你的hourlyRate DisplayPaySlip方法的字符串?当然最好像使用CalculatePay一样使用双倍?
BTW: Why is your hourlyRate a string for the DisplayPaySlip method? Surely it would be better to use a double like you do for CalculatePay?
calculatePay(hourlyRate, noOfHoursWorked)
DisplayPaySlip(fullName, noOfHoursWorked, employeeNumber, hourlyRate, weeklyPay)
getDetails()工作正常,因为没有输入参数。
Bye。
And getDetails() works fine because there is no input parameters.
Bye.
- 修改
getDetails
方法,以便将收集的数据提供给班级的其他成员(例如您可能有一个雇员列表作为类成员,并使getDetails
填写它。
- Modify
getDetails
method in order to make collected data available to other members of the class (for instance you may have a list of Employes as class member, and makegetDetails
fill it).
这篇关于方法调用的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!