Question: Create an ItemSold class for Francis Pet Supply. Fields include an invoice number, description, a...
(2 bookmarks)
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.
Expert Answer
Anonymousanswered this
Was this answer helpful?
0
0
2,868 answers
ItemSold.java
public class ItemSold {
private int invoiceNum;
private String description;
private float price;
public ItemSold(int invoiceNum, String description, float price) {
this.invoiceNum = invoiceNum;
this.description = description;
this.price = price;
}
public int getInvoiceNum() {
return invoiceNum;
}
public void setInvoiceNum(int invoiceNum) {
this.invoiceNum = invoiceNum;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public float getPrice() {
return price;
}
public void setPrice(float price) {
this.price = price;
}
}
DemoItemsAndPets.java
public class DemoItemsAndPets {
public static void main(String[] args) {
ItemSold item1 = new ItemSold(1001,"bucket",5.99f);
PetSold puppy = new PetSold(1002,"little bundle of cuteness",259.99f,true,true,false);
System.out.println(item1.getDescription() + " was sold for " + item1.getPrice());
System.out.println("A " + puppy.getDescription() + " was sold for " + puppy.getPrice());
System.out.println("The " + puppy.getDescription() + " Neutered status is: " + puppy.isNeutered() +
"\nAnd it is " + puppy.isHousebroken() + " that the " + puppy.getDescription() +" is housebroken");
}
}
PetSold.java
public class PetSold extends ItemSold{
private boolean vaccinated;
private boolean neutered;
private boolean housebroken;
public PetSold(int invoiceNum, String description, float price, boolean vaccinated, boolean neutered, boolean housebroken) {
super(invoiceNum, description, price);
this.vaccinated = vaccinated;
this.neutered = neutered;
this.housebroken = housebroken;
}
public boolean isVaccinated() {
return vaccinated;
}
public void setVaccinated(boolean vaccinated) {
this.vaccinated = vaccinated;
}
public boolean isNeutered() {
return neutered;
}
public void setNeutered(boolean neutered) {
this.neutered = neutered;
}
public boolean isHousebroken() {
return housebroken;
}
public void setHousebroken(boolean housebroken) {
this.housebroken = housebroken;
}
}
AshutoshSonwanianswered this
Was this answer helpful?
0
0
175 answers ANSWER : For the above problem, below is the VB code along with comments (in BOLD) and OUTPUT :
Public Class Form1 '' function to calculate and return doughnut price
Function doughnut() As Double
Dim x As Double '' chooses which ever radio button is checked
If Radio_Glaze.Checked = True Then
x = 0.75
ElseIf Radio_sugar.Checked = True Then
x = 0.75
ElseIf Radio_choc.Checked = True Then
x = 0.75
ElseIf Radio_filled.Checked = True Then
x = 0.95
End If
Return x
End Function ''function to calculate and return coffee price
Function coffee() As Double
Dim y As Double '' chooses which ever radio button is checked
If Radio_regular.Checked = True Then
y = 1.5
ElseIf Radio_capp.Checked = True Then
y = 2.75
ElseIf Radio_none.Checked = True Then
y = 0
End If
Return y
End Function '' function to calculate tax on subtotal and return tax
Function calc_tax(ByVal z As Double) As Double
Return z * (4.5 / 100)
End Function '' calculate button click event handler
Private Sub btn_calc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_calc.Click '' variable declarations
Dim doughnut_price As Double = 0
Dim coffee_price As Double = 0
Dim sub_total, tax, total As Double '' calling functions and assigning values to variables
doughnut_price = doughnut()
coffee_price = coffee() '' calculate subtotal
sub_total = doughnut_price + coffee_price '' calculate tax
tax = calc_tax(sub_total) '' calculate total
total = sub_total + tax '' display sub total, tax and total
txt_sub.Text = "$" + sub_total.ToString("#.##")
txt_tax.Text = "$" + tax.ToString("#.##")
txt_total.Text = "$" + total.ToString("#.##")
End Sub '' exit button click event handler
Private Sub btn_exit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_exit.Click '' closes application
Application.Exit()
End Sub
End Class OUTPUT :