Menu

Hi Need Someone Help Two Exercises Java Exercises Must Done Java Exercise 1 Governments Co Q43877608

Hi, I need someone to help me with two exercises in JAVA. Theexercises must be done in Java.

———————————————————–

Exercise 1

Governments and companies worldwide are becoming increasinglyconcerned with carbon footprints (annual releases of carbon dioxideinto the atmosphere) from buildings burning various types of fuelfor heat, vehicles burning fuels for power, and the like.

  1. Create 3 small classes unrelated by inheritance: Building, Car,and Bicycle
  2. Give each class the unique attributes and behaviors asspecified in the class diagram in Figure 1 below. Create a singleconstructor for each class to allow consumers of the class toprovide initial values for each attribute.
  3. Write an interface CarbonFootprint with a getCarbonFootprintmethod.
  4. Have each of your classes implement that interface so that itsgetCarbonFootprint method calculates the appropriate carbonfootprint for that class, as specified below:
    1. Building footprint = ([monthly gas bill / 10.68] * 119.58 * 12)+ ([monthly electric bill / 0.1188] * 1232 * 12)
    2. Car footprint = miles driven per year / miles per gallon *19.82
    3. Bicycle footprint = miles traveled per month * 0.9
  5. Write an application that does the following:
    1. Creates objects of each of the 3 classes
    2. Places references to those objects in an array ofCarbonFootprint
    3. Iterates through the array, polymorphically invoking eachobject’s getCarbonFootprint method
    4. For each object, print identifying information, such as milestraveled or monthly bill amount, along with the object’s carbonfootprint.

Exercise 2

Extend Exercise 1 by creating and demonstrating the use of anInvalidFootprintException class.

  1. Create the 4 constructors as discussed in this module/week’spresentations.
  2. Extend the appropriate superclass.
  3. Throw the InvalidFootprintException in the constructor of theBuilding, Car, and Bicycle classes if any of the provided parametervalues are negative.
  4. Add code in your main method that handles theInvalidFootprintException, and write code that demonstrates thatyour handler works (i.e., write code that purposefully causes theInvalidFootprintException to be thrown, but then ensure that itdoes not crash your program). Instead of crashing, your main methodmust print a message to the error stream that an invalid footprintwas detected.

Building Car - milesDrivenPerYear : double - milesPerGallon : double - monthlyElectricBill : double - monthlyGasBill : double

Building Car – milesDrivenPerYear : double – milesPerGallon : double – monthlyElectricBill : double – monthlyGasBill : double + Car(milesDrivenPerYear : double, milesPerGallong : double) + getMilesDrivenPerYear() : double + setMilesDrivenPerYear(milesDrivenPerYear : double) : void + getMilesPerGallon() : double + setMilesPerGallon(milesPerGallon : double) : void + Building(monthlyElectricBill : double, monthlyGasBill : double) + getMonthlyElectricBill() : double + setMonthlyElectricBill(monthlyElectricBill : double) : void + getMonthlyGasBill() : double + setMonthlyGasBill(monthlyGasBill : double) : void Bicycle <<interface>> CarbonFootprint – milesTraveledPerMonth : double + getCarbonFootPrint() : double + Bicycle(milesTraveledPerMonth : double) + getMilesTraveledPerMonth() : double + setMilesTraveledPerMonth(milesTraveledPerMonth : double) : void Show transcribed image text Building Car – milesDrivenPerYear : double – milesPerGallon : double – monthlyElectricBill : double – monthlyGasBill : double + Car(milesDrivenPerYear : double, milesPerGallong : double) + getMilesDrivenPerYear() : double + setMilesDrivenPerYear(milesDrivenPerYear : double) : void + getMilesPerGallon() : double + setMilesPerGallon(milesPerGallon : double) : void + Building(monthlyElectricBill : double, monthlyGasBill : double) + getMonthlyElectricBill() : double + setMonthlyElectricBill(monthlyElectricBill : double) : void + getMonthlyGasBill() : double + setMonthlyGasBill(monthlyGasBill : double) : void Bicycle CarbonFootprint – milesTraveledPerMonth : double + getCarbonFootPrint() : double + Bicycle(milesTraveledPerMonth : double) + getMilesTraveledPerMonth() : double + setMilesTraveledPerMonth(milesTraveledPerMonth : double) : void

Expert Answer


Answer to Hi, I need someone to help me with two exercises in JAVA. The exercises must be done in Java. ————————–…

OR