Ask Question
8 February, 09:11

Create an ItemSold class for Francis Pet Supply. Fields include an invoice number, description, and price. Create get and set methods for each field. Create a subclass named PetSold that descends from ItemSold and includes three Boolean fields that indicate whether the pet has been vaccinated, neutered, and housebroken, and include get and set methods for these fields. Write an application that creates two objects of each class, and demonstrate that all the methods work correctly. Save the files as ItemSold. java, PetSold. java, and DemoItemsAndPets. java.

+2
Answers (1)
  1. 8 February, 09:20
    0
    The program to this question can be given as:

    Program:

    class ItemSold / /define class.

    {

    private int invoiceNumber; / /define variable

    private String description;

    private float price;

    /define parameterized constructor.

    ItemSold (int invoiceNumber, String description, float price)

    {

    this. invoiceNumber = invoiceNumber;

    this. description = description;

    this. price = price;

    }

    public int getInvoiceNum () / /define function.

    {

    return invoiceNumber; / /return value.

    }

    public void setInvoiceNum (int invoiceNumber) / /define function

    {

    this. invoiceNumber = invoiceNumber; / /hold value.

    }

    public String getDescription () / /define function.

    {

    return description; / /return value

    }

    public void setDescription (String description) / /define function.

    {

    this. description = description; / /hold value.

    }

    public float getPrice () / /define function

    {

    return price; / /return value

    }

    public void setPrice (float price)

    {

    this. price = price; / /hold value.

    }

    }

    class PetSold extends ItemSold / /define class.

    {

    private Boolean vaccinated; / /define variable

    private Boolean neutered;

    private Boolean housebroken;

    //parameterized constructor

    PetSold (int invoiceNumber, String description, float price, Boolean vaccinated, Boolean neutered, Boolean housebroken)

    {

    super (invoiceNumber, description, price); / /use super function.

    this. vaccinated = vaccinated; / /holding value.

    this. neutered = neutered;

    this. housebroken = housebroken;

    }

    public Boolean isVaccinated () / /define function.

    {

    return vaccinated; / /return value.

    }

    public void setVaccinated (Boolean vaccinated) / /define function

    {

    this. vaccinated = vaccinated; / /holding value

    }

    public Boolean isNeutered () / /define function

    {

    return neutered; / /return value

    }

    public void setNeutered (Boolean neutered) / /define function

    {

    this. neutered = neutered; / /holding value

    }

    public Boolean isHousebroken () / /define function.

    {

    return housebroken; / /return value

    }

    public void setHousebroken (Boolean housebroken) / /define function

    {

    this. housebroken = housebroken; / /holding value

    }

    }

    public class DemoItemsAndPets / /define class.

    {

    public static void main (String[] args) / /define Main function

    {

    ItemSold ob1 = new ItemSold (101,"mug",6.95f); / /creating Object of ItemSold class & call constructor.

    //creating Object of PetSold class & call constructor.

    PetSold ob2 = new PetSold (102,"The book of love",234.97f, true, true, false);

    System. out. print (ob1. getDescription () + " was sold for " + ob1. getPrice ());

    System. out. print (ob2. getDescription () + " was sold in " + ob2. getPrice ());

    System. out. print (ob2. getDescription () + " Neutered status is: " + ob2. isNeutered () +

    "/nAnd it is " + ob2. isHousebroken () + " that " + ob2. getDescription () + " is housebroken");

    }

    }

    Output:

    mug was sold in 6.95

    The book of love was sold in 234.97.

    The book of love Neutered status is: true.

    And it is false that The book of love is housebroken.

    Explanation:

    In this program firstly we declare the class that's name is already given in the question. The class name is ItemSold. java, PetSold. java, and DemoItemsAndPets. java. In the ItemSold and PetSold class, we use the variable as a private, parameterized constructor and function. The variable is used for initializing the value in the constructor and the function is used for return and sets the value. In this class, there are two functions for each variable i. e get and set. The get function is used to return the value and set function is used to set the value. At the lass we define the main class that is DemoItemsAndPets in this class we create above class objects and pass the value in the constructor and print its value.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Create an ItemSold class for Francis Pet Supply. Fields include an invoice number, description, and price. Create get and set methods for ...” in 📗 Engineering if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers