Electric wire, like that in the photo, is a cylindrical conductor covered by an
ID: 3590925 • Letter: E
Question
Electric wire, like that in the photo, is a cylindrical conductor covered by an insulating material. The resistanc e of a piece of wire is given by the formula where is the resistivity of the conductor, and L, A, and d are the length, cross-sectional area, and diameter of the wire. The resistivity of copper is 1.678 x 10-8 m. The wire diameter, d is commonly specified by the American wire gauge (AWG), which is an integer, n. The diameter of an AWG n wire is given by the formula 36-n d= 0.127×9239 mm Write a Java class to compute and print out the resistance of copper and aluminum wire. Use the following class, and you add instance variables, constructors, and other methods. public class WireResistance [ II Takes the write gauge and returns the corresponding wire diameter double computeDiameter (int wireGauge) II Takes the length and gauge of a piece of copper wire and returns the resistance of that wire. double computeCopperWireResistance (double length, int wireGauge) II Takes the length and gauge of a piece of aluminum wire and returns the resistance of that wire. The resistivity // of aluminum is 2.82 x 10-8 m double computeAlumWireResistance (double length, int wireGauge) t public static void main(String args) Your program should validate user input for the wire gauge and wire length (i.e. prevent computation of zero or negative wire gauge or length) and displays the precision of the output resistance to three decimal points. Here is a sample output with no description message: Enter the wire gauge: 30 Enter the wire length in inches: 65 The resistance of a 65 inch piece of 30 gauge copper wire is 0.544 Ohms. The resistance of a 65 inch piece of 30 gauge aluminum wire is 0.914 Ohms.Explanation / Answer
import java.lang.Math;
import java.io.Console;
public class WireResistance {
private static double length, diameter, resistance;
private static int wireGauge;
private static double copperResistivity = 1.678e-8, alumResistivity = 2.82e-8;
public WireResistance(int wireGauge, double length) {
this.wireGauge = wireGauge;
this.length = length;
}
double computeDiameter(int wireGauge) {
diameter = 0.127 * Math.pow(92.0,((36.0 - wireGauge) / 39.0));
diameter = (diameter / 1000.0); // convert from mm to m as required by the formula
return diameter;
}
double computeCopperWireResistance(int wireGauge, double length) {
length = length * 0.0254; // convert inches to meters as required by the formula
// calculate resistance via: (4 * resistivity * length) / (PI * diameter ^ 2)
resistance = ((4.0 * copperResistivity * length) / (Math.PI * Math.pow(computeDiameter(wireGauge), 2.0)));
return resistance;
}
double computeAlumWireResistance(int wireGauge, double length) {
length = length * 0.0254; // convert inches to meters as required by the formula
// calculate resistance via: (4 * resistivity * length) / (PI * diameter ^ 2)
resistance = ((4.0 * alumResistivity * length) / (Math.PI * Math.pow(computeDiameter(wireGauge), 2.0)));
return resistance;
}
static int inputWireGauge() {
Console console = System.console();
wireGauge = Integer.parseInt(console.readLine("Please enter the wire gauge: "));
while(wireGauge < 1 || wireGauge > 40){
wireGauge = Integer.parseInt(console.readLine("Please enter the wire gauge [Possible values are 1..40]: "));
}
return wireGauge;
}
static double inputWireLength() {
Console console = System.console();
length = Double.parseDouble(console.readLine("Please enter the length of the wire in inches: "));
while(length <= 0){
length = Double.parseDouble(console.readLine("Please enter the length of the wire in inches [Please ensure values are > 0]: "));
}
return length;
}
public static void main(String[] args) {
Console console = System.console();
System.out.println("WIRE RESISTANCE CALCULATION PROGRAM: "
+"This program outputs the resistance of a user-specified gauge and length wire "
+"if it was made of copper, as well as if it was made of aluminum. ");
WireResistance myWire = new WireResistance(inputWireGauge(), inputWireLength());
System.out.printf(" The resistance of a %.1f inch piece of %d gauge copper wire is %.3f ohm. ",
length, wireGauge, myWire.computeCopperWireResistance(wireGauge, length));
System.out.printf("The resistance of a %.1f inch piece of %d gauge aluminum wire is %.3f ohm. ",
length, wireGauge, myWire.computeAlumWireResistance(wireGauge, length));
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.