I have an assignment where I have a bonus game where I have to display four prizes and if the same number appears more than one, they user wins that amount. Problem I'm having is user wins every time! Very long winded code below. I have four prizes, with 5 chances of winning all with different percentages. 50%, 27%, 15%, 6% and 2%.
int[] bonus;
bonus = new int[5];
bonus[0] = 10;
bonus[0] = 20;
bonus[0] = 50;
bonus[0] = 200;
bonus[0] = 1000;
int [] bonusSum = new int[4];
int bonusAmount1=0;
int bonusAmount2=0;
numCount=0;
//Select 4 bonus numbers
while (numCount<4) {
Random ran = new Random();
int bonusNumber = rand.nextInt(99)+1;
if (bonusNumber<49) {
System.out.print("€10 ");
bonusSum[numCount]=10;
numCount++;
}else if(bonusNumber<27) {
System.out.print("€20 ");
bonusSum[numCount]=20;
numCount++;
}else if (bonusNumber<15) {
System.out.print("€50 ");
bonusSum[numCount]=50;
numCount++;
}else if (bonusNumber<06) {
System.out.print("€200 ");
bonusSum[numCount]=200;
numCount++;
}else if (bonusNumber<02) {
System.out.print("€1,000 ");
bonusSum[numCount]=1000;
numCount++;
}
}
if (bonusSum[0]==bonusSum[1] || bonusSum[0]==bonusSum[2] || bonusSum[0]==bonusSum[3])
{
bonusAmount1=bonusSum[0];}
if (bonusSum[1]== bonusSum[0] || bonusSum[1]==bonusSum[2] || bonusSum[1]==bonusSum[3])
{
if (bonusAmount1==0) {
bonusAmount1=bonusSum[1];
}else if (bonusAmount1 == bonusSum[1]) {
}else if (bonusAmount2==0) { bonusAmount2=bonusSum[1];
}else if (bonusAmount2 == bonusSum[1]) {
}
}
if(bonusSum[2]==bonusSum[0] || bonusSum[2]==bonusSum[1] || bonusSum[2]==bonusSum[3]){
if (bonusAmount1==0) {
bonusAmount1=bonusSum[2];
}else if (bonusAmount1 == bonusSum[2]) {
}else if (bonusAmount2==0) {
bonusAmount2=bonusSum[2];
}else if (bonusAmount2 == bonusSum[2]) {
}
}
if(bonusSum[3]==bonusSum[0]|| bonusSum[3]==bonusSum[1] || bonusSum[3]==bonusSum[2]) {
if (bonusAmount1==0) {
bonusAmount1=bonusSum[3];
}else if (bonusAmount1 == bonusSum[3]) {
}else if (bonusAmount2==0) {
bonusAmount2=bonusSum[3];
}else if (bonusAmount2 == bonusSum[3]) {
}
}
if (bonusAmount1<=0 && bonusAmount2<=0) {
System.out.println("Sorry no Luck this time ");
}else {
System.out.println("Congratulations you have won €"+(Math.addExact(bonusAmount1,
bonusAmount2))+"!");
}
}
}
Aucun commentaire:
Enregistrer un commentaire