-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRabit.java
More file actions
76 lines (63 loc) · 1.33 KB
/
Rabit.java
File metadata and controls
76 lines (63 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//package main;
import java.util.*;
//import Manager.RabitManager;
public class Rabit
{
public static void main(String[] argvs)
{
int rabitNum = 0;
RabitManager manager = new RabitManager();
System.out.println("Please Input Day:");
Scanner in=new Scanner(System.in);
int day=in.nextInt();
rabitNum = manager.rabitCnt(day);
System.out.println("DAY="+day+";RabitNum is " + rabitNum);
}
}
/*public*/class RabitCouple
{
/*public*/RabitCouple(int brith_day)
{
this.brith_day = brith_day;
}
/*public*/ boolean bear(int day)
{
if ((day - brith_day) >= 2)
return true;
else
return false;
}
private int brith_day;
}
/*public*/ class RabitManager
{
/*public*/ RabitManager()
{
init();
}
private void init()
{
rabitList = new ArrayList();
rabitList.add(new RabitCouple(1));
}
/*public*/ int rabitCnt(int month)
{
int current_m = 0;
for (current_m = 1; current_m <= month; current_m++)
{
Iterator it = rabitList.iterator();
List newRabit = new ArrayList();
while (it.hasNext())
{
RabitCouple rabit = (RabitCouple) it.next();
if (rabit.bear(current_m))
{
newRabit.add(new RabitCouple(current_m));
}
}
rabitList.addAll(newRabit);
}
return rabitList.size();
}
List rabitList;
}