Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create an inheritance hierarchy for a business that sells building materials. La

ID: 3937180 • Letter: C

Question

Create an inheritance hierarchy for a business that sells building materials.

Lab 12 – Due 11/8 Create an inheritance hierarchy for a business that sells building materials, Some materials are sold by weight, others are sold by volume, and others are sold by quantity, write a member function to calculate cost using the following formulas, - by weight: $O,05/lb - by volume, SO.92 / cubic ft - by quantity 1 - 10 SO,1/ unit 11- 50 SO9/ unit 51+ SO96/ unit In main LL Instantiate an object of each of the different types, item with weight of 2345 lbs - item with volume of 6SSD cubic fit - item with a quantity of 343 2, Calculate and display the cost for each - call a global function that returns the celluccessed values use polymorphism

Explanation / Answer

Ans:

interface CostCalculation
{
   public abstract double calculateCost();
}
class SoldByWeight implements CostCalculation
{
   int input;
   SoldByWeight(int input){
   this.input=input;
   }

   @Override
   public double calculateCost()
   {
       double total=0.05*input;
       return total;
   }
}
class SoldByVolume implements CostCalculation
{
   int input;
   SoldByVolume(int input){
   this.input=input;
   }
   @Override
   public double calculateCost(){
   double total=0.09*input;
   return total;
   }
}
class SoldByQuantity implements CostCalculation
{
   int input;
   SoldByQuantity(int input){
   this.input=input;
   }
   @Override
   public double calculateCost(){
   double total=0;
   if(input>=51)
       total=0.06*input;
   else if(input>=11)
       total=0.09*input;
   else
       total=0.11*input;
   return total;
   }
}
//main program
class MainDemo
{
   public static void main(String args[])
   {
SoldByWeight w=new SoldByWeight(2345);
SoldByVolume v=new SoldByVolume(6550);
SoldByQuantity q=new SoldByQuantity(343);

System.out.println(w.calculateCost());
System.out.println(v.calculateCost());
System.out.println(q.calculateCost());

   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote