-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathasphalt.java
More file actions
47 lines (39 loc) · 1.63 KB
/
asphalt.java
File metadata and controls
47 lines (39 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import java.util.Scanner;
public class asphalt {
public static void main(String[] args) {
// Instantiating scanner
Scanner scnr = new Scanner(System.in);
// Declaring variables
double asphaltLengthInMiles;
int numberOfLanes;
int asphaltDepth;
double asphaltLengthInFeet;
double asphaltWidthInFeet;
double asphaltDepthInFeet;
final double asphaltWeightPerCubicFoot = 145;
double asphaltVolume;
double asphaltWeight;
int truckLoads;
double asphaltCost;
final double tonsPerTruckLoad = 5;
// Collecting user inputs
System.out.print("Enter length of road in miles : ");
asphaltLengthInMiles = scnr.nextDouble();
System.out.print("Enter number of lanes : ");
numberOfLanes = scnr.nextInt();
System.out.print("Enter depth of asphalt in inches : ");
asphaltDepth = scnr.nextInt();
// Calculating truckloads
asphaltDepthInFeet = asphaltDepth / 12.0;
asphaltWidthInFeet = numberOfLanes * 12;
asphaltLengthInFeet = (int) (asphaltLengthInMiles * 5280);
asphaltVolume = asphaltLengthInFeet * asphaltDepthInFeet * asphaltWidthInFeet;
asphaltWeight = (asphaltWeightPerCubicFoot * asphaltVolume);
truckLoads = (int) Math.ceil(asphaltWeight / 10000);
// Calculating costs
asphaltCost = Math.ceil(truckLoads * tonsPerTruckLoad) * 150.0;
// Printing outputs
System.out.printf("Truckloads of asphalt needed is : %d\n", truckLoads);
System.out.printf("Total cost of asphalt is : $%.2f\n", asphaltCost);
}
}