สมาคมครูหนุ่มหล่อแห่งประเทศไทย
Group Blog
 
All Blogs
 
Lecture 4 Exercises – Writing Applications

Lecture 4 Exercises – Writing Applications
Part 1 – Writing Command-Line Applications
Programming Tips
• The length of an array can be checked with its length property, i.e. arrayName.length
• Use the System.out.println(…) method to write to the console.
• Use the System.exit(…) method to exit the application. A parameter of zero means a normal exit, a parameter of one means an error was encountered.
• To convert a String into an integer use the Integer.parseInt() method
• String constants can be declared as:
public static final String MY_STRING = “myStringValue”;
• Use the new operator to create a new object, e.g. new Calculator(x, y).
• The Javadoc for the Java API can be found at: //java.sun.com/j2se/1.4.1/docs/api/index.html
Exercises

1. Write a simple application that when run simply writes out “Hello World” to the console.
2. Write a simple application that loops through the array containing its command-line parameters, writing each of them to the console (Tip: check the javadoc for java.lang.String):
a. In upper case
b. and include the length of each string.
3. Write a simple command-line calculator as described by the UML diagram below. The calculator should be able to accept the following command line parameters:
a. The first number
b. An operator. One of the following strings: plus, minus, times, divide
c. A second number
The calculator should then print out the results of the calculation. If an incorrect number of arguments are provided, or the user types in an unknown operator, then the program should exit with an appropriate message.



Create Date : 06 กุมภาพันธ์ 2554
Last Update : 6 กุมภาพันธ์ 2554 8:54:59 น. 0 comments
Counter : 956 Pageviews.

ชื่อ : * blog นี้ comment ได้เฉพาะสมาชิก
Comment :
  *ส่วน comment ไม่สามารถใช้ javascript และ style sheet
 

hangclub
Location :


[Profile ทั้งหมด]

ฝากข้อความหลังไมค์
Rss Feed
Smember
ผู้ติดตามบล็อก : 29 คน [?]




Friends' blogs
[Add hangclub's blog to your web]
Links
 
MY VIP Friend


 Pantip.com | PantipMarket.com | Pantown.com | © 2004 BlogGang.com allrights reserved.