Final Exam and the 1738 Program
Code
/// Name: Georgi Atanasov
/// Period: 5
/// Program Name: FinalExam
/// File Name: FinalExam.java
/// Date Finished: 1/20/2016
import java.util.Random;
import java.util.Scanner;
public class FinalExam
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
Random rng = new Random();
int heads = 0;
int tails = 0;
int n = 0;
System.out.println("");
System.out.println("");
System.out.println("<=================================1738=================================>");
System.out.println("Welcome to the Remy Boyz Simulator!");
System.out.println("Now how many coin flips would a Remy Boy like?");
System.out.println("");
int flips = keyboard.nextInt();
do
{
int flip = rng.nextInt(2);
if ( flip == 1 )
heads++;
else
tails++;
n++;
}
while (n != flips);
System.out.println("");
System.out.println("");
System.out.println("");
System.out.println("");
System.out.println("");
System.out.println("Heads: " + heads + " ");
System.out.println("Tails: " + tails + " ");
System.out.println("");
System.out.println("");
System.out.println("");
System.out.println("");
System.out.println("");
double probOfHeads = (double)heads / flips;
double probOfTails = (double)tails / flips;
System.out.println("");
System.out.println("Probability of heads: " + probOfHeads*100 + "%");
System.out.println("Probability of tails: " + probOfTails*100 + "%");
System.out.println("");
//I choose to use a do while because it makes everything easier and it gives us a chance for the music to get cooked the right way, and once it's cooked, I'm going to serve that meal that everybody's been waiting for.
System.out.println("<=================================1738=================================>");
System.out.println("");
System.out.println("");
}
}
Picture of the output