Campbell Ritchie wrote:Unfortunately I don't like that constructor. A blood group isn't a char and vice versa. Nor is the Rhesus type. And how are you going to model people with group AB? Blood groups looks like a good use for an enum, and so would Rhesus type. Junilu has already shown you how to do that.
Exception in thread "main" java.lang.NullPointerException
at Patient.<init>(Patient.java:9)
at TestPatient.main(TestPatient.java:7)
Exception in thread "main" java.lang.NullPointerException
at Patient.<init>(Patient.java:10)
at TestPatient.main(TestPatient.java:8)
Campbell Ritchie wrote:Copy your code somewhere else. Delete every method. Add the methods back one by one, and test them as you add them. Then show us what is going wrong.
a. Create a class named Lease with fields that hold an apartment tenant’s name,
apartment number, monthly rent amount, and term of the lease in months. Include
a constructor that initializes the name to “XXX”, the apartment number to 0, the
rent to 1000, and the term to 12. Also include methods to get and set each of the
fields. Include a nonstatic method named addPetFee() that adds $10 to the
monthly rent value and calls a static method named explainPetPolicy() that
explains the pet fee. Save the class as Lease.java.
b. Create a class named TestLease whose main() method declares four Lease
objects. Call a getData() method three times. Within the method, prompt a user
for values for each field for a Lease , and return a Lease object to the main()
method where it is assigned to one of main() ’s Lease objects. Do not prompt the
user for values for the fourth Lease object, but let it continue to hold the default
values. Then, in main() , pass one of the Lease objects to a showValues() method
that displays the data. Then call the addPetFee() method using the passed Lease
object and confirm that the fee explanation statement is displayed. Next, call the
showValues() method for the Lease object again and confirm that the pet fee has
been added to the rent. Finally, call the showValues() method with each of the other
three objects; confirm that two hold the values you supplied as input and one holds
the constructor default values. Save the application as TestLease.java.