Question3.(a)WriteaJavadefinitionforaclassPersondefinedbynameThenameofthepersonageTheperson’sageheightTheperson’sheight(inmeters)(youneedtodecidewhatisthetypeofeachattr...
Question 3.
(a)
Write a Java definition for a class Person defined by
name The name of the person
age The person’s age
height The person’s height (in meters)
(you need to decide what is the type of each attribute).
The class should contain two methods: a constructor (to set up an instance), and
a method greetings which displays the message
“Hello, my name is
name
, I am
age
, and I am
height
meters tall.”
(b) Write a Java application program that instantiates an object in the class Person
and then calls the greetings method.
(c) Define another greetings method which will print the message
“Hello your_name
, my name is name
, I am age
, and I am height meters tall.” (assume that your name is defined as a constant string in the main
method).
(d) Suppose we want to give this person an additional skill. She must be able to
convert a decimal length measure given in centimeters (to be read from the input)
to the imperial equivalent in inches.
Note:
use Person and TestPerson (driver class) for the two classes. You only
need to implement all the required methods in the one Person class. Extra
methods will be ignored.
展开