-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRandomBirthdayMonth.java
More file actions
101 lines (84 loc) · 2.98 KB
/
RandomBirthdayMonth.java
File metadata and controls
101 lines (84 loc) · 2.98 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import java.security.SecureRandom;
import java.util.Random;
import java.util.Scanner;
public class RandomBirthdayMonth
{
static Scanner input=new Scanner(System.in);
public static void main(String[] args)
{
do
{
final int numberOfMonths=12;
Random random=new SecureRandom();
int randomMonthNumber=1+random.nextInt(numberOfMonths);
System.out.print("\nEnter your birthday month: ");
String myBirthdayMonth=input.nextLine();
myBirthdayMonth=myBirthdayMonth.toUpperCase();
String calender[]= {" ","JANUARY","FEBRUARY","MARCH","APRIL","MAY","JUNE","JULY","AUGUST","SEPTEMBER","OCTOBER","NOVEMBER","DECEMBER"};
for(int j=0;j<numberOfMonths;j++)
{
if(myBirthdayMonth.equals(calender[j]))
{
int selectedRandomMonthNumber=randomMonthNumber;
System.out.print("\n\nThe random month chosen is in month number: " +integerToRoman(selectedRandomMonthNumber)+"\nAnd the Month Name is:"+calender[selectedRandomMonthNumber]+"\n"+calender[selectedRandomMonthNumber]+" Has "+CountCharacters(calender[selectedRandomMonthNumber])+" letters\n"+MyBirthday((myBirthdayMonth),calender[selectedRandomMonthNumber]));
System.out.println();
}
}
}while(true);
}
/*
* Function to Convert Integers into Roman Numerals
*/
private static int[] allArabianRomanNumbers =new int[] {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1};
private static String[] allRomanNumbers =new String[] {"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"};
private static String integerToRoman(int num)
{
if (num <= 0)
{
return "";
}
StringBuilder builder = new StringBuilder();
for (int i = 0; i < allArabianRomanNumbers.length; i++)
{
int times = num / allArabianRomanNumbers[i];
for (int j = 0; j < times; j++)
{
builder.append(allRomanNumbers[i]);
}
num -= times * allArabianRomanNumbers[i];
}
return builder.toString();
}
/**
* Count non-space character in string
*/
private static int CountCharacters(String str)
{
return str.replaceAll("\\s", "").length();
}
/*
* check if it is your birthday
*/
private static String MyBirthday (String myBirthdayMonth,String randomMonthGenerated)
{
boolean isMyBirthdayMonth = false;
String birthdayStatus=null;
if(randomMonthGenerated.equals(myBirthdayMonth))
{
isMyBirthdayMonth=true;
}
else
{
isMyBirthdayMonth=false;
}
if(isMyBirthdayMonth)
{
birthdayStatus="Is it your Birthday?: YES";
}
else
{
birthdayStatus="Is it your Bithday?: NO";
}
return birthdayStatus;
}
}