Question

In: Computer Science

string getStyle() ; int getNumOfBedRooms() ; int getNumOfBathRooms(); int getNumOfCarsGarage(); int getYearBuilt(); int getFinishedSquareFootage() ; double...

string getStyle() ;
int getNumOfBedRooms() ;
int getNumOfBathRooms();
int getNumOfCarsGarage();
int getYearBuilt();
int getFinishedSquareFootage() ;
double getPrice(double p) ;
double getTax(double t) ;

void print() ;

houseType();
houseType(string s, int numOfBeds, int numOfBaths, int numOfCars,
int yBuilt, int squareFootage, double p, double t);
private:
string style;
int numOfBedrooms;
int numOfBathrooms;
int numOfCarsGarage;
int yearBuilt;
int finishedSquareFootage;
double price;
double tax;
};

Questions
a.Write the definition of the member function set so that private members are set accordingy to the parameters.
b. Write the definition of the member function print that prints the values of the data members.
c. Write the definition of the constructor of the class houseType so that the private member variables are initialized according to the parameters.
d. Write a Java statement that prints the value of the object newHouse.
e. Write a Java statement that declares an object house of type newHouse and initializes the member variables of house to "Ranch",3,2,2,2005,1300,185000 and 3600.0 respectively.
f. Which function members are accessors and which are mutators ?



Solved in Java please

Solutions

Expert Solution

a.

The definition of member function set that set the private members are as follows :

//function set with all parameters that is to be set for private memebrs

void set(string s, int numOfBeds, int numOfBaths, int numOfCars, int yBuilt, int squareFootage, double p, double t){

//all private members

//set the style

//this keyword is used to reference the current object

this.style = s;

//set the number of bed rooms
this.numOfBedrooms = numOfBeds;

//set the number of bath rooms
this.numOfBathrooms = numOfBaths;

//set the number of cars
this.numOfCarsGarage = numOfCars;

//set the built year
this.yearBuilt = yBuilt;

//set the finished square footage
this.finishedSquareFootage = squareFootage;

//set the price
this.price = p;

//set the tax
this.tax=t;

}

b. The definition of member function print that prints the value of data members

void print(){

//print the value of data members

System.out.println("Style : "+this.style​​​​​​​);

System.out.println("Number of bedrooms : "+this.numOfBedrooms​​​​​​​);

System.out.println("Number of bathrooms : "+this.numOfBathrooms​​​​​​​);

System.out.println("Number of cars : "+this.numOfCarsGarage​​​​​​​);

System.out.println("Built year : "+this.yearBuilt​​​​​​​);

System.out.println("Finished square footage : "+this.finishedSquareFootage​​​​​​​);

System.out.println("Price : "+this.price​​​​​​​);

System.out.println("Tax : "+this.tax​​​​​​​);

}

c. Constructor to initialize the private members, a constructor should not have a return type.

houseType(string s, int numOfBeds, int numOfBaths, int numOfCars, int yBuilt, int squareFootage, double p, double t){

//set the style

//this keyword is used to reference the current object

this.style = s;

​​​​​​​//set the number of bed rooms
this.numOfBedrooms = numOfBeds;

//set the number of bath rooms
this.numOfBathrooms = numOfBaths;

//set the number of cars
this.numOfCarsGarage = numOfCars;

//set the built year
this.yearBuilt = yBuilt;

//set the finished square footage
this.finishedSquareFootage = squareFootage;

//set the price
this.price = p;

//set the tax
this.tax=t;

}

d. Java statement to print the values of an object of class houseType. Consider obj is an object of class houseType , then the below statement can be used to print the values

//print() is the method in class houseType

//it display all the values

obj.print();

e. The statement to create an object house of class houseType , which also initializes the values is given below

houseType house = new houseType("Ranch",3,2,2,2005,1300,185000,3600.0);

//this creates an object house by calling the parameterized constructor declared in the class definition

//which will initialize all the member variables with the passed parameters

f. Accessors are used to access or get the value of private member variables. Mutators are used to set the value of the private member variables. Here,

Accessors are :

getStyle() ;
getNumOfBedRooms() ;
getNumOfBathRooms();
getNumOfCarsGarage();
getYearBuilt();
getFinishedSquareFootage() ;
getPrice() ;
getTax() ;


Related Solutions

#include <iostream> #include <string> #include <ctime> using namespace std; void displayArray(double * items, int start, int...
#include <iostream> #include <string> #include <ctime> using namespace std; void displayArray(double * items, int start, int end) { for (int i = start; i <= end; i++) cout << items[i] << " "; cout << endl; } //The legendary "Blaze Sort" algorithm. //Sorts the specified portion of the array between index start and end (inclusive) //Hmmm... how fast is it? /* void blazeSort(double * items, int start, int end) { if (end - start > 0) { int p =...
#include <iostream> #include <string> #include <ctime> using namespace std; void displayArray(double * items, int start, int...
#include <iostream> #include <string> #include <ctime> using namespace std; void displayArray(double * items, int start, int end) { for (int i = start; i <= end; i++) cout << items[i] << " "; cout << endl; } //The legendary "Blaze Sort" algorithm. //Sorts the specified portion of the array between index start and end (inclusive) //Hmmm... how fast is it? /* void blazeSort(double * items, int start, int end) { if (end - start > 0) { int p =...
int bintodec(string); // converts a binary number (represented as a STRING) to decimal int hextodec(string); //...
int bintodec(string); // converts a binary number (represented as a STRING) to decimal int hextodec(string); // converts a hexadecimal number (represented as a STRING) to decimal string dectobin(int); // converts a decimal number to binary (represted as a STRING) string dectohex(int); // converts a decimal number to hexadecimal (represted as a STRING) //the addbin and addhex functions work on UNsigned numbers string addbin(string, string); // adds two binary numbers together (represented as STRINGS) string addhex(string, string); // adds two hexadecimal...
#include <string> using namespace std; //using recursion no loops allowed int main() { double nums[] =...
#include <string> using namespace std; //using recursion no loops allowed int main() { double nums[] = { 13.8, 2.14, 51, 82, 3.14, 1.7, 4.89, 18, 5, 23.6, 17, 48, 5.6 };   //Challenge #2: print the list from given range   printList(nums, 0, 12); //13.8 2.14 51 .... 48 5.6   cout << endl;   //Challenge #3: print the list, but backwards   printReverse(nums, 0, 12); //5.6 48 17 ... 2.14 13.8   cout << endl;                  //Challenge #4: reverse order of items in list   reverse(nums,...
binarySearchLengths(String[] inArray, String search, int start, int end) This method will take in a array of...
binarySearchLengths(String[] inArray, String search, int start, int end) This method will take in a array of strings that have been sorted in order of increasing length, for ties in the string lengths they will be in alphabetical order. The method also takes in a search string and range of indexes (start, end). The method will return a String formatted with the path of search ranges followed by a decision (true or false), see the examples below. Example 1: binarySearchLengths({"a","aaa","aaaaa"},"bb",0,2) would...
int main() {    footBallPlayerType bigGiants[MAX];    int numberOfPlayers;    int choice;    string name;   ...
int main() {    footBallPlayerType bigGiants[MAX];    int numberOfPlayers;    int choice;    string name;    int playerNum;    int numOfTouchDowns;    int numOfcatches;    int numOfPassingYards;    int numOfReceivingYards;    int numOfRushingYards;    int ret;    int num = 0;    ifstream inFile;    ofstream outFile;    ret = openFile(inFile);    if (ret)        getData(inFile, bigGiants, numberOfPlayers);    else        return 1;    /// replace with the proper call to getData    do    {       ...
c++ #include <iostream> #include <string> #include <ctime> using namespace std; void displayArray(double * items, int start,...
c++ #include <iostream> #include <string> #include <ctime> using namespace std; void displayArray(double * items, int start, int end) { for (int i = start; i <= end; i++) cout << items[i] << " "; cout << endl; } //The legendary "Blaze Sort" algorithm. //Sorts the specified portion of the array between index start and end (inclusive) //Hmmm... how fast is it? /* void blazeSort(double * items, int start, int end) { if (end - start > 0) { int p...
class ArrayStringStack { String stack[]; int top; public arrayStringStack(int size) { stack = new String[size]; top...
class ArrayStringStack { String stack[]; int top; public arrayStringStack(int size) { stack = new String[size]; top = -1; } //Assume that your answers to 3.1-3.3 will be inserted here, ex: // full() would be here //empty() would be here... //push() //pop() //displayStack() } 1. Write two boolean methods, full( ) and empty( ). 2. Write two methods, push( ) and pop( ). Note: parameters may be expected for push and/or pop. 3. Write the method displayStack( ) that prints the...
double calculateCost (char, int, int) with Drjava calculateCost will compute and return the cost of the...
double calculateCost (char, int, int) with Drjava calculateCost will compute and return the cost of the vacation It will take as input 3 pieces of information. First, a char representing the type of room being rented (‘d’ double, ‘k’ kingsize, ‘p’ for penthouse). The second input is an int representing the number of days they will stay, the last input is an int representing the number of people staying. To compute the cost of the stay we start with a...
struct TempScale { double fahrenheit; double centigrade; }; struct Reading { int windSpeed; double humidity; TempScale...
struct TempScale { double fahrenheit; double centigrade; }; struct Reading { int windSpeed; double humidity; TempScale temperature; }; Reading reading; // reading structure variable Write statements that will store the following data below, in the variable written above in C++ please Wind Speed: 37 mph Humidity: 32% Fahrenheit temperature: 32 degrees Centigrade temperature: 0 degrees
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT