DOC PREVIEW
UD CISC 181 - Transition help for introductory code from Racket (DrScheme) and Python to Java

This preview shows page 1-2 out of 7 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 7 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 7 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 7 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Transition help for introductory code from Racket (DrScheme) and Python to Java Racket version 5.0.2 • set DrScheme to use the Advanced Student language for the examples in this guide, add these helper functions to the top of your program: !;;!displayln:!ANY!//>!VOID!!;;!will!act!similar!to!System.out.println!in!Java!!(define!(displayln!line)!!!(begin!(display!line)!!!!!!!!!!(newline)))!!;;!in/range!is!built/in!for!Racket,!but!not!the!ASL!teaching!language.!;;!in/range:!NaturalNumber!//>!(listof!NaturalNumber)!!;;!in/range!consumes!a!NaturalNumber!N!and!returns!a!list!!;;!counting!up!from!0!to!(N/1).!!(define!(in/range!x)!!!(build/list!x!identity))!!Python version 2.6.5 Java version 1.6.0_22 • since Java requires all code to belong to a class, and include a main method as the entry point to run code, all Java code snippets (unless otherwise stated) belong within the body of the main method. For example, the actual runnable code in Java for the first example would look like this: !public!class!Transition!{!!!public!static!void!main(String[]!args)!{!!!!!System.out.println(5!+!10);!!!}!}! Expression*Racket(DrScheme)!(displayln!(+!5!10))!Python!print!(5!+!10)!Java!System.out.println(5!+!10);! Definition/Variable*assignment*Racket(DrScheme)!(define!LBS_TO_KILO!#i0.45359237)!(displayln!(*!175!LBS_TO_KILO))!Python!LBS_TO_KILO!=!0.45359237!print!(175!*!LBS_TO_KILO)!Java!double!LBS_TO_KILO!=!0.45359237;!System.out.println(175!*!LBS_TO_KILO)!!Variable*re5assignment*(mutation)*Racket(DrScheme)!(define!age!19)!(displayln!age)!(set!!age!(+!age!1))!(displayln!age)!Python!age!=!19!print!age!age!=!age!+!1!print!age!Java!!int!age!=!19;!System.out.println(age);!age!=!age!+!1;!System.out.println(age);!//!ALTERNATIVE!1!int!age!=!19;!System.out.println(age);!age!+=!1;!System.out.println(age);!//!ALTERNATIVE!2!int!age!=!19;!System.out.println(age);!age++;!System.out.println(age);! Selection*(conditional)*Racket(DrScheme)!(define!JOE_AGE!25)!(cond!((<!JOE_AGE!18)!(displayln!"minor"))!!!!!!!!((<!JOE_AGE!65)!(displayln!"adult"))!!!!!!!!(else!(displayln!"senior")))!Python!JOE_AGE!=!25!if!JOE_AGE!<!18:!!!print!"minor"!elif!JOE_AGE!<!65:!!!print!"adult"!else:!!!print!"senior"!Java!int!JOE_AGE!=!25;!if!(JOE_AGE!<!18)!{!!!!!System.out.println("minor");!}!else!if!(JOE_AGE!<!65)!{!!!!!System.out.println("adult");!}!else!{!!!!!System.out.println("senior");!}!


View Full Document

UD CISC 181 - Transition help for introductory code from Racket (DrScheme) and Python to Java

Download Transition help for introductory code from Racket (DrScheme) and Python to Java
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Transition help for introductory code from Racket (DrScheme) and Python to Java and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Transition help for introductory code from Racket (DrScheme) and Python to Java 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?