Question

JAVA ONLY - Complete the numbered comments import java.text.DecimalFormat; /** * Complete the code below the...

JAVA ONLY - Complete the numbered comments

import java.text.DecimalFormat;

/**
 * Complete the code below the numbered comments, 1 - 4.
 * Do not change the pre-written code
 * @author 
 */
public class HouseListing
{
    /*
     * 1. Create instance variables as shown in UML
     */

    
    /* 
     * default constructor (If an empty house object is created)
     * assigns listingNumber the text string 0000
     * assigns houseDescription an empty text string
     * assigns listingPrice the value of 1.0
     */
    public HouseListing( )
    {
        listingNumber = "0000";
        houseDescription = "";
        listingPrice = 1.0;
    }
    /* 
     * 2.
     * Overloaded Constructor
     * call the method setListingNumber() passing listCode
     * assigns houseDescription the value style holds
     * call the method setPrice() passing price
     */
    public HouseListing(String listCode, String style, double price)
    {
        
    }
    /*
     * accessor method
     * returns listingNumber
     */
    public String getHouseListing( )
    {
        return listingNumber;
    }
    /*
     * accessor method
     * returns houseDescription
     */
    public String getHouseDescription( )
    {
        return houseDescription;
    }
    /*
     * accessor method
     * returns listingPrice
     */
    public double getListPrice( )
    {
        return listingPrice;
    }
    /* 3.
     * mutator method
     * parameter changedNumber
     * method checks the number of characters in the parameter
     * if the number of characters is less than 4 assign 
     * listingNumber a string of 4 zeros (0000), otherwise assign 
     * listingNumber the value of the parameteer
     */
    public void setListingNumber(String changedNumber)
    {
        
    }
    /*
     * mutator method
     * parameter changeStyle
     * assigns houseDescription the parameter value
     */
    public void setHouseDescription(String changeStyle)
    {
       houseDescription = changeStyle;  
    }
    
    /* 4.
     * mutator method
     * parameter changePrice
     * method checks the parameter's value if the value is zero 
     * or less assign listingPrice one dollar (1.0), otherwise 
     * assign listingPrice the parameter value
     */
    public void setPrice(double changedPrice)
    {
        
    }
    /* 5.
     * this method displays a formatted text string with the values the
     * instance variables hold. See example of output for formatting
     */
    @Override
    public String toString( )
    {
        return ""; // written for syntax only, an error otherwise                
    }

    
}

Homework Answers

Answer #1

complete java code as per comments

(code to copy)

import java.text.DecimalFormat;

/**
 * Complete the code below the numbered comments, 1 - 4.
 * Do not change the pre-written code
 * @author 
 */
public class HouseListing
{
    /*
     * 1. Create instance variables as shown in UML
     */
     private String listingNumber;
     private String houseDescription;
     private double listingPrice;

    
    /* 
     * default constructor (If an empty house object is created)
     * assigns listingNumber the text string 0000
     * assigns houseDescription an empty text string
     * assigns listingPrice the value of 1.0
     */
    public HouseListing( )
    {
        listingNumber = "0000";
        houseDescription = "";
        listingPrice = 1.0;
    }
    /* 
     * 2.
     * Overloaded Constructor
     * call the method setListingNumber() passing listCode
     * assigns houseDescription the value style holds
     * call the method setPrice() passing price
     */
    public HouseListing(String listCode, String style, double price)
    {
        setListingNumber(listCode);
        houseDescription = style;
        setPrice(price);
    }
    /*
     * accessor method
     * returns listingNumber
     */
    public String getHouseListing( )
    {
        return listingNumber;
    }
    /*
     * accessor method
     * returns houseDescription
     */
    public String getHouseDescription( )
    {
        return houseDescription;
    }
    /*
     * accessor method
     * returns listingPrice
     */
    public double getListPrice( )
    {
        return listingPrice;
    }
    /* 3.
     * mutator method
     * parameter changedNumber
     * method checks the number of characters in the parameter
     * if the number of characters is less than 4 assign 
     * listingNumber a string of 4 zeros (0000), otherwise assign 
     * listingNumber the value of the parameteer
     */
    public void setListingNumber(String changedNumber)
    {
        if(changedNumber.length()<4){
            listingNumber = "0000";
        }else{
            listingNumber=changedNumber;
        }
    }
    /*
     * mutator method
     * parameter changeStyle
     * assigns houseDescription the parameter value
     */
    public void setHouseDescription(String changeStyle)
    {
       houseDescription = changeStyle;  
    }
    
    /* 4.
     * mutator method
     * parameter changePrice
     * method checks the parameter's value if the value is zero 
     * or less assign listingPrice one dollar (1.0), otherwise 
     * assign listingPrice the parameter value
     */
    public void setPrice(double changedPrice)
    {
        if(changedPrice<=0){
            listingPrice = 1.0;
        }else{
            listingPrice = changedPrice;
        }
    }
    /* 5.
     * this method displays a formatted text string with the values the
     * instance variables hold. See example of output for formatting
     */
    @Override
    public String toString( )
    {
        return "List Code: "+listingNumber+"\nStyle: "+houseDescription+"\nPrice: "+listingPrice; 
    }

    
}

