9
Using Eclipse to Develop Java Programs IEEM241 Routing and Fleet Management Feb 14, 2005

Using Eclipse to Develop Java Programs IEEM241 Routing and Fleet Management Feb 14, 2005

Embed Size (px)

Citation preview

Page 1: Using Eclipse to Develop Java Programs IEEM241 Routing and Fleet Management Feb 14, 2005

Using Eclipse to Develop Java Programs

IEEM241 Routing and Fleet Management

Feb 14, 2005

Page 2: Using Eclipse to Develop Java Programs IEEM241 Routing and Fleet Management Feb 14, 2005

Outline

• Introduction to Eclipse

• Download & Install Eclipse

• Review HelloWorldApp and FileIO applications with Eclipse

• A simple parsing tool– StringTokenizer

Page 3: Using Eclipse to Develop Java Programs IEEM241 Routing and Fleet Management Feb 14, 2005

Eclipse

• IDE (Integrated Development Environment) for Java with many powerful features, i.e. – syntax auto-checking– Debug– ……

• Developed by IBM• Free• Official website http://www.eclipse.org/

Page 4: Using Eclipse to Develop Java Programs IEEM241 Routing and Fleet Management Feb 14, 2005

Download Eclipse

• http://143.89.21.185/ieem241

• http://143.89.20.211/~kick

• ftp://ieem241:[email protected]

Please download eclipse-SDK-2.1.3-win32.zip

from any of the websites listed above

You may also download ~/t2/InstructionEclipse.pdf and ~/t1/sample.zip

Page 5: Using Eclipse to Develop Java Programs IEEM241 Routing and Fleet Management Feb 14, 2005

Parse Lines in Files

• readLine( ) is not enough, i.e. need to break the long sentence into individual words.

• Create a StringTokenizer to parse a string str with default delimiter (blank space)

StringTokenizer st = new StringTokenizer(str);

• Create a StringTokenizer with delimiter “,”StringTokenizer st = new StringTokenizer(str, “,”);

Page 6: Using Eclipse to Develop Java Programs IEEM241 Routing and Fleet Management Feb 14, 2005

Parse Lines in Files

• A common way to use StringTokenizerimport java.util.StringTokenizer;//or import java.util.*;……

StringTokenizer st = new StringTokenizer(str);while(st.hasMoreTokens()){

String token = st.NextToken();……//handle the tokens

}

Page 7: Using Eclipse to Develop Java Programs IEEM241 Routing and Fleet Management Feb 14, 2005

Data format

• Integer.parseInt(str)– To parse a string str into integer number

• Float.parseFloat(str)– To parse a string str into float number

Page 8: Using Eclipse to Develop Java Programs IEEM241 Routing and Fleet Management Feb 14, 2005

Example

• A simple counter which counts the total demand in a list which contains a customer name and the demand of the customer

• Data file – demandlist.txt• sample code – Counter.java• http://143.89.21.185/ieem241/t2• http://143.89.20.211/~kick/t2• ftp://ieem241:[email protected]/t2

Page 9: Using Eclipse to Develop Java Programs IEEM241 Routing and Fleet Management Feb 14, 2005

In-class Exercise

• Read from a file of arc information, the first line indicates the arc numbers, and other lines each contains three numbers: the from_node, the to_node, and the cost of this arc.

• Find the arc which has the lowest cost.• A brief frame of the program is provided, y

ou can download Arc.java from either of the mirror websites in ~/t2.