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 =...
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...
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...
void printList(double * A, int start, int end ) { if (start == end) //base case...
void printList(double * A, int start, int end ) { if (start == end) //base case { cout << A[start] << endl; } else //recursive case { cout << A[start] << endl; printList(A, start + 1, end); } } int main() { double nums[] = { 13.8, 2.14, 51, 82, 3.14, 1.7, 4.89, 18, 5, 23.6, 17, 48, 5.6 }; printList(nums, 0, 12); //13.8 2.14 51 .... 48 5.6 cout << endl; //HELP HERE: Using a recursive method on C++,...
Write a recursive method repeatNTimes(String s, int n) that accepts a String and an integer as...
Write a recursive method repeatNTimes(String s, int n) that accepts a String and an integer as two parameters and returns a string that is concatenated together n times. (For example, repeatNTimes ("hello", 3) returns "hellohellohello") Write a driver program that calls this method from the Main program. Need code in c#.
Debug please. It's in C++ #include<iostream> #include<string> using namespace std; template <class T> double half(int x)...
Debug please. It's in C++ #include<iostream> #include<string> using namespace std; template <class T> double half(int x) { double h = x / 2; return h; } class TuitionBill { friend ostream& operator<<(ostream, TuitionBill); private: string student; double amount; public: TuitionBill(string, double); double operator/(int); }; TuitionBill::TuitionBill(string student, double amt) { student = student; amount = amt; } double TuitionBill::operator/(int factor) { double half = amount / factor; return hafl; } ostream& operator<<(ostream& o, TuitionBill) { o << t.student << " Tuition:...
Make a function definition in C for the following: void insert (double *b, int c, double...
Make a function definition in C for the following: void insert (double *b, int c, double s, int pos); //Insert value s at position pos in array. //needs: // c > 0, pos >= 0, and pos <= c-1. Elements b[0]...b[c-1] exist. //this will do: //Elements from indexes pos up to c-2 have been moved up to indexes pos+1 up to c-1. The value s has been copied into b[pos]. //Note: the data that was in b[c-1] when the function...
This is my java method that is suppose to take data from a file(String, String, Double,...
This is my java method that is suppose to take data from a file(String, String, Double, Int ) and load that data into an object array. This is what I have and when I try to display the contents of this array it prints a "@" then some numbers and letters. which is not the correct output. any help correcting my method would be much appreciated. public void loadInventory(String fileName) { String inFileName = fileName; String id = null; String...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT