Question: Object oriented question Define a class named Household that has data members for the number of occupants and the annual income. Add the followings to

Object oriented question

Define a class named Household that has data members for the number of occupants and the annual income. Add the followings to the class Household: (a) A constructor that requires no argument and sets the occupants to 1 and the income to 0. (b) A constructor that receives two arguments, the value of which are assigned to the occupants and income instance variables respectively.

(c) Individual get and set methods for each data member

(d) toString() method which returns a String, for example, "Household: 4 occupants with annual income RM8000.00" where 4 is the number of occupants of the Household and 8000 is the annual income of the Household.

Write a main class that creates 2 objects of Household. Assign appropriate information for each of the object (using input data is an optional). The program then displays each Household's information and the average income.

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!