code screenshot

Compilation was succesful without errors.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
The following is for a Java Program Create UML Class Diagram for these 4 java classes....
The following is for a Java Program Create UML Class Diagram for these 4 java classes. The diagram should include: 1) All instance variables, including type and access specifier (+, -); 2) All methods, including parameter list, return type and access specifier (+, -); 3) Include Generalization and Aggregation where appropriate. Java Classes description: 1. User Class 1.1 Subclass of Account class. 1.2 Instance variables __ 1.2.1 username – String __ 1.2.2 fullName – String __ 1.2.3 deptCode – int...
1. Circle: Implement a Java class with the name Circle. It should be in the package...
1. Circle: Implement a Java class with the name Circle. It should be in the package edu.gcccd.csis. The class has two private instance variables: radius (of the type double) and color (of the type String). The class also has a private static variable: numOfCircles (of the type long) which at all times will keep track of the number of Circle objects that were instantiated. Construction: A constructor that constructs a circle with the given color and sets the radius to...
Use the class definition below to answer the following questions. public class TrafficLight { String stopLight...
Use the class definition below to answer the following questions. public class TrafficLight { String stopLight = "red"; String waitLight; String goLight; public void setStopLight(String colour) { stopLight = colour; } public String getGreenLight() { return goLight; } } How many field attributes are there in the TrafficLight class? Name a field attribute for this class. What is the name of the method that is an accessor? What is the name of the method that is a mutator? What is...
Use the class definition below to answer the following questions. public class TrafficLight { String stopLight...
Use the class definition below to answer the following questions. public class TrafficLight { String stopLight = "red"; String waitLight; String goLight; public void setStopLight(String colour) { stopLight = colour; } public String getGreenLight() { return goLight; } How many field attributes are there in the TrafficLight class? Name a field attribute for this class. What is the name of the method that is an accessor? What is the name of the method that is a mutator? What is the...
Use the class definition below to answer the following questions. public class TrafficLight { String stopLight...
Use the class definition below to answer the following questions. public class TrafficLight { String stopLight = "red"; String waitLight; String goLight; public void setStopLight(String colour) { stopLight = colour; } public String getGreenLight() { return goLight; } } 1. How many field attributes are there in the TrafficLight class? 2. Name a field attribute for this class. 3. What is the name of the method that is an accessor? 4. What is the name of the method that is...
Please show fully functioning java code and outputs. Design a Java Animal class (assuming in Animal.java...
Please show fully functioning java code and outputs. Design a Java Animal class (assuming in Animal.java file) and a sub class of Animal named Cat (assuming in Cat.java file).   The Animal class has the following protected instance variables: boolean vegetarian, String eatings, int numOfLegs and the following public instance methods: constructor without parameters: initialize all of the instance variables to some default values constructor with parameters: initialize all of the instance variables to the arguments SetAnimal: assign arguments to all...
Use the class definition below to answer the following questions. [Total 8 Marks] public class TrafficLight...
Use the class definition below to answer the following questions. [Total 8 Marks] public class TrafficLight { String stopLight = "red"; String waitLight; String goLight; public void setStopLight(String colour) { stopLight = colour; } public String getGreenLight() { return goLight; } } 1 :How many field attributes are there in the TrafficLight class? 2 :Name a field attribute for this class. 3 :What is the name of the method that is an accessor? 4 :What is the name of the...
Using Java language.... Polymorphism of Interfaces : Take the Account class from the last chapter and...
Using Java language.... Polymorphism of Interfaces : Take the Account class from the last chapter and make a java program for your bank. However, there is another type of customer that may not have money in the bank and may not in fact have a back account with this bank at all, but may have a loan here. Make another class in the application you are making called CarLoan. Carloan's should have a name, amount owed, a rate, and a...
Modify the Employee9C superclass so that is an abstract superclass with a constructor to set its...
Modify the Employee9C superclass so that is an abstract superclass with a constructor to set its variables (firstName and lastName). It should contain an abstract method called payPrint. Below is the source code for the Employee9C superclass: public class Employee9C {    //declaring instance variables private String firstName; private String lastName; //declaring & initializing static int variable to keep running total of the number of paychecks calculated static int counter = 0;    //constructor to set instance variables public Employee9C(String...
Please use java language in an easy way with comments! Thanks! Expand your below program, so...
Please use java language in an easy way with comments! Thanks! Expand your below program, so it can include cursed items (weapons that break, armor that causes more damage when worn). In order to do that, write an interface called "CursedItem". Then create subclasses of the armor, and weapon class that implement the CursedItem interface => CursedWeapon: using a random number generator, there is a 4 in 10 chance that the weapon breaks during combat. CursedArmor: this item amplifies the...