Java Reference
In-Depth Information
Write a program to simulate the duel using this strategy. Your program should
use random numbers and the probabilities given in the problem to determine
whether a shooter hits the target. Create a class named Duelist that contains the
dueler's name and shooting accuracy, a Boolean indicating whether the dueler is
still alive, and a method ShootAtTarget(Duelist target) that sets the target to
dead if the dueler hits his target (using a random number and the shooting
accuracy) and does nothing otherwise.
Once you can simulate a single duel, add a loop to your program that simulates
10,000 duels. Count the number of times that each contestant wins and print
the probability of winning for each contestant (e.g., for Aaron your program
might output “Aaron won 3,595/10,000 duels or 35.95%”).
An alternate strategy is for Aaron to intentionally miss on his first shot. Modify
the program to accommodate this new strategy and output the probability of
winning for each contestant. What strategy is better for Aaron, to intentionally
miss on the first shot or to try and hit the best shooter? Who has the best chance
of winning, the best shooter or the worst shooter?
Note: To generate a random number x , where 0 <= x
1, use x = Math.random(); .
This generates a random number between 0 and 1.
4.
You are interested in keeping track of the team members and competition informa-
tion for your school's annual entries in computer science programming competi-
tions. Each team consists of exactly four team members. Every year your team
competes in two competitions. As an initial start for your database, create a class
named Team that has the following data members:
// Name for the team
String teamName;
// Names for each team members.
String name1, name2, name3, name4;
// Info on each competition
Competition competition1, competition2;
Note that there is a much better way to represent the team members and
competitions using arrays; this is covered in a subsequent chapter. The class
should also have a method that outputs all the names of all team members and
the competition information to the console.
The Competition class contains variables to track the following:
String: Name of the competition, Name of the winning team, Name of the
runner-up
Integer: Year of the competition
Implement the Team and Competition classes with appropriate constructor,
accessor, and mutator methods. In entering data for past competitions, you note
that an entry is usually very similar to the previous year's entry. To help with the
Search WWH ::




Custom Search