//Will Douglas,
//Junior Division, Probability, Contest 1 Solution
import java.io.*;
import java.util.*;
import static java.lang.System.*;
class probability
{
static
Scanner kb;
void
run(Scanner in)
{
int selections, red, blue, total1, total2, one, two;
char
color1, color2, replace;
out.print("Enter the number of selections. ");
selections
= kb.nextInt();
out.print("Enter the number of red marbles. ");
red
= kb.nextInt();
out.print("Enter the number of blue marbles. ");
blue
= kb.nextInt();
total1
= red+blue;
//case 1
if(selections
== 1)
{out.print("Enter the color that is going to be chosen.
");
color1
= kb.next().charAt(0);
out.print("The answer is:: ");
if(color1
== 'R')
out.print(red);
else
out.print(blue);
out.println("/"+total1+"\n");}
//case 2+3
else
{ out.print("Enter
if you are replacing the first marble. Y or N. ");
replace
= kb.next().charAt(0);
out.print("Enter the color of the first marble.
");
color1
= kb.next().charAt(0);
out.print("Enter the color of the second marble.
");
color2
= kb.next().charAt(0);
//
first selection
if(color1
== 'R')
one
= red;
else
one
= blue;
//second
selection
if(replace
== 'Y')
{
if(color2
== 'R')
two
= red;
else
two
= blue;
out.println("The answer is::
"+one*two+"/"+total1*total1+"\n");
}
if(replace
== 'N')
{
if(color2
== 'R')
two
= red;
else
two
= blue;
total2
= total1-1;
if(one==two)
two
= two-1;
out.println("The answer is::
"+one*two+"/"+total1*total2+"\n");
}
}
}
public
static void main(String [] args)
{
probability
test = new probability();
kb
= new Scanner(in);
while(true) test.run(kb);
}
}