Question: Mr Jack Getting Dicey
Mr. Jack is now playing some dice games. In this game, 2 dice are rolled.
The score is calculated by summing the value on the 2 dice. However, when playing in special mode, if the number on both dice are equal, then one value if incremented, wrapping around to 1 if its value was 6.
Write a method Met to calculate the score. The parameters are 2 integers and 1 boolean. Each integer has the value of one of the dice. The boolean is true if the special mode is being played, otherwise it is false. You have to print the score depending on the values.
Only write the method - assume that the Class & main method have been defined.
Use the System.out.println() statement for printing.
Example Input: 4 3 false
Output: 7
Example Input: 4 4 false
Output: 8
Example Input: 4 4 true
Output: 9
Example Input: 6 6 true
Output: 7
Answers
METHOD....
public static void met(int a,int b,boolean c){
int result=0;
if(c){
if((a==b)&&a==6){
result=a+1;
System.out.println(result);
}
else if(a==b){
result=a+b+1;
System.out.println(result);
}
else{
result=a+b;
System.out.println(result);
}
}
else{
result=a+b;
System.out.println(result);
}
}
COMPLETE CODE........
import java.util.Scanner;
public class Program
{
public static void met(int a,int b,boolean c){
int result=0;
if(c){
if((a==b)&&a==6){
result=a+1;
System.out.println(result);
}
else if(a==b){
result=a+b+1;
System.out.println(result);
}
else{
result=a+b;
System.out.println(result);
}
}
else{
result=a+b;
System.out.println(result);
}
}
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int first_Dice_Score=sc.nextInt();
int second_Dice_Score=sc.nextInt();
boolean specialMode=sc.nextBoolean();
Program.met(first_Dice_Score,second_Dice_Score,specialMode);
}
}
Answer:
this is just method and required code
Explanation:
public static void Met(int a,int b,boolean c)
{
if((a==b)&&(a==6)&&c)
System.out.println(a+1);
else if((a==b)&&c)
System.out.println(a+b+1);
else
System.out.println(a+b);
}