Flogging a dead horse - reading a number
Remi Forax
forax at univ-mlv.fr
Sun Jan 19 18:15:42 UTC 2025
> From: "Kenneth Fogel" <kfogel at dawsoncollege.qc.ca>
> To: "amber-dev" <amber-dev at openjdk.org>
> Sent: Sunday, January 19, 2025 6:55:34 PM
> Subject: Flogging a dead horse - reading a number
> Hi,
Hello,
> I have started a new course this past week, a first level Java course. Once we
> get past “Hello Moose” (in Canada we prefer this to Hello World) I present a
> simple program that calculates loan payments. Then I present an interactive
> version where I am forced to write:
> var loan = Double.parseDouble(readln("Loan: "));
> var interest = Double.parseDouble(readln("Interest: "));
> var term = Double.parseDouble(readln("Term: "));
> Its all going well until I must describe what Double.parseDouble is.
> I do not need a read for each numeric type. A read for doubles is all I think is
> necessary and then I could write:
> var loan = (readNum("Loan: ")); // loan is a double
> or if I need an integer:
> var numberOfCarrots = (int)readNum(“How many carrots do you need? “);
> Heck, if I were greedy, I’d ask that if you cast a readln this results in
> numeric input:
> var loan = (double) readln("Loan: ")); // Just like Python
Java is not a dynamically typed language, so no !
That's said, you are free to provide a library for your students.
In my case, with my students, we first go from readln/println to IO.readln()/IO.println() and then we add Integer.parseInt() and Double.parseDouble(),
so Double.parseDouble() is not alien at the time it is introduced.
> But I’m not that greedy, today.
> Ken
regards,
Rémi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20250119/84f8fc4e/attachment.htm>
More information about the amber-dev
mailing list