Programming Fundamentals I Java Programming Spring 2009 XuanTung Hoang Lab 01
XuanTung Hoang 2 Content Programming Environment Installation Lab Assignments: Number Splitting Circle’s Area and Circumference
XuanTung Hoang 3 Installation Install JDK Download and install Java SE - JDK 6 from Faster link: Updating PATH so that you can invoke javac and java from co mmand line Add ; C:\Program Files\Java\jdk1.6.0_12\bin to PATH environmental variable Install editor Crimson Editor Download: Vim Editor Download: Update PATH so that you can start your editor from command line You are not allowed to use IDE (e.g.: NetBean, Eclipse,…) to writ e your program during this course
XuanTung Hoang 4 Open command line (Start – Run – type “cmd” – Enter) Edit Hello.java (assume that you use Crimson Editor) cedt Hello.java Type/copy the following code public class Hello { public static void main( String[] args ) { System.out.println("Hello world\n"); } Save the file Compile and run the sample application Compile: javac Hello.java Run: java Hello Testing Installation
XuanTung Hoang 5 I. Number Splitting Objectives: Input/output with Scanner object Modulus (%) operation for integers Requirements: Create a class name NumberSplitting that has only main method (the pr ogram entry.) In the main method, do the followings: Create an object of Scanner class Read a 5-digit integer from user (using nextInt() method of the created Scanner object) Split the 5-digit number into digits and print those digits to screen. Refer to Addition.java in Lecture 2 as an example A sample output of the program execution… C> java NumberSplitting Enter 5-digit integer: Digits in are C>
XuanTung Hoang 6 II. Circle’s area and circumference Objectives: Input/output with Scanner object Arithmetic operations (floating point numbers) Requirements: Create a class that has only main method (the program entry) In the main method, do the followings: Read the radius of a circle from user using nextDouble() of Scanner class Remember to create Scanner object and store the input radius into a variable of appropriat e type The usage of nextDouble() method is similar to nextInt() method Print out the corresponding diameter, area, and circumference of the circle A sample output of the program execution… Enter radius: 3.6 Diameter: 7.2 Area: Circumference: C>
XuanTung Hoang 7 Submission and Report Due: 4 th March, mid-night Compress your source/class files into a ZIP file Name the zip file according with the following template: StudentID_labNumber.zip Example: _lab1.zip Submit the file to TA address: Subject: “StudentID_ICE0124_lab1” Example: _ICE0124_lab1