Beta

Method Overloading: Operating on basic data types.

Description:

Explanation

Method overloading is useful when accepting multiple different data types. Many objects have multiple different methods with the same name: the input that the method receives determines which method is used.

Method overloading allows the same named method to output different results depending on the parameters. Alternatively, returning generic Objects works fine too, so long as the Objects returned are the correct types. In strongly-typed languages, like Java and C#, overloading is more important than it is in languages like Python and Ruby. Overloading is similar to overriding, except that it occurs inside the class itself, as opposed to taking a method from a parent class and redefining it.

Problem

In this problem, you are given a helper class by the name of Operate. You need to define four methods, Add, Sub, Mult, and Div. Each method will have a different output based on the input given. There also will be a base method that will be called if the inputs do not fall into the allowed categories that should output "Invalid Types."

Addition

// This is what addition should look like
Ops.Operate.Add(10, 10) == 20; // Integers
Ops.Operate.Add(2.5, 3.3) == 5.8; // Doubles
Ops.Operate.Add("C", "#") == "C#"; // Strings
Ops.Operate.Add('a', 3) == 'd'; // Char
Ops.Operate.Add(true, false) == true; // Bool is an OR statement for add

Any other parameter combinations should output "Invalid Types"

Subtraction

// This is what subtraction should look like
Ops.Operate.Sub(5, 3) == 2; // Integers
Ops.Operate.Sub(6.4, 2.3) == 4.1; // Doubles
Ops.Operate.Sub('d', 2) == 'b'; // Char
Ops.Operate.Sub("Hello World!", "orl") == "He Wd!"; // String
Ops.Operate.Sub(true, false) == false; // Bool is a NOR statement for subtract

Multiplication

// This is what multiplication should look like
Ops.Operate.Mult(5, 3) == 15; // Integers
Ops.Operate.Mult(1.2, 1.2) == 1.44; // Doubles
Ops.Operate.Mult("Hello", 3) == "HelloHelloHello"; // Strings
Ops.Operate.Mult(true, false) == false // Bool is an AND statement for multiplication

Division

// This is what division should look like
Ops.Operate.Div(7, 5) == 1; // Integers
Ops.Operate.Div(9.0, 5.0) == 1.8; // Doubles
Ops.Operate.Div(true, false) == true; // Bool is an XOR statement for division

The only data types that you need to worry about are ints, chars, strings, bools, and doubles (in C#). All other data types do not matter in this problem, and should return "Invalid Types."

Object-oriented Programming
Fundamentals

Stats:

CreatedFeb 23, 2021
PublishedMar 10, 2021
Warriors Trained72
Total Skips5
Total Code Submissions163
Total Times Completed15
C# Completions15
Total Stars4
% of votes with a positive feedback rating30% of 5
Total "Very Satisfied" Votes0
Total "Somewhat Satisfied" Votes3
Total "Not Satisfied" Votes2
Total Rank Assessments5
Average Assessed Rank
7 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • Deathbycalculus3 Avatar
  • hobovsky Avatar
Ad