public class CIRCUIT {
private double totalResistance;
static int totalVoltage;
double totalCurrent;
public static void setVoltageSource() {
totalVoltage = 24;
}
public String getTotalCurrent() {
totalCurrent = totalVoltage / totalResistance;
return String.format("%.2f", totalCurrent);
}
/**
* @return the totalResistance
*/
public String getTotalResistance() {
return String.format("%.2f", totalResistance);
}
/**
* @param totalResistance the totalResistance to set
*/
public void setTotalResistance(double totalResistance) {
this.totalResistance = totalResistance;
}
}
***************************************************Series.java***********************************************************
public class Series extends CIRCUIT implements DisplayCircuitType {
private int numres;
public void computeTotalResistance(double r1, double r2) {
numres = 2;
setTotalResistance(r1 + r2);
}
public void computeTotalResistance(double r1, double r2, double r3) {
numres = 3;
setTotalResistance(r1 + r2 + r3);
}
public void disType() {
System.out.println("SERIES CONNECTION with " + numres + " Resistors");
}
}
***************************************************Parallel.java***********************************************************
public class Parallel extends CIRCUIT implements DisplayCircuitType {
private int numres;
public void computeTotalResistance(double r1, double r2) {
numres = 2;
setTotalResistance(1 / ((1 / r1) + (1 / r2)));
}
public void computeTotalResistance(double r1, double r2, double r3) {
numres = 3;
setTotalResistance(1 / ((1 / r1) + (1 / r2) + (1 / r3)));
}
public void disType() {
System.out.println("PARALLEL CONNECTION with " + numres + " Resistors");
}
}
***************************************************DisplayCircuitType.java************************************************
public interface DisplayCircuitType {
void disType();
}
***************************************************Driver.java***********************************************************
import java.util.Scanner;
public class Driver {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Please Enter 3 resistance values: ");
double r1, r2, r3;
r1 = sc.nextDouble();
r2 = sc.nextDouble();
r3 = sc.nextDouble();
Series s1 = new Series();
Series s2 = new Series();
Parallel p1 = new Parallel();
Parallel p2 = new Parallel();
CIRCUIT.setVoltageSource();
s1.computeTotalResistance(r1, r2);
s1.disType();
System.out.println("Total Resistance in 24 (V) : " + s1.getTotalResistance());
System.out.println("Total Current in 24 (V) : " + s1.getTotalCurrent());
System.out.println(" -----------------------------------------------");
s2.computeTotalResistance(r1, r2, r3);
s2.disType();
System.out.println("Total Resistance in 24 (V) : " + s2.getTotalResistance());
System.out.println("Total Current in 24 (V) : " + s2.getTotalCurrent());
System.out.println(" -----------------------------------------------");
p1.computeTotalResistance(r1, r2);
p1.disType();
System.out.println("Total Resistance in 24 (V) : " + p1.getTotalResistance());
System.out.println("Total Current in 24 (V) : " + p1.getTotalCurrent());
System.out.println(" -----------------------------------------------");
p2.computeTotalResistance(r1, r2, r3);
p2.disType();
System.out.println("Total Resistance in 24 (V) : " + p2.getTotalResistance());
System.out.println("Total Current in 24 (V) : " + p2.getTotalCurrent());
sc.close();
}
}
WHAT IS THE ERROR IN THE PROGRAM? KINDLY FIX IT. I NEED IT ALREADY. TYSM
CIRCUIT.java
-----------------------------------------------------------------------
public class CIRCUIT {
private double totalResistance;
static int totalVoltage;
double totalCurrent;
public static void setVoltageSource() {
totalVoltage = 24;
}
public String getTotalCurrent() {
totalCurrent = totalVoltage / totalResistance;
return String.format("%.2f", totalCurrent);
}
/**
* @return the totalResistance
*/
public String getTotalResistance() {
return String.format("%.2f", totalResistance);
}
/**
* @param totalResistance the totalResistance to set
*/
public void setTotalResistance(double totalResistance) {
this.totalResistance = totalResistance;
}
}
----------------------------------------------------------------------------------==============
================================================================================================
DisplayCircuitType.java
------------------------------------------------------------------------------------------------
public interface DisplayCircuitType {
void disType();
}
===============================================================================================
Scanner.java
-----------------------------------------------------------------------------------------------
import java.util.Scanner;
public class Driver {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Please Enter 3 resistance values: ");
double r1, r2, r3;
r1 = sc.nextDouble();
r2 = sc.nextDouble();
r3 = sc.nextDouble();
Series s1 = new Series();
Series s2 = new Series();
Parallel p1 = new Parallel();
Parallel p2 = new Parallel();
CIRCUIT.setVoltageSource();
s1.computeTotalResistance(r1, r2);
s1.disType();
System.out.println("Total Resistance in 24 (V) : " + s1.getTotalResistance());
System.out.println("Total Current in 24 (V) : " + s1.getTotalCurrent());
System.out.println(" -----------------------------------------------");
s2.computeTotalResistance(r1, r2, r3);
s2.disType();
System.out.println("Total Resistance in 24 (V) : " + s2.getTotalResistance());
System.out.println("Total Current in 24 (V) : " + s2.getTotalCurrent());
System.out.println(" -----------------------------------------------");
p1.computeTotalResistance(r1, r2);
p1.disType();
System.out.println("Total Resistance in 24 (V) : " + p1.getTotalResistance());
System.out.println("Total Current in 24 (V) : " + p1.getTotalCurrent());
System.out.println(" -----------------------------------------------");
p2.computeTotalResistance(r1, r2, r3);
p2.disType();
System.out.println("Total Resistance in 24 (V) : " + p2.getTotalResistance());
System.out.println("Total Current in 24 (V) : " + p2.getTotalCurrent());
sc.close();
}
}
===============================================================================================
Parallel.java
----------------------------------------------------------------------------------------------
public class Parallel extends CIRCUIT implements DisplayCircuitType {
private int numres;
public void computeTotalResistance(double r1, double r2) {
numres = 2;
setTotalResistance(1 / ((1 / r1) + (1 / r2)));
}
public void computeTotalResistance(double r1, double r2, double r3) {
numres = 3;
setTotalResistance(1 / ((1 / r1) + (1 / r2) + (1 / r3)));
}
public void disType() {
System.out.println("PARALLEL CONNECTION with " + numres + " Resistors");
}
}
==============================================================================================
Series.java
---------------------------------------------------------------------------------------------
public class Series extends CIRCUIT implements DisplayCircuitType {
private int numres;
public void computeTotalResistance(double r1, double r2) {
numres = 2;
setTotalResistance(r1 + r2);
}
public void computeTotalResistance(double r1, double r2, double r3) {
numres = 3;
setTotalResistance(r1 + r2 + r3);
}
public void disType() {
System.out.println("SERIES CONNECTION with " + numres + " Resistors");
}
}
Result:
Comments
Leave a comment