Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create two classes, Trainee and NeoVsMorpheus, separately. Save them to Trainee.java and NeoVsMorpheus.java. Compile and run to test the program. Trainee Class a private int

Create two classes, Trainee and NeoVsMorpheus, separately. Save them to Trainee.java and NeoVsMorpheus.java. Compile and run to test the program.

Trainee Class

  • a private int data field named id

  • a private String data field named name

  • a private int data field named power

  • a private static int data fieled named numOfTrainee

  • a constructor that creates a trainee with specified id and name, and increment numOfTrainee by 1

  • a static getNumOfTrainee method that has no parameter and returns numOfTrainee

  • a getPower method that has no parameter and returns power

  • an addPower method (NOT setPower) that takes an int parameter, adds it to power, and returns no

    value

    NeoVsMorpheus Class This class has a public static final int data field named GAMES and is given a value of 5. This class is also the class with the main method that does the followings:

  • create a Scanner object named input, will be used for reading input

  • create a SecureRandom object named random, will be used for generating random numbers

  • create two Trainee objects named neo and Morpheus, with id 1, name Neo and id 2, name Morpheus

  • display current number of trainees by calling class Trainees getNumOfTrainee method

  • create three int variables named win, lose, tie, initialize them to zero

  • write a for loop, the loop body should run GAMES times (i.e. 5 times). Inside the loop:

o show the game round (Game 1 to Game 5) o create two int variable named neoPower and morpheusPower o use the SecureRandom object random to generate two random integer numbers between 1 and

100, assignment the two random numbers to neoPower and morpheusPower o display the two numbers o call the addPower method of Trainee object neo, use neoPower as the argument

o call the addPower method of Trainee object morpheus, use morpheusPower as the argument o use the getPower method to get then compare the current power values of neo and morpheus

if neos power > morpheuss power, then print Neo Win and increment win by 1 if neos power < morpheuss power, then print Morepheus Win and increment lose by 1 if neos power = morpheuss power, then print Tie and increment tie by 1

o display "Press to continue...", then use input to read a line after the loop had completed, show the summary information, including:

o the int variable win, as the times Neo wins o the int variable lose, as the times Morpheus wins (i.e. Neo loses) o the int variable tie, as the times of Tie o call the getPower method of Trainee object neo, to show neos final power o call the getPower method of Trainee object morpheus, to show morpheuss final power

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

Database Principles Programming And Performance

Authors: Patrick O'Neil, Elizabeth O'Neil

2nd Edition

1558605800, 978-1558605800

More Books

Students also viewed these Databases questions

Question

On the same day, Kyoto Fund converted $500,000 into JPY at

Answered: 1 week ago

Question

You have

Answered: 1 week ago