package MainSuit;
import java.io.*;
public class MainSuit {
public static void main(String[] args) {
System.out.println(”Permainan suit”);
System.out.println(”==============”);
System.out.println(”Masukkan salah satu dari 3 kemungkinan :”);
System.out.println(”J untuk Jempol”);
System.out.println(”T untuk Telunjuk”);
System.out.println(”K untuk Kelingking”);
System.out.println(” “);
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String input = null;
boolean inputvalid = false;
int suitKomputer = 0;
int suitUser = 0;
while (!inputvalid) {
System.out.print(”Masukkan suit Anda “);
try {
input = br.readLine();
} catch (IOException ioe) {
System.out.println(”Kesalahan IO, program berhenti”);
System.exit(1);
}
if (input.length() > 0) {
switch (input.charAt(0)) {
case ‘j’ :
case ‘J’ :
suitUser = 0;
inputvalid = true;
break;
case ‘t’ :
case ‘T’ :
suitUser = 1;
inputvalid = true;
break;
case ‘k’ :
case ‘K’ :
suitUser = 2;
inputvalid = true;
break;
}
}
}
suitKomputer = (int)(Math.random()*3);
if (suitKomputer == 3) {
suitKomputer = 2;
}
switch (suitKomputer) {
case 0:
System.out.println(”Suit komputer = Jempol”);
switch (suitUser) {
case 0:
System.out.println(”Seri”);
break;
case 1:
System.out.println(”Anda kalah”);
break;
case 2:
System.out.println(”Anda menang”);
break;
}
break;
case 1:
System.out.println(”Suit komputer = Telunjuk”);
switch (suitUser) {
case 0:
System.out.println(”Anda menang”);
break;
case 1:
System.out.println(”Seri”);
break;
case 2:
System.out.println(”Anda kalah”);
break;
}
break;
case 2:
System.out.println(”Suit komputer = Kelingking”);
switch (suitUser) {
case 0:
System.out.println(”Anda kalah”);
break;
case 1:
System.out.println(”Anda menang”);
break;
case 2:
System.out.println(”Seri”);
break;
}
break;
}
}
}

silakan di coba bagi yang berminat

About these ads