Question: Write a program which contains various functions in it that do various things. See descriptions on the next several pages for info on each function's

Write a program which contains various functions in it that do various things. See descriptions on the next several pages for info on each function's specifications.

//SOLVE USING SIMPLE JAVA LANGUAGE

Requirements:

As per usual, be sure to leave some comments (in your code, for each problem) on how certain complex / unique parts of your program work.

You'll must complete all THREE problems listed below and all of these functions must exist within the same source file.

Be sure to follow the instructions outlined for each function exactly as described. This includes small things such as using the right data types for your parameters, the spelling of each functions' name, having the correct return types, etc.

Do NOT use any external / existing functions found in the standard Java library (or anywhere else for that matter) in any of your code. All these problems can be completed by utilizing all the basic coding concepts we've learned throughout the course.

For example, don't use the "pow()" function found in the 'Math' class.

You can of course still use "System.out" for printing stuff to output, where appropriate.

Tips:

Your main method does NOT need to have any code in it.

Ideally, you would use it for testing purposes to see if the output / return results of some function calls (with various arguments) works out as expected. What's important for this assignment is that all the function definitions you created are formatted correctly and work as expected / described in these instructions.

The problems are ordered from easiest-to-hardest with Question #1 being the easiest and Question #3 [debatable] being the hardest.

1. Absolute value function (4 points)

Create a function, named "absolute", which has one integer parameter and returns (NOT print) what the absolute value of said parameter is.

Also, create an overloaded function which has a 'double' parameter instead.

For examples:

o "absolute(-3);" should return 3

o "absolute(4);" should return 4

o "absolute(-5.6);" should return 5.6

o "absolute(78.909);" should return 78.909

o etc.

2. Binomial coefficient function (6 points)

Create a function, named "binomialCoefficient", that takes two integer parameters (which you can assume will always be non-negative), labeled 'n' and 'r' in that respective order, and returns (NOT print) what the binomial coefficient between these two factors is.

NOTE: Even though this concept was skipped in Lecture 3, don't worry about overflow occurring; using the integer data type for a problem like this is [realistically] not ideal but for our sake is serviceable.

For examples:

o "binomialCoefficient(7, 2);" should return 21

o "binomialCoefficient(6, 2);" should return 15

o "binomialCoefficient(3, 1);" should return 3

o "binomialCoefficient(10, 10);" should return 1

o "binomialCoefficient(9, 0);" should return 1

o etc.

If you're not sure how to calculate this, here's a link that briefly showcases how this value is found: http://www.mathwords.com/b/binomial_coefficients.htm.

o NOTE: You can assume that the argument for 'n' will never be less than 'r'.

IMPORTANT RULE: You CANNOT solve this problem using recursion, otherwise you will lose points (even if its correct).

TIP: I recommend that you create a helper function which focuses on calculating / returning the factorial of a given number, this way the only real work that would need to be done in the binomial function is basic math on the three, needed factorial values.

Once again, if you're not sure how to calculate this, then check out this link: http://www.mathwords.com/f/factorial.htm

3. Printing a graph function (8 points)

Create a VOID function, named "printGraph", that takes one integer parameter and prints (NOT return) what a typical Cartesian graph, given said argument acting as a 'size', would be (as seen in examples below).

o REQUIREMENT: Do not have anything outputted if the argument is less than 1.

o TIP: Ideally, this should work for any given size though (for testing purposes) you can assume the value will never be greater than 7. Although ...

... make sure that you don't just hardcode a bunch of "if" / print statements (since doing so will cost you [some] credit) as you should use typical loop logic to go through each "row / column" to see which character(s) should be printed.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!