Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

USE JAVA TO DO: It is important to consider effect of thermal expansion when bui

ID: 3729930 • Letter: U

Question

USE JAVA TO DO: It is important to consider effect of thermal expansion when building a structure must withstand changes in temperature. For example, metals expand when exposed to hot temperatures and contract in colder temperatures. This is important because engineers must determine what stresses may cause a structure to fail. The change in length, delta-length, of a material (in centimeters) can be described by the following (mathematical) equation: delta-length = 100 × a × length × delta-temperature where length is the original length of the material when the change in temperature (deltatemperature) has a value of zero and a is the coefficient of expansion. The coefficient of expansion, a, for various metals is: Aluminum 2.13 × 10-5 Copper 1.70 × 10-5 Glass 8.50 × 10-6 Steel 1.20 × 10-5 Construct a program wherein the user enters values for length and the change in temperature. For each metal: If delta-length is positive then output the phrase For a change in temperature of xxx degrees C, yyy will expand by mmm centimeters. Replace mmm by delta-length by the calculated change in length to 2 decimal places, yyy by the actual name of the material and xxx by delta-temperature. If delta-length is negative then output the phrase For a change in temperature of xxx degrees C, yyy will contract by mmm centimeters. Replace xxx and yyy as described above, and mmm as described above BUT a positive value. If delta-length is zero then output the phrase For a change in temperature of xxx degrees C, yyy will remain the same. Replace xxx and yyy as described above. The following specifications and guidelines also apply: 1. Make sure that your project meets all of the requirements set forth. 2. 80% of your grade will be based on correctness, and 20% on innovation. 3. Be sure that it has your name in it. All work must be original and your own! No credit will be given for plagiarized work. 4. Even if you are not successful in completing the project, submit what you have as partial credit will be given for programs that would work if minor corrections in logic are made. 5. Any work that is submitted late is subject to the rules set forth in the syllabus!

Explanation / Answer

Answer:

ThermalExpansion.java:

import java.math.BigDecimal;

import java.math.RoundingMode;

import java.util.Scanner;

public class ThermalExpansion {

/**

* @param args

*/

public static void main(String[] args) {

// TODO Auto-generated method stub

double alluminum ;

double copper;

double glass;

double steel;

double length;

double temparature;

double deltalengthResult;

// Assigning the standard 'a' values for Materials.

alluminum = 2.13 * java.lang.Math.pow(10,-5);

copper = 1.70 * java.lang.Math.pow(10,-5);

glass = 8.50 * java.lang.Math.pow(10,-6);

steel = 1.20 * java.lang.Math.pow(10,-5);

Scanner sc = new Scanner(System.in);

//Object for calling methods of the class

ThermalExpansion thermalExpansion = new ThermalExpansion();

// Reading input from the user

System.out.println("Enter the length of Material: ");

length = sc.nextDouble();

System.out.println("Enter the change in Temparature: ");

temparature = sc.nextDouble();

// Calculating Delta length for Aluminum and displaying Phrase

deltalengthResult = (double) thermalExpansion.calculateDelta_length(alluminum, length, temparature );

thermalExpansion.display(deltalengthResult, temparature, "Alluminium");

// Calculating Delta length for Copper and displaying Phrase

deltalengthResult = (double) thermalExpansion.calculateDelta_length(copper, length, temparature );

thermalExpansion.display(deltalengthResult, temparature, "Copper");

// Calculating Delta length for Glass and displaying Phrase

deltalengthResult = (double) thermalExpansion.calculateDelta_length(glass, length, temparature );

thermalExpansion.display(deltalengthResult, temparature, "Glass");

// Calculating Delta length for Steel and displaying Phrase

deltalengthResult = (double) thermalExpansion.calculateDelta_length(steel, length, temparature );

thermalExpansion.display(deltalengthResult, temparature, "Steel");

}

//Function to calculate Delta length for each material

double calculateDelta_length(double a, double len, double Dtemp){

double deltaLegth = 0;

// rounding off the decimals precision to 2 digits

deltaLegth = BigDecimal.valueOf(100 * a * len * Dtemp).setScale(2, RoundingMode.HALF_UP).doubleValue();

return deltaLegth;

}

//Function to display the result phrase based on Delta length

void display(double res, double temp, String meterial){

if(res > 0){

System.out.println("For change in temparature of "+temp+" degrees C, "+ meterial +" will expand by "+res+" centimeters.");

}else{

System.out.println("For change in temparature of "+temp+" degrees C, " +meterial +"will contract by "+res+" centimeters.");

}

}

}

Output 1:

Enter the length of Material:
10
Enter the change in Temparature:
2
For change in temparature of 2.0 degrees C, Alluminium will expand by 0.04 centimeters.
For change in temparature of 2.0 degrees C, Copper will expand by 0.03 centimeters.
For change in temparature of 2.0 degrees C, Glass will expand by 0.02 centimeters.
For change in temparature of 2.0 degrees C, Steel will expand by 0.02 centimeters.

Ooutput 2:

Enter the length of Material:
120
Enter the change in Temparature:
-2
For change in temparature of -2.0 degrees C, Alluminiumwill contract by -0.51 centimeters.
For change in temparature of -2.0 degrees C, Copperwill contract by -0.41 centimeters.
For change in temparature of -2.0 degrees C, Glasswill contract by -0.2 centimeters.
For change in temparature of -2.0 degrees C, Steelwill contract by -0.29 centimeters.