한별복권
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
public class Blog {
public static void main(String[] args) {
new Byultto(1053);
}
}
class Byultto {
int count;
Date date;
LocalDate ld;
SimpleDateFormat sdf;
Byultto(int count) {
date = new Date();
ld = LocalDate.now();
this.count = count;
main();
}
void main() {
System.out.println(makeTitle());
System.out.println(
makeBody(
makeRandom(true, 10),
makeRandom(false, -1),
makeRandom(),
makeRandom(true, 9),
makeRandom(1000, 99999),
makeLotto()
)
);
}
String makeBody(
String random10,
String randomLong,
String randomCaps,
String random9,
String randomFormat,
List<Set<Integer>> lottos
) {
StringBuilder sb = new StringBuilder();
sb.append(" 제 " + count + " 회\r\n");
sdf = new SimpleDateFormat("yyyy/MM/dd (E) HH:mm:ss\r\n");
sb.append("발 행 일 : " + sdf.format(date));
sb.append("추 첨 일 : " + sdf.format(date).substring(0, 15) + "TR: " + random10 + "\r\n");
LocalDate limit = ld.plusYears(1).plusDays(1);
String temp = String.valueOf(limit).replace('-', '/');
sb.append("지급기한 : " + temp + "\r\n");
sb.append(randomLong + "\r\n");
sb.append(randomCaps + " " + random9 + "/" + randomFormat + "\r\n");
sb.append("-----------------------------------------" + "\r\n");
Iterator<Integer> it;
for (int i = 0; i < 5; i++) {
sb.append((char) (65 + i) + " 수 동 ");
it = lottos.get(i).iterator();
while (it.hasNext()) {
String s = String.valueOf(it.next());
sb.append(s);
if (s.length() == 1) {
sb.append(" ");
} else {
sb.append(" ");
}
}
sb.append("\r\n");
}
sb.append("-----------------------------------------" + "\r\n");
sb.append("금액 ₩5, 000\r\n");
sb.append(randomLong + "\r\n");
return sb.toString();
}
List<Set<Integer>> makeLotto() {
List<Set<Integer>> list = new LinkedList<>();
for (int i = 0; i < 5; i++) {
Set<Integer> set = new HashSet<>();
while (set.size() < 6) {
set.add((int) (Math.random() * 45) + 1);
}
list.add(set);
}
return list;
}
String makeRandom(boolean type, int digit) {
// true : random 10 digit
// false : 7 random 5 digit
if (type) {
return String.valueOf(Math.random()).replace(".", "").substring(1, digit + 1);
} else {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 7; i++) {
sb.append(String.valueOf(Math.random()).replace(".", "").substring(1, 6));
if (i < 6) {
sb.append(" ");
}
}
return sb.toString();
}
}
String makeRandom() {
// captial letters + number
String characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
int length = 16;
char[] text = new char[length];
for (int i = 0; i < length; i++) {
text[i] = characters.charAt((int) (Math.random() * 36));
}
return new String(text);
}
String makeRandom(int min, int max) {
// 000055555
int rd = (int) (Math.random() * (max - min) + 1) + min;
DecimalFormat df = new DecimalFormat("000000000");
return df.format(rd);
}
String makeBottom() {
StringBuilder sb = new StringBuilder();
return sb.toString();
}
String makeTitle() {
StringBuilder sb = new StringBuilder();
sb.append("\r\n 한별복권\r\n");
sb.append(" Byultto6/45\r\n");
return sb.toString();
}
}
댓글
댓글 쓰기