Created
January 25, 2017 04:50
-
-
Save TheEmpty/15aaf745cb3d6ff0f2cbac7ac46e9159 to your computer and use it in GitHub Desktop.
Girlfriend's C++ Homework in Clojure
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
(ns keyboard-calculator.core (:gen-class)) | |
(def number-of-regular-keys 89) | |
(def number-of-special-keys 14) | |
(defn get-width-height | |
[cin object] | |
(print (str "Width of " object ": ")) | |
(flush) | |
(let [width (.nextDouble cin)] | |
(print (str "Height of " object ": ")) | |
(flush) | |
{:width width :height (.nextDouble cin)})) | |
(defn get-area | |
[m] | |
(* (:width m) (:height m))) | |
(defn num-format | |
[num] | |
(.format (java.text.DecimalFormat. "#.###") num)) | |
(defn -main | |
[& args] | |
(let [cin (java.util.Scanner. System/in)] | |
(let [ | |
keyboard (get-width-height cin "Keyboard") | |
regular (get-width-height cin "Regular Keys") | |
special (get-width-height cin "Special Keys") | |
spacebar (get-width-height cin "Space Bar") | |
keyboard-area (get-area keyboard) | |
] | |
(println (str "Area of Keyboard: " (num-format keyboard-area)" squared inches.")) | |
(let [ | |
regular-keys-area (* (get-area regular) number-of-regular-keys) | |
special-keys-area (* (get-area special) number-of-special-keys) | |
total-keys-area (+ (get-area spacebar) regular-keys-area special-keys-area) | |
] | |
(println (str "Area of keys: " (num-format total-keys-area) " squared inches.")) | |
(println (str "Ratio of keys to keyboard: " (num-format (/ keyboard-area total-keys-area)))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment