Conditional.java

Resource The Java Documentation will come in handy. To find the String and ArrayList classes, just use the search box in the upper right-hand corner of the page.

Shell CodeDownload the shell file Conditional.java on the left. The comments in the file tell you what to do.

Scoring Each correctly coded method is worth 5 points. Test code for each method is worth 5 points also. It is important you test all branches and border cases.

The file is shown here if you'd like to copy and paste it.

public class Conditional
{
    /**
     * This computes the positive part of a number
     * @param x the number we are computing the positive  part of
     * @return x if x > 0 and 0 otherwise.
     */
    public static double positivePart(double x)
    {
        return 0;
    }
    /**
     * This computes the negative part of a number
     * @param x the number we are computing the negative  part of
     * @return -x if x < 0 and 0 otherwise.
     */
    public static double negativePart(double x)
    {
        return 0;
    }
    /**
     * This prints PASS for true and FAIL for false.
     * @param b the boolean
     * @return "PASS" for true and "FAIL" for false
     */
    public static String tester(boolean b)
    {
        return b? "PASS":"FAIL";
    }
    /**
     * Use this to check sufficient closeness of floating-point numbers
     */
    public static boolean closeEnough(double x, double y)
    {
        return Math.abs(x - y) < 1e-6;
    }
    /**
     * This implements a stepwise defined function
     * @param x the argument of this function
     * @return 4 - x*x if x < -2, 0 if |x| <= 2 and x - 2 otherwise
     */
    public static double mathCheese(double x)
    {
        return 0;
    }
    /**
     * This checks if an alphabetical string is in the
     * first half of the alphabeet.
     * @param s the String to be checked; this string must contain
     * only alphabetical characters and this check is case-insensitive
     * @return true if the s starts with a-m and false otherwise.
     */
    public static boolean isInFirstHalfOfAlphabet(String s)
    {
        return false;
    }
    /**
     * This assigns a letter grade on a ten-point scale
     * @param score a final average of grades
     * @return "A" if the score is 90 or above, "B" if the score is 
     * 80 or above, etc.  IF the score is under 60, return "F"
     */
    public static String assignLetterGrade(int score)
    {
        return "";
    }
    /**
     * This implements +/- grading.  The grade of F gets no +- modifier.
     * @return "+" if the second digit of the grade is 8 or higher,
     * a "-" if the second digit of the grade is 2 or lower, and
     * a "" otherwise.  Special note: any score of 98 or higher is an A+;
     * an average can exceed 100.
     */
    public static String assignPlusMinus(int score)
    {
        return "";
    }
    /**
     * This assigns the full grade
     * @param score the final average
     * @return a +- grade for the average
     */
    public static String assignGrade(int score)
    {
        return "";
    }
    public static void main(String[] args)
    {
        //test all of  your functions in here.  Example
        System.out.println("Testing positivePart:");
        double x = 5;
        System.out.printf("Case x = %s: %s\n",  x,  closeEnough(5, positivePart(x)));
        x = 0;
        System.out.printf("Case x = %s: %s\n",  x,  closeEnough(0, positivePart(x)));
        x = -5;
        System.out.printf("Case x = %s: %s\n",  x,  closeEnough(0, positivePart(x)));
        System.out.println("Testing negativePart:");
        System.out.println("Testing mathCheese:");
        System.out.println("Testing isInFirstHalfOfAlphabet:");
        String test = "naiman";
        System.out.printf("Case x = %s: %s\n", test , !isInFirstHalfOfAlphabet(test)); 
        System.out.println("Testing assignGrade:");
    }
}

If you got it all right, the program prints nothing but PASS.