0% found this document useful (0 votes)
24 views

Week 01 Lab 00 Revision Method

The document discusses 5 methods - CalculateCommission, CalculateTax, Heron, CalculateLastDigitFrequency, and DisplayIntArray. For each method, it provides the name, arguments, return type, and description of what the method does.

Uploaded by

ulfany.guimel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

Week 01 Lab 00 Revision Method

The document discusses 5 methods - CalculateCommission, CalculateTax, Heron, CalculateLastDigitFrequency, and DisplayIntArray. For each method, it provides the name, arguments, return type, and description of what the method does.

Uploaded by

ulfany.guimel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

COMP123

Method Revision

For each of the method below, state the following: name, argument(s), return type and what it does

public static void CalculateCommission()


{ # 1:
Console.Write("Enter your sales amount: ");
double amount = Convert.ToDouble(Console.ReadLine());
double commission = (amount > 1000) ? (amount - 1000) * 0.25 : 0;
Console.WriteLine("For sales of {0:c} your commission is {1:c}", amount, commission);
}

Name: CalculateCommission

Argument(s): No argument

Return type: No return since is void

What it does: Calculates commissions based on user input and displays them for the number of sales
entered.

public static void CalculateTax(double price, string province)


{ # 2:
double tax = 0;
switch (province.ToUpper())
{
case "ON":
tax = price * 0.13;
break;
case "QC":
tax = price * 0.17;
break;
}
Console.WriteLine("An item of {0:c} in {1} will cost {2:c}", price, province, price + tax);
}

Name: CalculateTax

Argument(s): double representing the cost price and two-letter province code

Return type: Void

What it does: It calculates and displays the selling price of the item based on the province. If the
province is Ontario a tax of 13% is added to the price, if the province is Quebec a tax of 17% is added to
the cost price. There is no tax for the rest of the provinces and territories
public static double Heron(double a, double b, double c)
{
double s = (a + b + c) / 2; # 3:
return Math.Sqrt(s * (s - a) * (s - b) * (s - c));
}

Name: Heron

Argument(s) double a, double b, double c (doubles representing three sides of a triangle)

Return type double

What it does: Calculates and return the area of an specific triangle.

public static int[] CalculateLastDigitFrequency(int[] numbers)


{ # 4:
int[] result = new int[10];
foreach (int x in numbers)
result[x % 10]++;
return result;
}

Name: CalculateLastDigitFrequency

Argument(s): int[] numbers)

Return type: int

What it does: This method will create an int array of 10 elements

public static void DisplayIntArray(int[] array)


{ # 5:
foreach (int x in array)
Console.Write("{0} ", x);
}

Name: DisplayIntArray

Argument(s): int[] array (array of ints)

Return type: void

What it does: This method displays all the elements of the argument on a single line.

You might also like