Point Value Letters ----------------------------------------------------------- 1 A, E, I, O, U, L, N, R, S, T ----------------------------------------------------------- 2 D, G ----------------------------------------------------------- 3 B, C, M, P ----------------------------------------------------------- 4 F, H, V, W, Y ----------------------------------------------------------- 5 K ----------------------------------------------------------- 8 J, X ----------------------------------------------------------- 10 Q, Z -----------------------------------------------------------Your program should prompt the user to enter a word, then it should use the nextLine method of the Scanner class that returns a String reference to the line of input entered by the user. Next, your program should check to see if the line entered is valid (a single word). If the input is valid, output the word and its Scrabble score, if not output the word and an error message. Here are some runs of my program (note the error handling):
% java ScrabbleScore This program computes a word's Scrabble score. Enter a single word: zoo The Scrabble score for 'zoo' is: 12 % java ScrabbleScore This program computes a word's Scrabble score. Enter a single word: HeLLo The Scrabble score for 'HeLLo' is: 8 % java ScrabbleScore This program computes a word's Scrabble score. Enter a single word: hello there Error: 'hello there' is not a valid word % java ScrabbleScore This program computes a word's Scrabble score. Enter a single word: 234566 Error: '234566' is not a valid word
% java RadioActiveDecay Year Atoms Left ----- ---------- 0 10000 1 5029 2 2546 3 1256 4 625 5 311 6 171 7 84 8 47 9 32 10 11 11 5 12 0 % java RadioActiveDecay Year Atoms Left ----- ---------- 0 10000 1 5053 2 2535 3 1288 4 623 5 319 6 155 7 85 8 44 9 19 10 11 11 5 12 2 13 1 14 0
area of circle with radius 1 PI number of darts inside circle ---------------------------- = -- ~= ----------------------------- area of square with side 2 4 number of darts thrownEach dart's position is given by an (x, y) coordinate, so you need to randomly generate two values for each dart throw, which will be somewhere inside the square. You can use the Pythagorean Theorm to determine if the dart is within the circle:
Your program shouls prompt the user to enter the number of dart throws, and then compute the approximation of pi. Each run should produce a slightly different approximation due to the random number generator. Here are two runs of my program:
% java MonteCarloPi This program approximates the value of PIusing the Montecarlo Method. Enter the number of darts to throw: 1000 The value of pi is: 3.104 % java MonteCarloPi This program approximates the value of PIusing the Montecarlo Method. Enter the number of darts to throw: 1000 The value of pi is: 3.092
In the comment at the top of your solution to problem (4) answer this question: Which pi approximation method is better? Why?
a note about debugging: if your program doesn't seem to be computing the correct value, add debugging output statements to your program to print out intermediate results (like the height and the width and the area values as you compute them for each rectangle). And, think about what type you want to use for each of these.