Department of Computer Engineering Using Objects 2140101 Computer Programming for International Engineers.

Slides:



Advertisements
Similar presentations
L2:CSC © Dr. Basheer M. Nasef Lecture #2 By Dr. Basheer M. Nasef.
Advertisements

Self Check 1.Which are the most commonly used number types in Java? 2.Suppose x is a double. When does the cast (long) x yield a different result from.
Java Programming Strings Chapter 7.
Chapter 2: Using Objects Part 1. To learn about variables To understand the concepts of classes and objects To be able to call methods To learn about.
 2005 Pearson Education, Inc. All rights reserved Introduction.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
Primitive Data Types and Operations. Introducing Programming with an Example public class ComputeArea { /** Main method */ public static void main(String[]
03 Data types1June Data types CE : Fundamental Programming Techniques.
1 LECTURE#7: Console Input Overview l Introduction to Wrapper classes. l Introduction to Exceptions (Java run-time errors). l Console input using the BufferedReader.
Mathematical Operators  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course. Introduction to Computers and Programming in.
Fundamental Programming Structures in Java: Strings.
The Class String. String Constants and Variables  There is no primitive type for strings in Java.  There is a class called String that can be used to.
1 Introduction to Console Input  Primitive Type Wrapper Classes  Converting Strings to Numbers  System.in Stream  Wrapping System.in in a Buffered.
Fundamental Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
Chapter 2  Using Objects 1 Chapter 2 Using Objects.
Chapter 3b Standard Input and Output Sample Development.
COMP 110 Introduction to Programming Mr. Joshua Stough September 10, 2007.
COMPSCI 125 Spring 2005 ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 3: IO *Standard Output *Formatting Decimal.
1 Strings and String Operations  What is a Strings?  Internal Representation of Strings  Getting Substrings from a String  Concatenating Strings 
1 Chapter 2 JAVA FUNDAMENTALS CONT’D. 2 PRIMITIVE DATA TYPES Computer programs operate on data values. Values in Java are classified according to their.
Department of Computer Engineering Recursive Problem Solving Computer Programming for International Engineers.
CSCI 1730 January 17 th, 2012 © by Pearson Education, Inc. All Rights Reserved.
1 Course Lectures Available on line:
Copyright 2006 by Pearson Education 1 Building Java Programs Chapters 3-4: Using Objects.
VARIABLES Introduction to Computer Science 1- COMP 1005, 1405 Instructor : Behnam Hajian
CSI 1390: Introduction to Computers TA: Tapu Kumar Ghose Office: STE 5014
1 Java Console I/O Introduction. 2 Java I/O You may have noticed that all the I/O that we have done has been output The reasons –Java I/O is based on.
The string data type String. String (in general) A string is a sequence of characters enclosed between the double quotes "..." Example: Each character.
Unit 3: Java Data Types Math class and String class.
Console Input. So far… All the inputs for our programs have been hard-coded in the main method or inputted using the dialog boxes of BlueJ It’s time to.
Objects and Classes; Strings. 2 Classes and objects class: A program entity that represents either 1.A program / module, or 2.A type of objects* –A class.
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
Chapter 2 Elementary Programming
Zhen Jiang Dept. of Computer Science West Chester University West Chester, PA CSC141 Computer Science I 5/27/20161.
CIS 260: App Dev I. 2 Programs and Programming n Program  A sequence of steps designed to accomplish a task n Program design  A detailed _____ for implementing.
Using Data Within a Program Chapter 2.  Classes  Methods  Statements  Modifiers  Identifiers.
Chapter 2 Using Objects. Types A type defines a set of values and the operations that can be carried out on the values Examples: 13 has type int "Hello,
Introduction to Programming
Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY.
String Definition A String is a set of characters that behaves as a single unit. The characters in a String include upper-case and lower-case letters,
Chapter 3: Classes and Objects Java Programming FROM THE BEGINNING Copyright © 2000 W. W. Norton & Company. All rights reserved Java’s String Class.
FUNDAMENTALS 2 CHAPTER 2. OPERATORS  Operators are special symbols used for:  mathematical functions  assignment statements  logical comparisons 
Lesson 4 Input. JAVA Input JAVA input is not straightforward and is different depending on the JAVA environment that you are using. The reason it is not.
String Processing Word processing term papers, writing memoirs, sending messages, responding to surveys, placing online orders and registering products.
A Simple Java Program //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { public static void main(String[]
Chapter 2 Input, Variables and Data Types. JAVA Input JAVA input is not straightforward and is different depending on the JAVA environment that you are.
Java Variables, Types, and Math Getting Started Complete and Turn in Address/Poem.
CSC Programming I Lecture 9 September 11, 2002.
1 Using Objects Chapter 3 Spring 2006 CS 101 Aaron Bloomfield.
CSI 3125, Preliminaries, page 1 Java I/O. CSI 3125, Preliminaries, page 2 Java I/O Java I/O (Input and Output) is used to process the input and produce.
String Definition A string is a set of characters that behaves as a single unit. The characters in a string include upper-case and lower- case letters,
Department of Computer Engineering Methods Computer Programming for International Engineers.
1 Predefined Classes and Objects Chapter 3. 2 Objectives You will be able to:  Use predefined classes available in the Java System Library in your own.
CHAPTER 6 GC Strings. THE CLASS STRING  Contains operations to manipulate strings.  String:  Sequence of zero or more characters.  Enclosed.
1 reading: 3.3 Using objects. Objects So far, we have seen: methods, which represent behavior variables, which represent data (categorized by types) It.
CSCI 161 – Introduction to Programming I William Killian
Building Java Programs
String class.
Introduction to Computer Science / Procedural – 67130
Exposure Java 2015 Pre-AP®CS Edition Chapter 12 Slides String Methods
Introduction to Java Programming
Lecture Notes - Week 2 Lecture-1. Lecture Notes - Week 2 Lecture-1.
Chapter 3 Spring 2006 CS 101 Aaron Bloomfield
Using Objects (continued)
CS2011 Introduction to Programming I Strings
Fundamental OOP Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
In this class, we will cover:
Chapter 2: Java Fundamentals cont’d
More on iterations using
Presentation transcript:

Department of Computer Engineering Using Objects Computer Programming for International Engineers

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY Objectives Students should: Understand classes and objects. Be able to use class methods and data from existing classes. Be familiar with the String class and be able to use its methods. Be able to use the BufferedReader class to get users’ input from keyboards. Be able to process keyboard input as String and numeric values.

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY Classes and Objects Classes – Classes are non-primitive data types in Java –New classes can be made while there are no such things as new primitive data types. Objects – object is an instance of a class.

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY Classes and Objects (1) String is a class in Java. String s1; s1 = “Chocolate Chip”; a variable named s1 is declared as a variable that is used for storing an object of the class String. an object of class String is created with the content “Chocolate Chip” and assigned to the variable s1.

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY Classes and Objects (2) s1 - - “Chocolate Chip” s1 “Chocolate Chip” String s1; s1 is created. It does not contain anything yet. s1 = “Chocolate Chip”; A String object containing “Chocolate Chip” is created, but unreferenced. s1 = “Chocolate Chip”; s1 is made to point to the String object “Chocolate Chip”.

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY Using Data and Methods provided in Classes An object of a class contains data and methods. For example –Class Rectangle –The data contained in each object Such as height, width, x, and y stores necessary attributes that define a rectangle. –several methods related to using the rectangle such as getHeight(), getWidth(), getX(), getY(), and setLocation().

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY Example Rectangle height width x y getHeight() getWidth() getX() getY() setLocation() : Data Methods

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY Using Data and Methods provided in Classes (2) The dot operator (.) is used for accessing data or methods from a class or an object of a class. Consider the two methods below. System.out.print(“Strawberry Sundae”); System.out.println(“Banana Split”);

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY Using Data and Methods provided in Classes (3) System – System is a class in a standard Java package. –This class contains an object called out. Out –An object whose class is a class called PrintStream. –Using the dot operator, we refer to this out object in the class System by using System.out. PrintStream –The class contains print() and println() we can access the two methods using System.out.print() and System.out.println().

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY Class “System” System in out : PrintStream print() println() : : data methods data System System.out.println() System.out.print()

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY Using Data and Methods provided in Classes (4) Some data and methods can be accessed by using the dot operator with the name of the class Some can be accessed by using the name of the variable storing the object of that class.

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY Using Data and Methods provided in Classes (5) Class (or static) data and methods –Data and methods that are accessed via the class name Instance (or non-static) data and methods –Data and methods that are accessed via the object name Now  only realize the difference in accessing the two.

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY Example public class AreaOfCircle { public static void main(String[] args) { double area, r = 10; String s1 = "The Area of a circle with "; String s2 = " r = "; String s3 = " is "; String s4; area = Math.PI*Math.pow(r,2); s4 = s1.concat(s2); System.out.println(s4+area); }

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY Example This Java program calculates the area of a circle with radius r, where r equals 10. we calculate the area by multiplying Math.PI with Math.pow(r,2). double area, r = 10; area = Math.PI*Math.pow(r,2);

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY Example Math.PI –refers to the  value that is defined in a constant value names PI in the Math class. Math.pow(r,2) –the activation of a method called pow() that is also defined in the Math class. Notice that we do not need to create an object of the Math class but we access the data and method from the name of the class directly.

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY Example A method called concat() is accessed from a variable that contains a String object. s1.concat(s2) –returns a String object resulting from the concatenation of the String object in s1 and the String object in s2. s4 = s1.concat(s2);

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY Useful String methods Some methods that we can use from a String object. charAt() –Let s be a String object and i be an int. – s.charAt(i) returns the char value at the i th index. length() –Let s be a String object. – s.length() returns the int value equals to the length of the String.

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY Example public class CharAtDemo { public static void main(String[] args) { String s = "ABCD\nEFGH"; char c; System.out.println("s = "); System.out.println(s); c = s.charAt(0); System.out.println("charAt(0)="+c); c = s.charAt(1);

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY System.out.println("charAt(1)="+c); c = s.charAt(5); System.out.println("charAt(5)="+c); System.out.print("The length of this string is ") System.out.println(s.length()+" characters"); c = s.charAt(s.length()-1); System.out.println("The last char ="+c); } Example

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY Example

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY the String s contains 9 characters –which are ‘A’, ‘B’, ‘C’, ‘D’, ‘\n’, ‘E’, ‘F’, ‘G’, and ‘H’. –an escape sequence is considered a single character. Example

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY the characters at 0, 1, and 5 which are ‘A’, ‘B’ and ‘E’ are assigned to the char variable c. Then, c is printed out to the screen after each assignment. c = s.charAt(0); System.out.println("charAt(0)="+c); c = s.charAt(1); System.out.println("charAt(1)="+c); c = s.charAt(5); System.out.println("charAt(5)="+c); Example

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY the length of the String in s is extracted via the method length(). Be aware that, the first index of a String is 0, so the location of the last character is s.length()-1. System.out.println(s.length()+" characters"); c = s.charAt(s.length()-1); Example

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY Useful String methods (2) concat() –Let s be a String object and r be another String object. – s.concat(r) returns an new String object whose content is the concatenation of the String in s and r.

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY Example public class ConcatDemo { public static void main(String[] args) { String s1 = "First"; String s2 = "Second"; String s3, s4; s3 = s1.concat(s2); s4 = s2.concat(s1); System.out.println("s1 is "+s1); System.out.println("s2 is "+s2); System.out.println("s3 is "+s3); System.out.println("s4 is "+s4); String s5 = "AB".concat("CD").concat("EF"); System.out.println("s5 is "+s5); }

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY Example

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY Example s1.concat(s1) ≠ s1.concat(s1). the method concat() from a String s creates a new String object –based on s and the String input into the parentheses –it does not change the value of the original String object.

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY Example we can invoke String methods directly from a String object without having to be referred to by a variable –i.e. “AB”.concat(“CD”) since “AB”.concat(“CD”) results in a new String object, we can call a String method from it directly –e.g. “AB”.concat(“CD”).concat(“EF”) String s5 = "AB".concat("CD").concat("EF");

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY Useful String methods (3) indexOf() – Let s be a String object and c be a char value. s.indexOf(c) returns the index of the first c appearing in the String. It returns -1 if there is no c in the String. – If i is an int value equals to the Unicode value of c s.indexOf(i) returns the same result. –A String r can also be used in the place of c. the method finds that String inside the String s returns the index of the first character of r found in the String s. it returns -1 if r is not found in s.

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY Useful String methods (4) lastIndexOf() –works similarly to indexOf() –but it returns the index of the last occurrence of the input character

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY Example public class IndexOfDemo { public static void main(String[] args) { String s = "oxx-xo--xoXo"; System.out.println("The first 'x' is at "+s.indexOf('x')); System.out.println("The first 'o' is at "+s.indexOf('o')); System.out.println("The first '-' is at "+s.indexOf(45)); System.out.println("The first 'X' is at "+s.indexOf('X')); }

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY Example

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY Example public class IndexOfDemo3 { public static void main(String[] args) { String s = "say ABC ABC ABC"; System.out.println(s); System.out.println("lastIndexOf(\'B\')="+s.lastIndexOf('B')); System.out.println("lastIndexOf(\"AB\")="+s.lastIndexOf("AB")); }

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY Useful String methods (5) substring() –Let s be a String object. s.substing(a,b) – a and b are int values –returns a new String object whose content are the characters of the String s from the a th index to the (b-1) th index. –If b is omitted the substring runs from a to the end of s.

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY Useful String methods (6) toLowerCase() –Let s be a String object. – s.toLowerCase() returns a new String object which is a copy of s but with all uppercase characters converted to lowercase. toUpperCase() –Let s be a String object. – s.toUpperCase() returns a new String object which is a copy of s but with all lowercase characters converted to uppercase.

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY Example public class SubstringDemo { public static void main(String[] args) { String s = "Sir Isaac Newton"; System.out.println(s.substring(10)); int startIdx = 4; int len = 5; System.out.println(s.toUpperCase().substring(startIdx,star tIdx+len)); }

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY More String Methods There are many more methods provided by the String class. consult class notes and Java API doc.

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY Reading Input String from Keyboards It is usually a common requirement to obtain values from the user of the program via keyboards. In Java, this capability is provided by some methods, already defined in classes.

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY A class called BufferedReader BufferedReader provides a method called readLine(). –read characters from keyboard input –until a newline character is found –store the characters into a String object. Note that the newline character (\n) signaling the end of the input is not included in the String. Reading Input String from Keyboards

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY Using BufferedReader First, since we are going to use the BufferedReader class, which is not in the standard Java packages –we need to let the compiler know where to look for the definition of this class –adding the following statement in to our source code on a line prior to the start of our program’s definition. import java.io.*;

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY create an object of class BufferedReader we need to create an object of class BufferedReader by using the following statement. This statement creates a variable named stdin that refers to a BufferedReader object. stdin is a BufferedReader object. BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY Reading Keyboard Input Once a BufferedReader object is created, we can access the readLine() method from that object. For example –we can use the following statement to read keyboard input to a String object called s. – stdin is the object we created in the previous statement. String s = stdin.readLine();

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY Reading Keyboard Input Once the statement is executed, the program waits for the user to type in the input until a newline character is entered. This input can be used later in the program from the String s.

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY Reading Keyboard Input The following program asks the user to input his/her first and last name. it prints a message containing the names on to the screen. Notice that another thing that is required to be added is throws IOException in the header of the main() method. –Explanation is omitted until you learn about exceptions in Java.

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY Example import java.io.*; public class Greeting { public static void main(String[] args) throws IOException { String firstname, lastname; BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in)); System.out.print("Please enter your firstname:"); firstname = stdin.readLine(); System.out.print("Please enter your lastname:"); lastname = stdin.readLine(); System.out.println(" "); System.out.println("Hello "+firstname+" "+lastname); System.out.println(" "); }

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY Example

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY Converting Strings to numbers sometimes we expect the keyboard input to be numeric data so that we can process numerically we need a way to convert a String object to an appropriate numeric value. Java has provided methods responsible for doing so.

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY Converting Strings to numbers (2) parseInt() – parseInt() is a static method that takes in a String object –returns an int whose value associates with the content of that String. – parseInt() is defined in a class called Integer. –calling a static method named parseInt() from the Integer class – s is a String object whose content we wish to convert to int. Integer.parseInt(s)

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY Converting Strings to numbers (3) parseDouble() – parseDouble() is a static method that takes in a String object –returns an double whose value associates with the content of that String. – parseDouble() is defined in a class called Double. –calling parseDouble() takes the form – s is a String object whose content we wish to convert to double. Double.parseDouble(s)

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY Integer and Double It is necessary to know that Integer is a class –not the primitive type int Double is another class –not the primitive type double.

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY Example double theta, f, thetaRad, fx, fy; BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in)); // prompt for f System.out.print("Enter F: "); f = Double.parseDouble(stdin.readLine()); // prompt for theta System.out.print("Enter Theta: "); theta = Double.parseDouble(stdin.readLine());

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY In-class quiz No.2 Before Chapter 6 Materials covered up to Chapter 5