Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8920725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:20:59+00:00 2026-06-15T06:20:59+00:00

I am doing one exercise in the Absolute Java, Chapter 5, exercise 3. And

  • 0

I am doing one exercise in the Absolute Java, Chapter 5, exercise 3. And facing with a problem confusing me.
Let me introduce the background first.

The Question is :

In the land of Puzzlevania, Aron, Bob, and Charlie had an argument over which one of them was the greatest puzzler of all time.

To end the argument once and for all, they agreed on a duel to the death. Aaron was a poor shooter and only hit his target with a probability of 1>3. Bob was a bit better and hit his target with a probability of 1>2. Charlie was an expert marksman and never missed.

A hit means a kill and the person hit drops out of the duel. To compensate for the inequities in their marksmanship skills, the three decided that they would fire in turns, starting with Aaron, followed by Bob, and then by Charlie. The cycle would repeat until there was one man standing, and that man would be the Greatest Puzzler of All Time. An obvious and reasonable strategy is for each man to shoot at the most accurate shooter still alive, on the grounds that this shooter is the deadliest and has the best chance of hitting back.

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. Which 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?

My Question is:

How to use random numbers and the probabilities given in the problem to determine whether a shooter hits the target?

I don’t understand why should use random numbers and probabilities, is there any relationship between them?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T06:21:00+00:00Added an answer on June 15, 2026 at 6:21 am

    Generate a random number (in the range [0,1)) with Math.random, then simply check that it’s less than the given probability. So if someone had a 20% accuracy, we would have

    Math.random() < 0.20
    

    which will be true 20% of the time.


    I don’t understand why should use random numbers and probabilities, is there any relationship between them?

    I think the best way to understand this is to look at a simple case: consider flipping a coin. How would we simulate such an event? Well there is a 50% chance that it lands on tails, and a 50% chance that it lands on heads. Consequently, if we have a random variable that has a 50% chance of being true and a 50% chance of being false, we can use this variable to run the simulation, since it is analogous to the actual coin flip itself, with false being heads and true being tails (or the other way around, it really doesn’t matter). In this case, we would have something like

    boolean isHeads = Math.random() < 0.5;
    

    What is written above works in the same way, but with probabilities other than 50%.

    Now if you’re wondering why Math.random() < 0.5 has a 50% chance of being true, you should think about it geometrically. Math.random() returns a random number from 0 to 1 – and 0.5 cuts this interval in half. Therefore, there is a 50% chance that the random number will land to the right of 0.5, and a 50% chance that it will land to the left.

    Since Math.random() < 0.5 is essentially asking “is the random number to the left of .5“, it has a 50% chance of being true and a 50% chance of being false.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am doing a book exercise regarding the Ackermann function. I have one question
I am doing currently a sample exercise and i found one weird observation that
I'm doing an school exercise and I can't figure how to do one thing.
Im doing a small exercise to read a file which contains one long string
Iam doing one application in iphone.In this i need to get the browsing history
I'm doing one research on video encoding tools for flv. I tested flvtool2 and
i am doing one small application , wheich have login functionality, in the user
hi i am doing one application here i need to disply 6 images in
I am doing one project on Struts 2 that I am getting knowledge little
Before I have tried about doing one attachment (upload) for each record of my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.