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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started