Java Mini Project
Java Mini Project
Project Guide
Prof. Pranoti Tamgave mam
1. Acknowledgement.
2. Introduction.
3. Program.
4. Output.
5. Information
6. Conclusion
ACKNOWLEDGEMENT
INTRODUCTION
Dice game are very much popular in the world and the board games of dice are also very much
popular. So here we created a simple Dice Game where you and Computer will have the battle
against you. In this program there is no need to put any input just run every time and get
output.
The program is made with “java.util.Random” for generating random number or picking up
random inputs from the program
. We are using Switch statement and IF statement in the program.
The result or output is very easy to understand there will be win, lose and draw. The output
will show the Dice value you got and the Dice value computer get and whose value is higher
will win the game and if equal then draw will be made.
Program:
import java.util.Random;
public class Program
{
public static void six(){
System.out.print("---------\n| * * |\n| * * |\n| * * |\n---------");
}
public static void five(){
System.out.print("---------\n| * * |\n| * |\n| * * |\n---------");
}
public static void four(){
System.out.print("---------\n| * * |\n| |\n| * * |\n---------");
}
}
public static void three(){
System.out.print("---------\n| * |\n| * |\n| * |\n---------");
}
public static void two(){
System.out.print("---------\n| * |\n| |\n| * |\n---------");
}
public static void one(){
System.out.print("---------\n| |\n| * |\n| |\n---------");
}
public static int random(){
Random r = new Random();
int a = r.nextInt(6)+1;
return a;
}
public static void main(String[] args) {
int you = random();
int computer = random();
System.out.println("you");
switch(you){
case 1: one(); break;
case 2: two(); break;
case 3: three(); break;
case 4: four(); break;
case 5: five(); break;
case 6: six(); break;
}
System.out.println("\n");
System.out.println("computer");
switch(computer){
case 1: one(); break;
case 2: two(); break;
case 3: three(); break;
case 4: four(); break;
case 5: five(); break;
case 6: six(); break;
}
if(you>computer){
System.out.println("\nLucky! you won. \n :)");
}
if(computer>you){
System.out.println("\nYou lost :( \n :)");
}
if(you==computer){
System.out.println("\nDraw! click run button again");
}
}
}
Output:
INFORMATION
• Here we are building a simple and fun dice game through java.
• We are using “java.util.random” class to generate random numbers.
• We created a dice pattern and the Dice value as well.
• We will using “switch statement” and “if statement” in the program.
• There is no need to input some value, just run and play the game.
Conclusion:
• We successfully created a simple dice game using java.
• Learned to use switch statement and If statement.
THANK YOU!