Question: Hey guys i have this code for my CS class i have been stuck on for awhile. We use the program zybooks and I am
Hey guys i have this code for my CS class i have been stuck on for awhile. We use the program zybooks and I am not getting full credit with the code I made so I am not really sure whats going on. I was hoping someone could rebuild it from scratch but if you want to see my current code let me know. Here is the prompt and eveything I have so far.
Thanks in advance!
[CODE] [50pts] Write a class encapsulating the concept of a house, assuming a house has the following attributes: value (in dollars), a city location, and number of bedrooms. Your class name should be House and your code should be in a file called House.java. You will need to create this file (remember to NOT check the box to create a main method). In this class, include:
Private instance variables for the previously-mentioned attributes
A default constructor An overloaded constructor
Accessor and mutator methods (i.e., get and set methods)
The toString method
The equals method
Your default constructor should typically initialize the instance variables to some default values that you feel are appropriate (lets just go with a $100,000, 2-bedroom home in Azusa). The overloaded constructor should pass in values for value, city location and number of bedrooms which are used to initialize the class instance variables.
Also, use the provided template file (CS220_Lab11.java) as your client class to test all the methods in your class. So, you would want to test the default and overloaded constructors, as well as accessors, mutators, toString and equals methods. Since this is the first time youve ever thought about creating a client to test a user-defined class, weve included a sample of how you should do this below.
Provided template typed********
import java.text.DecimalFormat;
public class CS220_Lab11 {
public static void main(String[] args) {
// Your program should always output your name and the lab/problem
// number. DO NOT DELETE OR COMMENT OUT. Replace with relevant info.
System.out.println("Dan Grissom & My Partner");
System.out.println("Lab 11, Problem 3");
System.out.println("");
// Your code should go below this line
// Decimal format....do not need cents b/c negligible
// compared to hundreds of thousands of dollars
DecimalFormat df = new DecimalFormat("$#, ##0");
// Testing default constructor and to String()
House defaultHouse = new House();
System.out.println (defaultHouse.toString());
System.out.println(); // Spacing
// Testing overloaded constructor and toString()
House bigHouse = new House (1400000,"Pasadena", 6);
System.out.println(bigHouse.toString());
// Tests the getters
System.out.println("Before modifying big house using setters:");
System.out.println("Big house value: " + df.format(bigHouse.getValue()));
System.out.println("Big house location: " + bigHouse.getLocation());
System.out.println("Big house bedrooms: " + bigHouse.getNumBedrooms());
// Apply the setters....will test their functionality
// by calling getters again next..
bigHouse.setValue (3200000);
bigHouse.setLocation ("Hollywood");
bigHouse.setNumBedrooms (14);
System.out.println(); // Spacing
// Tests that the setters did their jobs
System.out.println("After modifying big house using setters:");
System.out.println("Big house value: " + df. format (bigHouse.getValue()));
System.out.println("Big house location: " + bigHouse.getLocation());
System.out.println("Big house bedrooms " + bigHouse.getNumBedrooms());
System.out.println(); // Spacing
// Test the equals() method on case that should return false
System.out.print("The default house and big house ");
if (defaultHouse.equals(bigHouse))
System.out.println("are the SAME houses!");
else
System.out.println("are DIFFERENT houses!");
System.out.println(); // Spacing
// Test the equals() method on case that should return true
House identicalBigHouse = new House (3200000, "Hollywood", 14);
System.out.print("The identical big house and big house ");
if (identicalBigHouse.equals (bigHouse))
System.out.println("are the SAME houses!");
else
System.out.println("are DIFFERENT houses!");
}
}
I typed it out so here is the original in case I made any mistakes

CS220_Lab11.java Contents public static void main (String[] args) // Your program should always output your name and the lab/problem // number. DO NOT DELETE OR COMMENT OUT. Replace with relevant info System.out.println ("Dan Grissom & My Partner") System.out.println ("Lab 9, Problem 2") System.out.println("") Your code should go below this 1ine 7 Decimal format....do not need cents b/c negligible // compared to hundreds of thousands of dollars DecimalFormat df = new DecimalFormat ("$#,##0"); // Testing default constructor and toString () House defaultHouse = new House(); System.out.println (defaultHouse.toString )) System.out.println) Spacing // Testing overloaded constructor and toString ) House bigHouse new House (1400000, "Pasadena", 6) System.out.println (bigHouse.toString )) // Tests the getters System.out.println ("Before modifying big house using setters:"); System.out.println ("Big house value: " df.format (bigHouse.getvValue ))) System.out.println ("Big house location:"+ bigHouse.getLocation )) System.out.println ("Big house bedrooms:"+ bigHouse.getNumBedrooms )) /Apply the setters....will test their functionality // by calling getters again next... bigHouse.setValue (3200000) bigHouse.setLocation ("Hollywood") i bigHouse.setNumBedrooms (14) System.out.println) Spacing // Tests that the setters did their jobs System.out.println ("After modifying big house using setters:") System.out.println("Big house value:" df.format (bigHouse.getvalue ))) System.out.println("Big house location: "bigHouse.getLocation )) System. out.println ("Big house bedrooms:"+ bigHouse.getNumBedrooms )) System.out.println): // Spacing // Test the equals() method on case that should return false System.out.print ("The default house and big house ") if (defaul tHouse.equals (bigHouse)) System.out.printin ("are the SAME houses!") else System.out.println ("are DIFFERENT houses!") System.out.println ): I1 Spacing // Test the equals) method on case that should return true House identicalBigHouse- new House (3200000, "Hollywood", 14) system.out.print ("The identical big house and big house " if (identicalBigHouse.equals (bigHouse)) System.out.println ("are the SAME houses!") else System.out.println ("are DIFFERENT houses!")
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
