The Assignment This assignment is about using arrays. You will define two classes - one to...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
The Assignment This assignment is about using arrays. You will define two classes - one to represent a die with an arbitrary number of sides, and one to represent a collection of dice (these are the model classes). Then you will roll the entire collection repeatedly and use an array to build a histogram of the results. The view class for this assignment uses a main method and Standard Input and Output. The Dice Collection (model) A Die object can have any integer number of sides. The number of sides is specified when a Die is created and cannot be changed. A Die can report its number of sides, can report the side that is currently showing, and can be rolled. When a die is rolled, it generates and stores a new integer from 1 to n, where n is its number of sides. It has a toString() method that reports the number of sides and the number that is currently showing. That's all it can do. A DiceCollection object holds a set of Die objects in an array. The number of sides on each Die is specified by passing an array of integers to the DiceCollection constructor. This array is used to create and store the corresponding Die objects. A DiceCollection object can report the current sum of all the sides showing on the dice, it can report the maximum and minimum possible sums, and it can roll all the dice at once. It has a toString() method that reports all the dice, the minimum possible roll, the maximum possible roll, and the current total showing on the dice. It also has a histogram method, described below. That's all it can do. The Histogram Method The histogram method of DiceCollection accepts a parameter that specifies the number of rolls it should make. Then it rolls the entire collection of dice that number of times and returns an integer array of counters (i.e., a histogram) to keep track of how many times each possible sum got rolled. For example, if the sum of the dice is 12, you should add 1 to array element 12. See HistogramExample.java in this week's examples for some code that might help. Number of occurrences 1200 Gaussian Distribution of 2D6 IL. Possible randam value from adding two dice rolls Design and Implementation The exact details of the implementation and interface of these two classes is up to you, but you must respect e specifications given above, and you must create and hand in a UML class diagram to represent Die, DiceCollection and the association relationship between the two classes. This UML diagram can be hand drawn, or it you can use UMLet or draw.io. If you have another piece of software you would like to use check with your instructor The Main Method (View) The main method asks the user to enter the number of dice and number of sides for each die. Then it should create the DiceCollection and print it to the screen. Then it should present a menu in a loop that allows them to roll once or roll 100,000 times. The main method should do no calculations at all. If they choose to roll once, show the result by printing the dice they got and the sum. If choose 100,000 rolls, call the histogram method described above, and print the non-zero elements of the array, as shown in the example output. Handing In See the due date on Canvas. Hand in by attaching a zipped version of your .java (not .class) files and your class diagram to the Canvas assignment. Evaluation Your assignment will be evaluated for performance (20%), class diagram (20%), structure (40%), and documentation (20%) using the rubric in the drop box. Example Output Below is an example output of the program. User input is boldfaced and red. You are free to make your interface look however you like. How many dice? 4 Enter the number of sides of each die: 4 4 46 Dice Collection: d4-4 d4=1 d4=1 d6=4 Min=4 Max=18 Current=10 1=roll once, 2=roll 100000 times, 3=quit: 1 Dice Collection: d4=1 d4-4 d4=3 d6=3 Min 4 Max=18 Current=11 1=roll once, 2-roll 100000 times, 3-quit: 2 4: 246 5: 1096 6: 2489 5253 7: 8: 8288 9: 11423 56 ********** 10: 13782 11: 14621 12: 13790 13: 11507 14: 8347 15: 5257 16: 17: 18: 251 2597 1053 Optional Extra 1: Here's a nicer way to display the histogram, courtesy of Mark Yendt. Scale the numbers down and print asterisks to represent the quantities. 4: 257 BYE!!! 5: 1056 6: 2559 7: 5308 8: 8331 9:11303 10:13788 ************** 14: 8339 15: 5287 16: 2670 17: 1043 18: 271 Dice Collection: d4=1 d4=3 d4=1 d6=4 Min=4 Max=18 Current=9 ***** ******** 11:14643 *************** 12:13747 13:11398 *********** ************** ******** *** 1=roll once, 2=roll 100000 times, 3-quit: 3 Optional Extra 2: How about displaying the histogram as a bar graph using the FXAnimation Template? The Assignment This assignment is about using arrays. You will define two classes - one to represent a die with an arbitrary number of sides, and one to represent a collection of dice (these are the model classes). Then you will roll the entire collection repeatedly and use an array to build a histogram of the results. The view class for this assignment uses a main method and Standard Input and Output. The Dice Collection (model) A Die object can have any integer number of sides. The number of sides is specified when a Die is created and cannot be changed. A Die can report its number of sides, can report the side that is currently showing, and can be rolled. When a die is rolled, it generates and stores a new integer from 1 to n, where n is its number of sides. It has a toString() method that reports the number of sides and the number that is currently showing. That's all it can do. A DiceCollection object holds a set of Die objects in an array. The number of sides on each Die is specified by passing an array of integers to the DiceCollection constructor. This array is used to create and store the corresponding Die objects. A DiceCollection object can report the current sum of all the sides showing on the dice, it can report the maximum and minimum possible sums, and it can roll all the dice at once. It has a toString() method that reports all the dice, the minimum possible roll, the maximum possible roll, and the current total showing on the dice. It also has a histogram method, described below. That's all it can do. The Histogram Method The histogram method of DiceCollection accepts a parameter that specifies the number of rolls it should make. Then it rolls the entire collection of dice that number of times and returns an integer array of counters (i.e., a histogram) to keep track of how many times each possible sum got rolled. For example, if the sum of the dice is 12, you should add 1 to array element 12. See HistogramExample.java in this week's examples for some code that might help. Number of occurrences 1200 Gaussian Distribution of 2D6 IL. Possible randam value from adding two dice rolls Design and Implementation The exact details of the implementation and interface of these two classes is up to you, but you must respect e specifications given above, and you must create and hand in a UML class diagram to represent Die, DiceCollection and the association relationship between the two classes. This UML diagram can be hand drawn, or it you can use UMLet or draw.io. If you have another piece of software you would like to use check with your instructor The Main Method (View) The main method asks the user to enter the number of dice and number of sides for each die. Then it should create the DiceCollection and print it to the screen. Then it should present a menu in a loop that allows them to roll once or roll 100,000 times. The main method should do no calculations at all. If they choose to roll once, show the result by printing the dice they got and the sum. If choose 100,000 rolls, call the histogram method described above, and print the non-zero elements of the array, as shown in the example output. Handing In See the due date on Canvas. Hand in by attaching a zipped version of your .java (not .class) files and your class diagram to the Canvas assignment. Evaluation Your assignment will be evaluated for performance (20%), class diagram (20%), structure (40%), and documentation (20%) using the rubric in the drop box. Example Output Below is an example output of the program. User input is boldfaced and red. You are free to make your interface look however you like. How many dice? 4 Enter the number of sides of each die: 4 4 46 Dice Collection: d4-4 d4=1 d4=1 d6=4 Min=4 Max=18 Current=10 1=roll once, 2=roll 100000 times, 3=quit: 1 Dice Collection: d4=1 d4-4 d4=3 d6=3 Min 4 Max=18 Current=11 1=roll once, 2-roll 100000 times, 3-quit: 2 4: 246 5: 1096 6: 2489 5253 7: 8: 8288 9: 11423 56 ********** 10: 13782 11: 14621 12: 13790 13: 11507 14: 8347 15: 5257 16: 17: 18: 251 2597 1053 Optional Extra 1: Here's a nicer way to display the histogram, courtesy of Mark Yendt. Scale the numbers down and print asterisks to represent the quantities. 4: 257 BYE!!! 5: 1056 6: 2559 7: 5308 8: 8331 9:11303 10:13788 ************** 14: 8339 15: 5287 16: 2670 17: 1043 18: 271 Dice Collection: d4=1 d4=3 d4=1 d6=4 Min=4 Max=18 Current=9 ***** ******** 11:14643 *************** 12:13747 13:11398 *********** ************** ******** *** 1=roll once, 2=roll 100000 times, 3-quit: 3 Optional Extra 2: How about displaying the histogram as a bar graph using the FXAnimation Template?
Expert Answer:
Related Book For
Java An Introduction To Problem Solving And Programming
ISBN: 9780134462035
8th Edition
Authors: Walter Savitch
Posted Date:
Students also viewed these programming questions
-
Let A, B be sets. Define: (a) the Cartesian product (A B) (b) the set of relations R between A and B (c) the identity relation A on the set A [3 marks] Suppose S, T are relations between A and B, and...
-
can someone solve this Modern workstations typically have memory systems that incorporate two or three levels of caching. Explain why they are designed like this. [4 marks] In order to investigate...
-
A certain radioactive isotope is a by - product of some nuclear reactors. Due to an explosion, a nuclear reactor experiences a massive leak of this radioactive isotope. Fortunately, the isotope has a...
-
Annual cash inflows from two competing investment opportunities are given. Each investment opportunity will require the same initial investment. Requirement Assuming a 14% interest rate, which...
-
Gig Harbor Boating is the wholesale distributor of a recreational sailboat. Management provided the following data for budgeting purposes: Budgeted unit sales 6 2 0 Selling price per unit $ 2 , 0 3 0...
-
Locate questions that can be used during a debtors examination once a judgment is obtained. Try to find questions specific to California, as many states have limits on the types of questions that can...
-
Graham Railways Inc. is evaluating its operations and provides the following information: Required: For each of the years 2014 through 2016, calculate Graham Railwayss earnings per share and dividend...
-
Jessica received a gift of $7,500 at the time of her high school graduation. She invests it in an account that yields 10% compounded semiannually. What will the value of Jessica's investment be at...
-
Is it alright for non-native speaker of English to use a sound from his/her language as a substitute for an English sound that is nonexistent in his/her language? Why or why not? Explain your answer...
-
Beswick Limited manufactures mountain and road bikes. The trial balance at 3 1 December 2 0 2 0 was as follows: Dr Cr Revenue 3 , 5 6 4 , 3 0 0 Purchases 1 , 5 7 8 , 2 5 0 Inventory on 3 1 / 1 2 / 1...
-
Which type of international strategy is Microsoft using, and what is the evidence? Is this the best choice of an international strategy, and why? Which type of international mode(s) is Microsoft...
-
What is the difference between iron and steel? What isthe difference between wrought iron and cast iron? How can you tell a shear connection from a momentconnection? What is the role of each?
-
Analyze the role of narrative gaps and ellipses in constructing a compelling story. How do authors like Ernest Hemingway with his "iceberg theory" or Cormac McCarthy with his sparse prose create a...
-
Convert the following problem to a standard form linear programming problem and solve it using the simplex method. Show all your calculations. min |x1|+|x2|+|x3| subject to x1 + x2 1 2x1 + x3 = 3 and...
-
Consider the following scenario before answering this question, Tails-up is an established pet food company that manufactures both wet and dry food and treats for dogs and cats. One of the products...
-
1. You own a call option with a strike price of $27.50.What is your payoff on this option contract if the underlying stockis selling for $31.20 on the option expiration date? The payoff amount is the...
-
A business had revenues of $280,000 and operating expenses of $315,000. Did the business (a) Incur a net loss (b) Realize net income?
-
Implement your base class for the hierarchy from the previous exercise. Previous exercise. Consider a program that will keep track of the items in a schools library. Draw a class hierarchy, including...
-
Create a JavaFX application that acts as a simple calculator. Create buttons for digits 0-9 and a text field that concatenates digits for the current number as the buttons are clicked. Add additional...
-
Write a recursive method that will count the number of vowels in a string. Each time you make a recursive call, use the String method substring to construct a new string consisting of the second...
-
A system, consisting of \(2 \mathrm{~mol}\) of \(\mathrm{N}_{2}, 5 \mathrm{~mol}\) of \(\mathrm{H}_{2}\) and \(2 \mathrm{~mol}\) of \(\mathrm{NH}_{3}\) initially, is undergoing the following...
-
A thermodynamic system (a) Is a definite quantity of matter (b) Is surrounded by a boundary (c) Can exchange energy with its surroundings (d) All of these.
-
The study of thermodynamics enables us to understand (a) Whether the transformation of energy is feasible or not (b) To what extent the transformation will take place (c) In which direction the...
Study smarter with the SolutionInn App