Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*ข้อสอบเรื่อง Class OOP
- *คำถามท้ายการทดลอง
- 1.Constucter มีไว้ทำอะไร มีเพื่ออะไร การทำงานเป็นไง
- 2.modifier คืออะไร มันสำคัญมากแค่ไหน
- 3.หาก ไม่ใช้ public หน้า method ใดๆ จะเกิดอะไรขึ้น
- 4.ในบรรดที่ 31 หากอามมี่บอกว่าห้ามสร้าง Object คุณจะทำยังไง
- 5.เหตุใด math.random() จึงต้องแปลงเป็น int และต้อง *2
- 6.อะไรคือฟิลล์
- 7.ทำการแก่ไข้โค้ด บรรดทัดที่ 6 เป็น private int N; และแก้ไขโปรแกรมให้สามารถใช้งานได้ดั่งเดิม (คำใบ้ getset)
- BY :Army Horyshit (อามมี่ คนหัวเสีย)
- At: BanInw
- department: SoftWareEngineer(Soft-En)
- https://www.facebook.com/codegeassmasterzeronebreakout
- */
- class Coin {
- byte HEAD = 0;
- byte Tail = 1;
- byte N;
- public Coin() {
- N=(byte)(Math.random()*2);
- }
- public void flip() {
- if(N==1)
- N=0;
- else if(N==0)
- N=1;
- }
- public void spin() {
- N=(byte)(Math.random()*2);
- }
- public int getForce() {
- return N;
- }
- }
- class Foo
- {
- public static void main(String[] args) {
- Coin c=new Coin();
- System.out.println(c.getForce());
- c.flip();
- System.out.println(c.getForce());
- c.spin();
- if(c.getForce()==new Coin().HEAD)
- System.out.println("Head");
- else if (c.getForce()==new Coin().Tail)
- System.out.println("Tail");
- }
- }
Add Comment
Please, Sign In to add comment