키오스크
package re_html;
import java.util.Scanner;
/*
키오스크 메뉴형태에 맞는 주문 시스템을 제작합니다
다음 결과에 맞춰서 출력되도록 합니다.
*/
public class re_java6 {
public static void main(String[] args) {
re_java6_box rb = new re_java6_box();
}
}
class re_java6_box{
Scanner sc = null;
String menu[] = null;
int usermenu = 0; //사용자가 선택한 메뉴값
public re_java6_box() {
this.menu = new String[]{"커피","햄버거","콜라","피자","샌드위치"};
this.sc = new Scanner(System.in);
this.menu_select();
}
private void menu_select() {
//StringBuilder,StringBuffer : 문자열을 쉽게 연결해서 사용 가능
StringBuilder sb = new StringBuilder(); // append 사용
int w = 0;
while(w<this.menu.length) {
sb.append((w+1)+". "+this.menu[w]+"\n");
w++;
}
System.out.println(sb+"메뉴를 선택해주세요 : ");
try { //try => 정상적인 프로세서 진행에 대한 처리 메소드
this.usermenu = this.sc.nextInt(); //사용자가 입력한 값을 변수로 이관
if(this.usermenu == 5) {
System.out.println("매진");
menu_select();
}else {
System.out.println("주문 완료");
System.exit(0);
}
}
catch(Exception e) { //catch => 문제사항이 발생시 처리되는 메소드
System.out.println("메뉴 번호는 숫자만 입력하셔야 합니다.");
System.out.println(e);
new re_java6_box();
}finally {
this.sc.close();
}
}
}
로또
난수(랜덤수) 생성
package re_html;
import java.util.ArrayList;
import java.util.Arrays;
public class re_java7 {
public static void main(String[] args) {
re7_box rb = new re7_box();
// rb.ny_lotto();
}
}
class re7_box{
//pc가 선택한 숫자 6개를 담을 클래스 배열
ArrayList<Integer> no = null;
Integer result = 0;
//선생님이 짠 로또
public re7_box() { //즉시실행
this.no = new ArrayList<Integer>();
this.games();
}
private void games() { // 결과 출력
for (;;) { // 무한 loop
this.result = this.pc_lotto();
boolean callback = this.number_check(this.result);
if (this.no.size() < 7) {
if (callback == true) { // 이미 선택된 숫자가 없을 경우
this.no.add(this.result);
} else { // 배열에 이미 선택된 숫자가 있을경우
continue;
}
} else {
break;
}
}
System.out.println(this.no);
}
private boolean number_check(Integer result) {
boolean ck = true;
int w = 0;
while(w <this.no.size()) {
if(result == this.no.get(w)) {
ck = false;
}
w++;
}
return ck;
}
private Integer pc_lotto() { //pc가 1~46 숫자 중 한가지를 무작위 선택
Integer no = (int)Math.ceil(Math.random()*46);
return no;
}
//내가짠로또
public void ny_lotto(){
int nos[] = new int[6];
int i = 0;
int j = 0;
while(i<6) {
nos[i] = (int)Math.ceil(Math.random()*46);
j=0;
while(j<nos.length) {
if(nos[i]==nos[j]) {
nos[i] = (int)Math.ceil(Math.random()*46);
}
j++;
}
i++;
}
System.out.println(Arrays.toString(nos));
}
}