What are the errors in this code? //1. //Filename: CarbonFootprintTest.java //The file tests the Car class and CarbonFootprint...

60.1K

Verified Solution

Question

Programming

What are the errors in this code?

//1.

//Filename: CarbonFootprintTest.java
//The file tests the Car class and CarbonFootprint class
public class CarbonFootprintTest {
    public static void main (String [] args) {

   CarbonFootprint[] obj = newCarbonFootprint[2];
   obj[0] = new CarbonFootprint(20);
   obj[1] = new Car(30);

    System.out.println(\"Carbon Foot Print foreach item (lbs):\n\");
    //additional info for to give general idea ofprogram
    for (CarbonFootprint test: obj)
       test.getCarbonFootprint();

}//end main method
}//end class

//2. Filename: CarbonFootprint.java It only include

s one abstract method
public class CarbonFootprint {
    //returns the carbon footprint of anobject
    public void GetCarbonFootprint();

}//end interface

//3. Filename: Car.java
public class Car extends CarbonFootprint {
   private double gallons;
   public Car( double g ){
      gallons = g;
   } // end Car constructor
   // one gallon of gas yields 20 pounds of CO2
      public abstract voidGetCarbonFootprint(){
      System.out.printf( \"Car that hasused %.2f gallons of gas: %.2f\n\",
         gallons,gallons * 20 );
   } // end function GetCarbonFootprint
} // end class Car

Answer & Explanation Solved by verified expert
4.2 Ratings (530 Votes)
1Filename CarbonFootprintTestjavaThe file tests the Car class and CarbonFootprint classpublic class CarbonFootprintTest public static void main String args CarbonFootprint obj new CarbonFootprint2obj0 new CarbonFootprint20here you cannot object forabstract classobj1 new Car30SystemoutprintlnCarbon Foot Print for each item lbsadditional info for to give general idea of programfor CarbonFootprint test objtestgetCarbonFootprinthere the method name    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students