70 likes | 263 Views
Programming Fundamentals I Java Programming Spring 2009. XuanTung Hoang tung_hx@icu.ac.kr. Lab 01. Content. Programming Environment Installation Lab Assignments: Number Splitting Circle’s Area and Circumference. Installation. Install JDK
E N D
Programming Fundamentals IJava Programming Spring 2009 XuanTung Hoang tung_hx@icu.ac.kr Lab 01
Content • Programming Environment Installation • Lab Assignments: • Number Splitting • Circle’s Area and Circumference
Installation • Install JDK • Download and install Java SE - JDK 6 from http://java.sun.com/javase/downloads/?intcmp=1281 • Faster link: • http://wine.icu.ac.kr/ice0124/jdk-6u12-windows-i586-p.exe • Updating PATH so that you can invoke javac and java from command line • Add ; C:\Program Files\Java\jdk1.6.0_12\bin to PATH environmental variable • Install editor • Crimson Editor • Download: http://www.crimsoneditor.com • Vim Editor • Download: http://www.vim.org/download.php#pc • Update PATH so that you can start your editor from command line • You are not allowed to use IDE (e.g.: NetBean, Eclipse,…) to write your program during this course
Testing Installation • 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
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 program 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: 78368 Digits in 78368 are 7 8 3 6 8 C>
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 appropriate 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: 40.6944 Circumference: 22.608 C>
Submission and Report • Due: 4th 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: 20091004_lab1.zip • Submit the file to TA • Email address: submit.hw.code@gmail.com • Subject: “StudentID_ICE0124_lab1” • Example: 20061004_ICE0124_lab1