Created
September 23, 2023 04:33
-
-
Save stevenvelozo/7f7713dd9d8fe00ee47da2ce8bf5d69b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * Homework.java | |
| * | |
| * Version: 1.0 | |
| * | |
| * 1: Take an integer input from the user. | |
| * Value of x | |
| * 2: Determine if the number is even or odd. | |
| * Value of x_is_odd | |
| * 3: Display the number and whether it is even or odd to the user. | |
| * oddness_name = (x_is_odd) ? "odd" : "even"; | |
| * "The integer x is oddness_name." | |
| * Note to self: we need a string to tell the user if odd or even; the boolean value is janky. | |
| * 4: Profit. | |
| * | |
| * | |
| * 5: Bonus: Categorize the number on a scale of whether or not you could afford a car in 2023, Seattle, Washington. | |
| * input: x | |
| * output: The Aesop Car Affordability Spectrum(TM) | |
| * spectrum: | |
| * low = 0-599 | |
| * high = 600-1199 | |
| * enough to afford a car = 1200-14999 | |
| * ginormous = 15000+ | |
| */ | |
| import java.io.*; | |
| import java.util.Scanner; | |
| class Homework | |
| { | |
| public static void main(String[] args) | |
| { | |
| // Declare variables | |
| int x; | |
| boolean x_is_odd; | |
| // 1a. Prompt the User for Input | |
| System.out.println("Please input an integer for me to divine its oddness: "); | |
| // Initialize the command line scanner object | |
| Scanner scannerInput = new Scanner(System.in); | |
| // 1b. Read an Integer from the user | |
| x = scannerInput.nextInt(); | |
| // 2. Determine if the number is even or odd | |
| x_is_odd = (x % 2 == 1); | |
| // 3. Display the oddness result | |
| String oddness_name; | |
| if (x_is_odd) | |
| { | |
| oddness_name = "odd"; | |
| } | |
| else | |
| { | |
| oddness_name = "even"; | |
| } | |
| // 4. Profit | |
| // 5. Bonus: Categorize the number on a scale of whether or not you could afford a car in 2023, Seattle, Washington. | |
| String affordability_name; | |
| if (x < 600) | |
| { | |
| affordability_name = "low"; | |
| } | |
| else if (x < 1200) | |
| { | |
| affordability_name = "high"; | |
| } | |
| else if (x < 15000) | |
| { | |
| affordability_name = "enough to afford a car"; | |
| } | |
| else | |
| { | |
| affordability_name = "ginormous"; | |
| } | |
| System.out.println("We have divined that the integer " + x + " is " + oddness_name + " and your affordability range for cars is " + affordability_name + ". You would need about 1,200 dollars to afford a car in 2023, Seattle, Washington."); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment