精華區beta b885060xx 關於我們 聯絡資訊
Assignment #1 A little exercise for class definition -- Counter (~ Refer to p.230 in textbook, Programming Exercise 2) Define a class called Counter. An object of this class is used to count things, so it records a count that is a nonnegative whole number. Include methods to wet the counter to zero, to increase the count by 1, and to decrease the count by 1. Be sure that no method allows the value of the counter to become negative. Also, include an accessor method that returns the current count value. Also, include a method that outputs the count to the screen. There will be no input method. The only method that can set the counter is the one that sets it to zero. Also, write a program to test your class definition. Hint: You only need one instance variable. Deadline: 14:00, 3/28 (According to the receiving time) --- 好像控制碼弄得有點小誇張:Q -- ※ 發信站: 批踢踢實業坊(ptt.twbbs.org) ◆ From: ntucsa.csie.ntu. > -------------------------------------------------------------------------- < 作者: ledia (就是固執不改初衷) 看板: b885060xx 標題: [中譯] Java 作業一 時間: Sun Mar 12 01:33:50 2000 翻譯得不好不要怪我 ^^;; Java 作業一 做一個叫 Counter 的計數器 ( 定義出這個 class ) 這種 class 定義出來的物件用以計數,所以它所 計的是一個非負的整數值,其中的 method 包括 了歸零、加一、減一,要確定不會有 method 使 得所計的數變成了負的。此外,其中還包括了傳 回所計的值和將之輸出至螢幕上的 method ,但 不會有輸入的 method ,唯一能重設計數值的方 法就是把它重設回零。最後寫一個程式測試你的 class 的定義。 提示:你只需要一個 instance variable Due Day: 3/28 14:00 -- 有時候,遺忘,是令人快樂的。什麼時候?當然是有人傷了你的心的時候。  存心傷你的那個人,固然是故意和你過不去,但是被傷了心而耿耿於懷的你  ,卻是和自己過不去了。所以,記性不好的人,通常會是比較快樂的人,也  是比較不容易被擊倒的人。 -- ※ 發信站: 批踢踢實業坊(ptt.twbbs.org) ◆ From: h170.s103.ts.hinet.net