Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a Java program. A simple game that consist of an arbitrary number of players, each player has a unique numerical id and gets assigned

Create a Java program. A simple game that consist of an arbitrary number of players, each player has a unique numerical id and gets assigned a random value between 0 and 1, the player with the highest value wins.

*Player Class

Design a Java class named Player that contains:

-A private int data field named id corresponding to the player number (default 0).

-A private double data field named val that stores a random value (default 0).

-A constructor that assigns initial values to id and val.

-Two get methods that return the stored values for id and val.

*Winner Class

Design a Java class named Winner that contains:

-The main Java method.

-A method called init_game where an array of players gets instantiated. The number of players needs to be specified as text input by using the Scanner class. The method instantiates, i.e. constructs, all players with their id number and a random value between 0 and 1. The player array with all their ids and values needs to be printed.

-A method called find_winner where random values assigned to each player are compared and the player with the largest value gets printed as the winner. Printout should include the player id and value corresponding to the winner.

*Game Package

Both classes should be stored inside a package named game.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Conceptual Database Design An Entity Relationship Approach

Authors: Carol Batini, Stefano Ceri, Shamkant B. Navathe

1st Edition

0805302441, 978-0805302448

More Books

Students also viewed these Databases questions

Question

What aspects would it be impossible to capture?

Answered: 1 week ago

Question

Enhance your words with effective presentation aids

Answered: 1 week ago