Question: Answer the following in Java! Your program must consist of two classes (as described below). Aside from the 'main()' method you are not to write

Answer the following in Java!

Your program must consist of two classes (as described below). Aside from the 'main()' method you are not to write static methods for this question.

Assignment description

  • Defines a class 'Adventurer'
  • Defines two private attributes: 'health' (type int) and 'name' (type String)
  • Methods:
  • A no argument constructor that sets the name and health attributes to the following starting values (e.g., "nameless" for the name and -1 for the health
  • A 'gainLevel()' method that displays a message onscreen ("Congratulations!") and increases health by 5.
  • An accessor ('get)' method called 'getHealth()' method that returns the value of the health attribute.
  • An accessor ('get)' method called 'getName()' method that returns the value of the name attribute.
  • A mutator ('set)' method called 'setHealth()' method that sets the value of the health attribute to the parameter passed into it.
  • A mutator ('set)' method called 'setName()' method that sets the value of the name attribute to the parameter passed into it.
  • Defines class 'Driver'. The 'main()' method will contain the following instructions
  • Declares a reference to an 'Adventurer'.
  • Creates/instantiates an Adventurer object by calling the default constructor.
  • Displays the health and name of the adventurer using the two 'get' methods, the default values should appear.
  • Uses the mutator methods to set the name to 'Balin' and health to 10.
  • Calls the 'gainLevel()' method of the adventurer.
  • Displays the health and name of the adventurer again via the get methods, the new values should appear 'Balin' and 15

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!