1. Trang chủ
  2. » Công Nghệ Thông Tin

Begin java having used alice

34 250 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 34
Dung lượng 437 KB

Nội dung

Begin Java having used Alice Pepper - Some slides from Alice in Action with Java Objectives • Write some first Java programs • Learn the basics of the BlueJ Integrated Development Environment (IDE) • Begin making the transition from Alice to Java Alice vs Java Alice Java • 3D graphics let you visualize programming concepts • Drag-and-drop coding reduces syntax errors • Create new objects - • Run Java programs across various platforms • Build applets to make Web pages interactive Much of Alice is written in Java A very simple Alice program A Very Simple Java Program public class JavaWorld { public static void main(String[] args) { System.out.println ("This is my first Java program."); } } Class header Method header statements Close braces mark the end Open braces mark the beginning A First Program – What Does It Do? Prints the message This is my first Java program. Ends the line System.out.println ("This is my first Java program."); Same steps to create a program Alice Java Storywrite Design Code Code Compile Play Run Test Test Make the Program Run • Compile (translate to java byte code) • Run (interpreter for that OS reads java byte code and translates for machine) Source x.java Compile (javac x.java) Object x.class Execute (java x) Development Environment Blue Jay Lets you enter code just like Alice did Download at: http://www.bluej.org/download/download.html Instructions on syllabus Exercise • Add the line “Welcome to Java” • When you run the program, you will see: This is my first Java Program. Welcome to Java. • Extra: – Info: print() does not go to the next line – Try splitting Welcome to Java into two statements: “Welcome” and then “ to Java.” [...]... DollarsToEuroConverter { public static void main(String[ ] args) { } } Comments – setup #2 • Comments: – Inline: begins comment with // and ends at line’s end – Block (C-style): begins with /* and ends with */ – Javadoc: begins with /** and ends with */ • Add comments to your class now at the top: /** DollarsToEurosConverter .java converts dollars to euros @author you */ Public class DollarsToEurosConverter Import Packages... Scanner class is in java. util package • Bring it in with an import statement – Example: import java. util.Scanner; let’s us talk with the user – like world’s “ask user for” functions • Do it now in your program between comment and class start: /** DollarsToEurosConverter .java converts dollars to euros @author you */ Import java. util.scanner Public class DollarsToEurosConverter Some Java Statements • Technique... */ Import java. util.scanner Public class DollarsToEurosConverter Some Java Statements • Technique for writing a program – Go through an algorithm step by step – Translate each step into an equivalent Java statement • Goal: apply technique to dollars-to-euros algorithm • Step 1 – Display "How many dollars do you want to convert?” – Use System.out.print(String query) – Like SAY • Ask now in your program,... euros + “euros”); • RUN YOUR Program Check test data • Possible inputs and outputs: Input Dollar Input euros Output Euros per dollar Rate 10 10.55 10 100 100 055 1000 1055 55 0 100 100 0 0 0 Testing a Java Program Using BlueJ • Functional testing – Running a program multiple times, using various values – Example: use various dollar values and exchange rates • Sanity checking: testing with easily verified... have at least one argument (format-string) – Arguments after the format-string need a placeholder – Example: "%.2f dollars => %.2f euros“ • Placeholder %.2f provides precision and type information Some Java Statements (continued) Step 6 – a bit better Type the statement to print the result to the screen in place of println: System.out.printf( “%.2f dollars => %.2f euros”,dollars, euros); Your toolset . Begin Java having used Alice Pepper - Some slides from Alice in Action with Java Objectives • Write some first Java programs • Learn the basics of the. basics of the BlueJ Integrated Development Environment (IDE) • Begin making the transition from Alice to Java Alice vs Java Alice Java • 3D graphics let you visualize programming concepts • Drag-and-drop. objects - • Run Java programs across various platforms • Build applets to make Web pages interactive Much of Alice is written in Java A very simple Alice program A Very Simple Java Program public

Ngày đăng: 23/10/2014, 13:55

TỪ KHÓA LIÊN QUAN

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN