

package circuit;

import java.util.Scanner;

public class Circuit {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        double vSource,r1,r2,r3,r4,reg1,reg2,iTotal,v1,power;
        // Get the user's values
        System.out.print("Enter voltage (in Volts):");
        vSource = in.nextDouble();          //read the value of voltage store it in vSource
        System.out.print("Enter Resistor1 value:");
        r1 = in.nextDouble();               //read the value of Resistor1 store it in r1
        System.out.print("Enter Resistor2 value:");
        r2 = in.nextDouble();                //read the value of Resistor2 store it in r2
        System.out.print("Enter Resistor3 value:");
        r3 = in.nextDouble();               //read the value of Resistor3 store it in r3
        System.out.print("Enter Resistor4 value:");
        r4 = in.nextDouble();               //read the value of Resistor4 store it in r4
        in.close();
        reg1 = getReq1(r1,r2);                      // call getReq1 method and store the value in reg1
        System.out.println("\nEquivalence resistance Req1 = "+reg1+" Ohms");
        reg2 = getReq1(r3,r4);                      // call getReq1 method and store the value in reg2
        System.out.println("\nEquivalence resistance Req2 = "+reg2+" Ohms");
        System.out.println("\nTotal Equivalence resistance = "+(reg1+reg2)+" Ohms");
        iTotal = getItotal(vSource, reg1,reg2);     // call getItotal method and store the value in iTotal
        System.out.println("I Total is: "+iTotal+" Amps");
        v1 = getVoltage(vSource,reg1,reg2);         // call getVoltage method and store the value in v1
        System.out.println("\nV1 is: "+v1+" Volts");
        power = getPower(iTotal,reg1,reg2);         // call getPower method and store the value in power
        System.out.println("\nPower dissipated in the circuit is: "+power+" watts\n");
    }

    //method to return the value of equivalent resistance
    private static double getReq1(double r1,double r2)
    {
        return 1/((1/r1)+(1/r2));
    }
    // method to calculate the value of total electrical current Itotal
    private static double getItotal(double vSource,double reg1,double reg2)
    {
        return vSource/(reg1+reg2);
    }
    //method to calculate the voltage V1
    private static double getVoltage(double vSource,double reg1,double reg2)
    {
        return vSource*(reg2/(reg1+reg2));
    }
    //method to calculate the the power P
    private static double getPower(double iTotal,double reg1,double reg2)
    {
        return (Math.pow(iTotal, 2))*(reg1+reg2);
    }

}

