FunctionX Logo

Passing Arguments to a Method

 

Introduction

This is an example that contains arrays and displays menus to process ice cream order processing

First Version

using System;

public class Payroll
{
	static double WeeklyWage(double WeeklyHours, double HourlySalary)
	{
		double Total = WeeklyHours * HourlySalary;
		return Total;
	}

	static string GetName()
	{
		string FirstName, LastName, FN;
	
		FirstName = "Georgette";
		LastName = "Samsons";
	
		FN = FirstName + " " + LastName;
		return FN;
	}

	static double GetHours(string FullName)
	{
		double Monday, Tuesday, Wednesday, Thursday, Friday, TotalHours;
		Monday = 8.00;
		Tuesday = 8.50;
		Wednesday = 8.50;
		Thursday = 7.50;
		Friday = 9;
		
		TotalHours = Monday + Tuesday + Wednesday + Thursday + Friday;
		return TotalHours;
	}

	static void Main()
	{
		string FullName;
		double Hours, Weekly;
	
		FullName = GetName();
		Hours = GetHours(FullName);
		Weekly = WeeklyWage(Hours, 12.55);
	
		Console.WriteLine("Employee's Payroll");
		Console.Write("Full Name:      ");
		Console.WriteLine(FullName);
		Console.Write("Weekly Hours:   ");
		Console.Write(Hours);
		Console.WriteLine(" hours");
		Console.Write("Weekly Salary:  ");
		Console.WriteLine(Weekly);

		Console.Write("\n");
	}
}
 

Another Version

using System;

public class Payroll
{
	static double WeeklyWage(double WeeklyHours, double HourlySalary)
	{
		double Total = WeeklyHours * HourlySalary;
		return Total;
	}

	static string GetName()
	{
		string FirstName, LastName, FN;
	
		FirstName = "Georgette";
		LastName = "Samsons";
	
		FN = FirstName + " " + LastName;
		return FN;
	}

	static double GetHours(string FullName)
	{
		double Monday, Tuesday, Wednesday, Thursday, Friday, TotalHours;
		Monday = 8.00;
		Tuesday = 8.50;
		Wednesday = 8.50;
		Thursday = 7.50;
		Friday = 9;
		
		TotalHours = Monday + Tuesday + Wednesday + Thursday + Friday;
		return TotalHours;
	}

	static double GetHourlySalary()
	{
		double HSalary;
	/*	string SalValue;

		Console.Write("Enter Hourly Salary: ");
		SalValue = Console.ReadLine();
		HSalary = double.Parse(SalValue);
	*/
		HSalary = 14.55;
		return HSalary;
	}

	static void DisplayPayroll(string Name, double Hours, double HSalary, double WSalary)
	{
		Console.WriteLine("Employee's Payroll");
		Console.Write("Full Name:      ");
		Console.WriteLine(Name);
		Console.Write("Weekly Hours:   ");
		Console.Write(Hours);
		Console.WriteLine(" hours");
		Console.Write("Hourly Salary:  ");
		Console.WriteLine(HSalary);
		Console.Write("Weekly Salary:  ");
		Console.WriteLine(WSalary);
	}

	static void Main()
	{
		string FullName;
		double Hours, Hourly, Weekly;
	
		FullName = GetName();
		Hours    = GetHours(FullName);
		Hourly   = GetHourlySalary();
		Weekly   = WeeklyWage(Hours, Hourly);
	
		DisplayPayroll(FullName, Hours, Hourly, Weekly);

		Console.Write("\n");
	}
}
 

Home Copyright 2004-2005 FunctionX, Inc.