Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is the code i have so far 9. Define a class called House that has the following specification a. id > integer value representing

image text in transcribed

This is the code i have so farimage text in transcribed

9. Define a class called House that has the following specification a. id > integer value representing a house's id b. roomsinteger representing the number of rooms count integer with the default value of 0 Methods a. Constructor with id and rooms parameters Initializes all the instance variables of the object. Name b. Default Constructor- Initializes the object with an id value of -1 and a number of rooms equals to 1 c. toString - Returns a string with the id, followed by the rooms, followed by the count. Use the following the parameters after the instance variables. You must increase the count accordingly You must call the previous constructor in order to implement this one format: id: id rooms: rooms count: count where id and rooms represent the values associated with the object and count is the static variable value d. addToHouse - Static method that has as parameters a House reference and an integer representing a number of rooms. The method will increase the number of rooms of the provided house by the provided integer value. The method will return a reference to the House parameter e. addRooms Non-static method that has an integer as a parameter. The parameter represents the number of rooms to be added to the number of rooms associated with the current object. You must implement this method using the addToHouse method The following driver and associated output illustrates the functionality associated with the House class. Driver Output public static void main (String[ args) House housel new House (2, 4): System.out.println (housel) id: 2 rooms: 4 count:1 id: -1 rooms: 1 count: 2 id: 2 rooms: 64 count: 2 id: -1 rooms: 601 count: 2 House house2-new House () System.out.println (house2) House.addToHouse (House.addToHouse (housel, 10)50) System.out.println (housel) house2.addRooms (100) .addRooms (500) System.out.println (house2) 1 package Tester; 3 public class House 4 private int id, rooms; private static int cont= 0; e public House(int id, int rooms) this.id-id this.rooms-rooms; count++; public House) House defyal count++ new House(-1, 1); public static Object addToHouse (Object house, int roomNum) houserooms + roomNum return house; 23e public static void main(String[] args) /TODO Auto-generated method stub House house1 new House (2,4); System.out.println (house1); House house2 new House (2,4); System.out.println(house2); 30 House.addToHouse(House.addToHouse(housel, 10), 50); System.out.println (house1); house2.addRooms (100).addRooms (500); System.out.println (house2) 36 38 39 9. Define a class called House that has the following specification a. id > integer value representing a house's id b. roomsinteger representing the number of rooms count integer with the default value of 0 Methods a. Constructor with id and rooms parameters Initializes all the instance variables of the object. Name b. Default Constructor- Initializes the object with an id value of -1 and a number of rooms equals to 1 c. toString - Returns a string with the id, followed by the rooms, followed by the count. Use the following the parameters after the instance variables. You must increase the count accordingly You must call the previous constructor in order to implement this one format: id: id rooms: rooms count: count where id and rooms represent the values associated with the object and count is the static variable value d. addToHouse - Static method that has as parameters a House reference and an integer representing a number of rooms. The method will increase the number of rooms of the provided house by the provided integer value. The method will return a reference to the House parameter e. addRooms Non-static method that has an integer as a parameter. The parameter represents the number of rooms to be added to the number of rooms associated with the current object. You must implement this method using the addToHouse method The following driver and associated output illustrates the functionality associated with the House class. Driver Output public static void main (String[ args) House housel new House (2, 4): System.out.println (housel) id: 2 rooms: 4 count:1 id: -1 rooms: 1 count: 2 id: 2 rooms: 64 count: 2 id: -1 rooms: 601 count: 2 House house2-new House () System.out.println (house2) House.addToHouse (House.addToHouse (housel, 10)50) System.out.println (housel) house2.addRooms (100) .addRooms (500) System.out.println (house2) 1 package Tester; 3 public class House 4 private int id, rooms; private static int cont= 0; e public House(int id, int rooms) this.id-id this.rooms-rooms; count++; public House) House defyal count++ new House(-1, 1); public static Object addToHouse (Object house, int roomNum) houserooms + roomNum return house; 23e public static void main(String[] args) /TODO Auto-generated method stub House house1 new House (2,4); System.out.println (house1); House house2 new House (2,4); System.out.println(house2); 30 House.addToHouse(House.addToHouse(housel, 10), 50); System.out.println (house1); house2.addRooms (100).addRooms (500); System.out.println (house2) 36 38 39

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_2

Step: 3

blur-text-image_3

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

Beginning C# 5.0 Databases

Authors: Vidya Vrat Agarwal

2nd Edition

1430242604, 978-1430242604

More Books

Students also viewed these Databases questions

Question

Assess three steps in the selection process.

Answered: 1 week ago

Question

Identify the steps in job analysis.

Answered: 1 week ago