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.

computer science

Description

 

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.

 

Requirements:a

  1. 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.
  2. You'll must complete all THREE problems listed below and all of these functions must exist within the same source file.
  3. 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.
  4. 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:

  1. 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.
  2. 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   The function call of "absolute(-3);" would return 3, not -3

o   "absolute(4);" returns 4 since the absolute value of a positive number is itself

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

o   "absolute(78.9);" would return 78.9

o   etc.

 

 

 



Related Questions in computer science category