The resistance is a strand of wire can be computed using R

The resistance is a strand of wire can be computed using: R = 4pL/pi d^2 where rho is the resistivity of the wire, L is the length and d is the diameter. The diameter of wire can be determined given the American wire gange number: d = 0.127 times 92 where n is the AWG number. As appropriate header for the first method might be: and for the second method: Write a program that prompts the user for the AWG number (integer) and the length of a piece of wire (double) and the wire\'s resistivity. First, compute the diameter of the wire from the AWG number using the appropriate method. Save this value and pass it, along with the collected length and resistivity to the resistance method to compute the desired result. Test your program with the values shown below. Remember, write a main () method to collect the necessary input, to call the other methods and collect their returned values and then to display the output.

Solution

For part 1

question2.java

import java.lang.Math;
import java.util.Scanner;

public class question2{

    //method to calculate resistance by taking in resistivity, length and diameter
    public static double resistance(double resistivity, double diameter, double length){
        return (4*resistivity*length)/(Math.PI*diameter*diameter);
    }

    //method to calculate diameter by taking in gauge number
    public static double diameter(int n){
        return 0.127*Math.pow(92, (36.0-n)/39.0);
    }

    public static void main(String[] args) {

        //Scanner to take in inputs
        Scanner sc = new Scanner(System.in);

        //Getting input for wire gauge
        System.out.print(\"Enter wire gauge: \");
        int n = sc.nextInt();

        //getting input for wire length
        System.out.print(\"\ Enter wire length (in m.): \");
        double l = sc.nextDouble();

        //getting input for resistivity
        System.out.print(\"\ Enter wire resistivity: \");
        double resistivity = sc.nextDouble();

        //closing the scanner
        sc.close();

        //calling diameter method to get diameter
        double d = diameter(n);

        //calling resistance method to get resistance
        double resistance = resistance(resistivity, d, l);

        //Print statements to print diameter and resistance
        System.out.println(\"Diameter of the wire is: \" + d);
        System.out.println(\"Resistance of the wire is: \" + resistance + \" ohms\");

    }
}

For part 2

question2.java

import java.lang.Math;
import java.util.Scanner;

public class question2{

    //method to calculate resistance by taking in resistivity, length and diameter
    public static double resistance(double resistivity, double length, int n){

        //calculating diameter
        double diameter = 0.127*Math.pow(92, (36.0-n)/39.0);

        //printing diameter
        System.out.println(\"Diameter of the wire is: \" + diameter);

        //returning the value of resistance
        return (4*resistivity*length)/(Math.PI*diameter*diameter);
    }

    //method to check if inputs are greater than 0
    public static boolean isValid(double n){
        return n>0;
    }

    public static void main(String[] args) {

        //Scanner to take in inputs
        Scanner sc = new Scanner(System.in);

        //Getting input for wire gauge
        System.out.print(\"Enter wire gauge: \");
        int n = sc.nextInt();

        //checking if n>0
        while(!isValid((double)n)){
            //Getting input for wire gauge
            System.out.print(\"\ That was an invalid input.\ Enter wire gauge: \");
            n = sc.nextInt();
        }


        //getting input for wire length
        System.out.print(\"\ Enter wire length (in m.): \");
        double l = sc.nextDouble();

        //checking if l>0
        while(!isValid(l)){
            //Getting input for wire length
            System.out.print(\"\ That was an invalid input.\ Enter wire length (in m.): \");
            l = sc.nextDouble();
        }

        //getting input for resistivity
        System.out.print(\"\ Enter wire resistivity: \");
        double resistivity = sc.nextDouble();

        while(!isValid(resistivity)){
            //getting input for resistivity
            System.out.print(\"\ That was an invalid input.\ Enter wire resistivity: \");
            resistivity = sc.nextDouble();
        }
        //closing the scanner
        sc.close();

        //calling resistance method to get resistance
        double resistance = resistance(resistivity, l, n);

        //Print statements to print resistance
        System.out.println(\"Resistance of the wire is: \" + resistance + \" ohms\");

    }
}

 The resistance is a strand of wire can be computed using: R = 4pL/pi d^2 where rho is the resistivity of the wire, L is the length and d is the diameter. The d
 The resistance is a strand of wire can be computed using: R = 4pL/pi d^2 where rho is the resistivity of the wire, L is the length and d is the diameter. The d
 The resistance is a strand of wire can be computed using: R = 4pL/pi d^2 where rho is the resistivity of the wire, L is the length and d is the diameter. The d

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site