Evaluation Problems Using Conditional Testing


Problem: Positive Integer Test

Write a JAVA program named IsPositiveInteger that prompts the user to enter a positive integer.

The program is to test the user input value to identify whether or not it is a positive integer (a value greater than or equal to zero).

As output, the program will display a message indicating that the user input value is or is not a positive integer.

Sample input/output:
user input: 7      display message: The value 7 is positive
user input: -33   display message: The value -33 is not positive
user input: 0      display message: The value 0 is positive

Initial Questions
Algorithm
Solution
Video

Problem: Absolute Value

Write a JAVA program named GetAbsVal. The program prompts the user to enter an integer (negative or positive). As output, the program will display the absolute value of that integer.

Note: You may not use the math library.

Note: Absolute value is always represented as a positive number. For instance, the absolute value of a positive number is that number, the absolute value of a negative number is the positive of that number.

examples:
abs(10) = 10   notated |10| = 10
abs(-10) = 10  notated |-10| = 10

Initial Questions
Algorithm
Solution
Sample Input/Output
Video

Problem: Square Test

Write a JAVA program named IsSquare that prompts the user to enter four integers representing the lengths of the four sides of a possible square.

As output, the program will display a message indicating whether or not the four sides are those of a square.

Sample input/output

Sample 1:
Input values:   s1 = 34, s2 = 34, s3 = 34, s4 = 34
Output:   The four sides represent those of a square.

Sample 2:
Input values   s1 = 34, s2 = 15, s3 = 34, s4 = 15
Output:   The four sides do not represent those of a square.

Initial Questions
Algorithm
Solution
Video

Problem: Rectangle Test

Write a JAVA program named IsRectangle that prompts the user to enter four integers representing the lengths of the four sides of a possible rectangle.

As output, the program will display a message indicating whether or not the four sides are those of a rectangle.

Note: for purposes of this program, a square (in which the lengths of all four sides are equal) will not be considered to be a rectangle.

Note: for purposes of this program, the degrees of each of the four angles need not to be taken into consideration.

Sample input/output

Sample 1:
Input values:   s1 = 34, s2 = 34, s3 = 96, s4 = 96
Output:   The four sides represent those of a rectangle.

Sample 2:
Input values:   s1 = 34, s2 = 34, s3 = 34, s4 = 34
Output:   The four sides do not represent those of a rectangle.

Sample 3:
Input values:   s1 = 34, s2 = 44, s3 = 63, s4 = 71
Output:   The four sides do not represent those of a rectangle.

Initial Questions
Algorithm
Solution
Video