import java.util.*; // Please note that this program is annotated with comments for us // and are not an example of how to write comments. Proper method // comments should describe parameters, returns, and what the // method does, rather than notes to other developers public class DatingAge { public static void main(String[] args) { /* // Wrong way to do everything!!!!! int minDatingAge; minDatingAge(42); */ Scanner console = new Scanner(System.in); System.out.print("Enter your age: "); int age = console.nextInt(); int minDatingAge = minDatingAge(age); System.out.println("Min dating age for " + age + ": " + minDatingAge(age)); int maxDatingAge = maxDatingAge(age); System.out.println("Max dating age for " + age + ": " + maxDatingAge); System.out.println(); System.out.print("Enter your honey's age: "); int otherAge = console.nextInt(); // if other person is less than minDatingAge -- ruh roh! // otherwise -- it's possible! // relational operators: >, <, >=, <=, ==, != // operator // join two+ tests: // test1 && test2 -- and // test1 || test2 -- or if (otherAge < minDatingAge || otherAge > maxDatingAge) { System.out.println("ruh roh!"); } else { System.out.println("it's possible!"); } /* Could also produce the same behaviour by switching the if / else above. if (otherAge >= minDatingAge && otherAge <= maxDatingAge) { System.out.println("it's possible!"); } else { System.out.println("ruh roh!"); } */ } // min dating age: age / 2 + 7; // Returns: // 1. what type of data you're returning // 2. return the data public static int minDatingAge(int age) { int minDatingAge = age / 2 + 7; return minDatingAge; } // max dating age: (age - 7) * 2 public static int maxDatingAge(int age) { int maxDatingAge = (age - 7) * 2; return maxDatingAge; } }