hi guys ok so i just recently started to code and my first real object is to do this dungeons of dragon game kinda thing . Either way what i have to do is that the user has to input a value that is bigger than 10 (num>10) and if it is also a even number the (num%2=0) it will give a +1 at each even number. example if the input is 12 which is the first even number after ten the bonus value would be +1, and if the input is 14 the bonus value would be +2. If the input was 13 which only have still passed 1 even number the output would be +1. idk if you get understand it . Below is the code iv come up with and its half done and i from what i know iv created a if loop for every statement iv made and its a big hassle . is there another way to do it. Please help me out
import java.util.Scanner;
class Main2
{ public static void main (String arg[])
{ int bonusstr = 0,bonusdex =
0,bonuscon=0,bonusintel=0,bonuswise=0,bonuschara=0;
Scanner sc=new Scanner(System.in);
System.out.print("Enter Level");
int Level= sc.nextInt();
System.out.print("Enter Str value");
int str =sc.nextInt();
if(str==10)
{bonusstr=0;
}
else if(str%2==0 && str>=10)
{bonusstr=(str-10)/2;
}
else if(str%2==1 && str>=10)
{bonusstr=((str-10)-1)/2;
}
System.out.print("Enter dex value");
int dex =sc.nextInt();
if(dex==10)
{bonusdex=0;
}
else if(dex%2==0 && dex>=10)
{bonusdex=(dex-10)/2;
}
else if(dex%2==1 && dex>=10)
{bonusdex=((dex-10)-1)/2;
}
System.out.print("Enter con value");
int con =sc.nextInt();
if(con==10)
{bonuscon=0;
}
else if(con%2==0 && con>=10)
{bonuscon=(con-10)/2;
}
else if(con%2==1 && con>=10)
{bonuscon=((con-10)-1)/2;
}
System.out.print("Enter int value");
int intel =sc.nextInt();
if(intel==10)
{bonusintel=0;
}
else if(intel%2==0 && intel>10)
{bonusintel=(intel-10)/2;
}
else if(intel%2==1 && intel>10)
{bonusintel=((intel-10)-1)/2;
}
System.out.print("Enter wise value");
int wise =sc.nextInt();
if(wise==10)
{bonuswise=0;
}
else if(wise%2==0 && wise>10)
{bonuswise=(wise-10)/2;
}
else if(wise%2==1 && wise>10)
{bonuswise=((wise-10)-1)/2;
}
System.out.print("Enter cha value");
int chara =sc.nextInt();
if(chara==10)
{bonuschara=0;
}
else if(chara%2==0 && chara>10)
{bonuschara=(chara-10)/2;
}
else if(chara%2==1 && chara>10)
{bonuschara=((chara-10)-1)/2;
}
double hitpoints= Level*(Math.random()*1000 %6+1);
System.out.print("\nLevel \t"+Level+" \nStr \t"+str+" ["+bonusstr+"] \nDex \t"+dex+" ["+bonusdex+"] \nCon \t"+con+" ["+bonuscon+"] \nInt \t"+intel+" ["+bonusintel+"]\nwise \t"+wise+" ["+bonuswise+"] \nCha \t"+chara+" ["+bonuschara+"] \nhp \t"+hitpoints+" ");
}
}
Aucun commentaire:
Enregistrer un commentaire