Uploaded by Muhammad Umar Asif

WAQAS JAVA

advertisement
Name:MUHAMMAD WAQAS
SAP ID: 70068263
SEC:S
SUMITTED TO:
“SIR SAUD”
PROGRAM:
package game;
public class Game {
public static void main(String[] args)
{
int plus=0;
player pl = new player();
player p2 = new player();
player p3 = new player();
player p4 = new player();
int play1=0,play2=0,play3=0,play4=0;
while(plus==0)
{
System.out.println("player 1's Turn :");
play1+=pl.gameplay();
System.out.println("Now P1 score is :
" + play1);
play1=pl.bonus(play1);
play1=pl.penalty(play1);
System.out.println("player 2's Turn :");
play2+=p2.gameplay();
System.out.println("Now P2 score is :
" + play2);
play2=p2.bonus(play2);
play2=p2.penalty(play2);
System.out.println("player 3's Turn :");
play3+=p3.gameplay();
System.out.println("Now P3 score is :
play3=p3.bonus(play3);
" + play3);
play3=p3.penalty(play3);
System.out.println("player 4's Turn :");
play4+=p4.gameplay();
System.out.println("Now P4 score is :
" + play4);
play4=p4.bonus(play4);
play4=p4.penalty(play4);
if(play1>=100||play2>=100||play3>=100||play4>=100)
{
plus++;
}
}
System.out.println("The Winner is : ");
if(play1>=100)
{
System.out.println("P1 ");
}
else if(play2>=100)
{
System.out.println("P2 ");
}
else if(play3>=100)
{
System.out.println("P3 ");
}
else if(play4>=100)
{
System.out.println("P4 ");
}
}
}
Class:
package game;
import java.util.Random;
public class player
{
public int gameplay()
{
Random r=new Random();
int i=r.nextInt(6)+1;
System.out.println( " gameplayed The No. : "+ i);
return i;
}
int bonus(int score)
{
if(score==1||score==4||score==8||score==21||score==28||score==50||score==71||score==86)
{
System.out.println(" +8 bonus points :");
score=score+8;
}
return score;
}
int penalty(int score)
{
if(score==38||score==36||score==48||score==62||score==88||score==95||score==97)
{
System.out.println(" -6 penalty points :");
score=score-6;
}
return score;
}
}
Download