|
บทที่ 6 > 6.5 การโปรแกรมแบบเชิงวัตถุ > 6.5.2 ภาษาโปรแกรมเชิงวัตถุ |
6/35 |
|
|
|
|
|
รูปที่ 6.10 แสดงการสร้างซอฟต์แวร์ประยุกต์ ด้วย ภาษาจาวา
ดังที่ได้กล่าวมาแล้วว่า ภาษาจาวาเป็นภาษาที่สร้างงานโดยมองทุกอย่างเป็นวัตถุ
ดังนั้น โปรแกรมทั้งโปรแกรมก็เทียบได้กับวัตถุขนาดใหญ่ชิ้นหนึ่ง และภายในวัตถุนั้นจะต้องมีการกระทำที่ชื่อว่า
main ดังรูปที่ 6.10 ส่วนที่มีการแรเงาคือส่วนประกอบของการกระทำ main ในคลาสหรือวัตถุที่ชื่อว่า average - number
|
|
|
|
|
|
|
|
import ConsoleInput.KeyboardInput;
Class average_number
{
public static String s = "Please enter the number : " ;
public static void main(String args[])
{
int sum=0;
int N = 1;
System.out.print(" The program will calculate the average of ");
System.out.println ("five integers you enter through the keyboard …");
While (N <= 5)
{
system.out.print(s);
int data = Integer.parseInt(KeyboardInput.read(Text));
sum = sum + data;
N++;
}
System.out.println ("The average of five numbers is " + sum/N);
}
}
|
|
|
|
|
|
|
|
|

|
|