/* This is the ConditionTester template. Use this class to test simple boolean methods! Coded by: Vikram Idury Date: 10/7/12 I did problems 15, 16, and 17. */ import java.util.Scanner; import java.awt.Color; public class ConditionTester { public static void main(String[ ] args) { Scanner kboard = new Scanner(System.in); // Copy-Paste more of these lines if more input is necessary System.out.print("Enter size1: "); int size1 = kboard.nextInt(); System.out.print("Enter size2: "); int size2 = kboard.nextInt(); System.out.print("Enter the space: "); int space = kboard.nextInt(); // Change this code so that it calls your testing method. ConditionTester tester = new ConditionTester(); int result = tester.findBestFit(size1, size2, space); // Printing out the result of the test! System.out.println("The result of the test: " + result); } // Finds if a point is in a rectangle with the given parameters. public boolean isPointInRectangle (int x, int y, int rectX, int rectY, int rectWidth, int rectHeight) { boolean result; if ((y <= rectY + rectHeight && y >= rectY) && (x <= rectX + rectWidth && x >= rectX)) result = true; else result = false; return result; } // Finds if a give year is a leap year. public boolean isLeapYear(int year) { boolean result; if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) result = true; else result = false; return result; } // Determines if the given number ends with two zeros. public boolean hasTwoEndingZeros(int x){ boolean result; if (x % 100 == 0 && x % 1000 != 0) result = true; else result = false; return result; } // Finds which of the given dates is later. public boolean isLater(int month1, int day1, int year1, int month2, int day2, int year2){ boolean result; if (year1 == year2 && month1 > month2 ||year1 == year2 && month1 == month2 && day1 > day2 || year1 > year2) result = true; else result = false; return result; } // Calculates the total of the order, given certain special deals. public static double getOrderTotal(int bp, int nb){ double result; if (bp == 1 && nb == 1) result = 37.95; else if (bp + nb >=3 && bp + nb < 12) result = 15.95 * (nb + bp); else if (bp + nb >= 12) result = 14.00 * (nb + bp); else result = 18.95 * bp + 21.95 * nb; return (double)((int)(result * 100 + .5))/100; } // Returns a color based on the values for red, green, and black public Color bestMatch(int r, int g, int b){ Color result = Color.GRAY; if (r > g && r > b) result = Color.RED; else if (g > r && g > b) result = Color.GREEN; else if (b > r && b > g) result = Color.BLUE; else if (r == g && r > b && g > b) result = Color.YELLOW; else if (r == b && r > g && b > g) result = Color.MAGENTA; else if (b == g && g > r && b > r) result = Color.CYAN; else result = Color.GRAY; return result; } // Returns a number for which file(s) would better fit in the given space. public int findBestFit(int size1, int size2, int space){ int result = 0; if (size1 + size2 <= space) result = 3; else if(size1 < space || size2 < space){ if (size1 >= size2) result = 1; else if (size2 > size1) result = 2; } else result = 0; return result; } }