Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Essentials of Database Management

Authors: Jeffrey A. Hoffer, Heikki Topi, Ramesh Venkataraman

1st edition

133405680, 9780133547702 , 978-0133405682

More Books

Students also viewed these Databases questions

Question

Explain the Neolithic age compared to the paleolithic age ?

Answered: 1 week ago

Question

What is loss of bone density and strength as ?

Answered: 1 week ago