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

in java Write a program with an interface containing two methods one called Elec

ID: 3830889 • Letter: I

Question


in java

Write a program with an interface containing two methods one called ElectPower, which returns a value and takes in two double values and another method called ElectEnergy, which returns a double value and takes in three double values. Implement the interface in class called EnergyConsumption, which implements the methods and return the product of the two input arguments for the first one and the (product of the three arguments)/1000 for the second one. Implement in a main class, method that calculate the electric power (first method) in watts for the input variables current = 2.0 amps and voltage = 120.0 volts and electric energy for the second in one in KWH using the input variables current = 2.0 amps and voltage = 120.0 volts and hours = 1000.0

Explanation / Answer


/**
*
* @author Sam
*/
public class EnergyConsumption implements EneryInterface {

    @Override
    public double ElectPower(double current, double voltage) {
        return current * voltage; //return product of the variables
    }

    @Override
    public double ElectEnergy(double current, double voltage, double hours) {
        return current * voltage * hours/1000; //return product of three parameters divided by 1000
    }
  
    public static void main(String[] args) {
        EnergyConsumption energyConsumption = new EnergyConsumption(); //object required since the methods are not static
        double current = 2.0;
        double voltage = 120.0;
      
        double power = energyConsumption.ElectPower(current, voltage); //used for calculation
        System.out.println("Power consumtion is " + power + "W"); //print with unit
      
        double hours = 1000;
      
        double energy = energyConsumption.ElectEnergy(current, voltage, hours); //used for calculation
        System.out.println("Enery consumtion: " +energy+"kWh"); //print with unit
    }
}

interface EneryInterface {
    double ElectPower(double current, double voltage); //as defined in the question
    double ElectEnergy(double current, double voltage, double hours);
}

I tried my best to keep the code as simple as possible. I have commented few lines of the code to make things easy for you. If you think you need more information, or facing any problem with the code, please feel free to comment below. I shall be glad to help you with the code.