Write a program with an interface containing two methods one called ElectPower,
ID: 3830896 • Letter: W
Question
Write a program with an interface containing two methods one called ElectPower, which returns a double 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 returns 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.0Explanation / Answer
EnergyInterface.java
//Creating an Interface
public interface EnergyInterface {
//Creating abstract methods
double ElectPower(double a,double b);
double ElectEnergy(double a,double b,double c);
}
_________________
EnergyConsumption.java
public class EnergyConsumption implements EnergyInterface {
@Override
public double ElectPower(double a, double b) {
return a*b;
}
@Override
public double ElectEnergy(double a, double b, double c) {
return (a*b*c)/1000;
}
}
__________________
Main.java
public class Main {
public static void main(String[] args) {
//Create an object to the EnergyConsumption class
EnergyConsumption ec=new EnergyConsumption();
//Calling the method by passing the inputs as arguments
double elecPower=ec.ElectPower(2, 120);
System.out.println("Electric Power :"+elecPower);
//Calling the method by passing the inputs as arguments
double elecEnergy=ec.ElectEnergy(2, 120, 1000);
System.out.println("Electric Energy :"+elecEnergy);
}
}
___________________
Output:
Electric Power :240.0
Electric Energy :240.0
___________________Thank You
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.