Java : Membuat Game Kuis Sederhana Menggunakan Java
Buatlah sebuah
game sederhana yang berupa kuis dengan 10 pertanyaan (pertanyaan berupa hitung angka).
User harus menjawab pertanyaan tersebut melalui keyboard. Jika jawaban benar
nilai bertambah 1 dan jika salah nilai berkurang satu. Gunakan operator unary
(increment dan decrement). Di akhir program tampilkan nilai total yang didapat
oleh user.
Algoritma :
input
: jawaban user
output
: nilai yang didapat user berdasarkan
jawaban yang benar
prosedur
:
1. Tampilkan pertanyaan
2. user memasukkan jawaban
3. cek jawaban, jika benar nilai ditambah 1, jika salah nilai dikurangi 1
4. ulangi langkah 1-3 sampai pertanyaan habis
5. tampilkan nilai
6. jika user menekan Y atau y kembali ke langkah awal, jika menekan T atau
t program exit.
silahkan Copas
saja Langsung Codingnya :D
import
java.util.Scanner;
/**
*
* @Newbie
*/
public class coba1 {
public static void main(String[] args) {
int jumlah = 0 ;
int input = 0 ;
String a = "y" ;
int poin = 0 ;
int jawab ;
do {
System.out.println ("Skor pertama anda adalah Nol");
System.out.println ("Jika jawaban anda benar Bertambah1");
System.out.println ("Jika jawaban anda salah Dikurangi 1");
Scanner scan = new Scanner (System.in);
System.out.print("1+5=");
jawab = scan.nextInt();
if(jawab==6){
System.out.println("jawaban anda benar");
System.out.print("poin anda adalah:");
System.out.println(poin+=1);}
else {
System.out.println("jawaban anda salah");
System.out.print("poin anda adalah:");
System.out.println(poin-=1);}
System.out.print("6:2=");
jawab = scan.nextInt();
if(jawab==3){
System.out.println("jawaban anda benar");
System.out.print("poin anda adalah:");
System.out.println(poin+=1);}
else {
System.out.println("jawaban anda salah");
System.out.print("poin anda adalah:");
System.out.println(poin-=1);}
System.out.print("5+5=");
jawab = scan.nextInt();
if(jawab==10){
System.out.println("jawaban anda benar");
System.out.print("poin anda adalah:");
System.out.println(poin+=1);}
else {
System.out.println("jawaban anda salah");
System.out.print("poin anda adalah:");
System.out.println(poin-=1);}
System.out.print("5x5=");
jawab = scan.nextInt();
if(jawab==25){
System.out.println("jawaban anda benar");
System.out.print("poin anda adalah:");
System.out.println(poin+=1);}
else {
System.out.println("salah");
System.out.print("poin anda adalah:");
System.out.println(poin-=1);}
System.out.print("12+8=");
jawab = scan.nextInt();
if(jawab==20){
System.out.println("jawaban anda benar");
System.out.print("poin anda adalah:");
System.out.println(poin+=1);}
else {
System.out.println("jawaban anda salah");
System.out.print("poin anda adalah:");
System.out.println(poin-=1);}
System.out.print("4x4=");
jawab = scan.nextInt();
if(jawab==16){
System.out.println("jawaban anda benar");
System.out.print("poin anda adalah:");
System.out.println(poin+=1);}
else {
System.out.println("jawaban anda salah");
System.out.print("poin anda adalah:");
System.out.println(poin-=1);}
System.out.print("20+21=");
jawab = scan.nextInt();
if(jawab==41){
System.out.println("jawaban anda benar");
System.out.print("poin anda adalah:");
System.out.println(poin+=1);}
else {
System.out.println("jawaban anda salah");
System.out.print("poin anda adalah:");
System.out.println(poin-=1);}
System.out.print("10+65=");
jawab = scan.nextInt();
if(jawab==75){
System.out.println("jawaban anda benar");
System.out.print("poin anda adalah:");
System.out.println(poin+=1);}
else {
System.out.println("salah");
System.out.print("poin anda adalah:");
System.out.println(poin-=1);}
System.out.print("100-25=");
jawab = scan.nextInt();
if(jawab==75){
System.out.println("benar");
System.out.print("poin anda adalah:");
System.out.println(poin+=1);}
else {
System.out.println("salah");
System.out.print("poin anda adalah:");
System.out.println(poin-=1);}
System.out.print("12+7=");
jawab = scan.nextInt();
if(jawab==19){
System.out.println("benar");
System.out.print("poin anda adalah:");
System.out.println(poin+=1);}
else {
System.out.println("salah");
System.out.print("poin anda adalah:");
System.out.println(poin-=1);}
System.out.println("apakah anda ingin mengulang ? y/t)");
a= scan.next();
}while ("y".equals(a) );
}
}
/**
*
* @Newbie
*/
public class coba1 {
public static void main(String[] args) {
int jumlah = 0 ;
int input = 0 ;
String a = "y" ;
int poin = 0 ;
int jawab ;
do {
System.out.println ("Skor pertama anda adalah Nol");
System.out.println ("Jika jawaban anda benar Bertambah1");
System.out.println ("Jika jawaban anda salah Dikurangi 1");
Scanner scan = new Scanner (System.in);
System.out.print("1+5=");
jawab = scan.nextInt();
if(jawab==6){
System.out.println("jawaban anda benar");
System.out.print("poin anda adalah:");
System.out.println(poin+=1);}
else {
System.out.println("jawaban anda salah");
System.out.print("poin anda adalah:");
System.out.println(poin-=1);}
System.out.print("6:2=");
jawab = scan.nextInt();
if(jawab==3){
System.out.println("jawaban anda benar");
System.out.print("poin anda adalah:");
System.out.println(poin+=1);}
else {
System.out.println("jawaban anda salah");
System.out.print("poin anda adalah:");
System.out.println(poin-=1);}
System.out.print("5+5=");
jawab = scan.nextInt();
if(jawab==10){
System.out.println("jawaban anda benar");
System.out.print("poin anda adalah:");
System.out.println(poin+=1);}
else {
System.out.println("jawaban anda salah");
System.out.print("poin anda adalah:");
System.out.println(poin-=1);}
System.out.print("5x5=");
jawab = scan.nextInt();
if(jawab==25){
System.out.println("jawaban anda benar");
System.out.print("poin anda adalah:");
System.out.println(poin+=1);}
else {
System.out.println("salah");
System.out.print("poin anda adalah:");
System.out.println(poin-=1);}
System.out.print("12+8=");
jawab = scan.nextInt();
if(jawab==20){
System.out.println("jawaban anda benar");
System.out.print("poin anda adalah:");
System.out.println(poin+=1);}
else {
System.out.println("jawaban anda salah");
System.out.print("poin anda adalah:");
System.out.println(poin-=1);}
System.out.print("4x4=");
jawab = scan.nextInt();
if(jawab==16){
System.out.println("jawaban anda benar");
System.out.print("poin anda adalah:");
System.out.println(poin+=1);}
else {
System.out.println("jawaban anda salah");
System.out.print("poin anda adalah:");
System.out.println(poin-=1);}
System.out.print("20+21=");
jawab = scan.nextInt();
if(jawab==41){
System.out.println("jawaban anda benar");
System.out.print("poin anda adalah:");
System.out.println(poin+=1);}
else {
System.out.println("jawaban anda salah");
System.out.print("poin anda adalah:");
System.out.println(poin-=1);}
System.out.print("10+65=");
jawab = scan.nextInt();
if(jawab==75){
System.out.println("jawaban anda benar");
System.out.print("poin anda adalah:");
System.out.println(poin+=1);}
else {
System.out.println("salah");
System.out.print("poin anda adalah:");
System.out.println(poin-=1);}
System.out.print("100-25=");
jawab = scan.nextInt();
if(jawab==75){
System.out.println("benar");
System.out.print("poin anda adalah:");
System.out.println(poin+=1);}
else {
System.out.println("salah");
System.out.print("poin anda adalah:");
System.out.println(poin-=1);}
System.out.print("12+7=");
jawab = scan.nextInt();
if(jawab==19){
System.out.println("benar");
System.out.print("poin anda adalah:");
System.out.println(poin+=1);}
else {
System.out.println("salah");
System.out.print("poin anda adalah:");
System.out.println(poin-=1);}
System.out.println("apakah anda ingin mengulang ? y/t)");
a= scan.next();
}while ("y".equals(a) );
}
}
0 komentar:
Posting Komentar