-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstoplights.java
More file actions
36 lines (30 loc) · 1.33 KB
/
stoplights.java
File metadata and controls
36 lines (30 loc) · 1.33 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
import java.util.Scanner;
public class stoplights {
public static void main(String[] args) {
// Instantiating scanner
Scanner scnr = new Scanner(System.in);
// Declaring variables
double milesOfRoad;
int numberOfLanes;
int numberOfStoplights;
double costOfStoplights;
int numberOfIntersections;
int stoplightsPerIntersection;
int lanesPerIntersection;
// Collecting inputs from user
System.out.print("Enter the number of miles of road : ");
milesOfRoad = scnr.nextDouble();
System.out.print("Enter the number of lanes on the road : ");
numberOfLanes = scnr.nextInt();
// Calculating stoplights and intersections
numberOfIntersections = (int) milesOfRoad;
stoplightsPerIntersection = (int) (numberOfIntersections * 2.0);
lanesPerIntersection = (int) (numberOfLanes * numberOfIntersections);
numberOfStoplights = stoplightsPerIntersection + lanesPerIntersection;
costOfStoplights = numberOfStoplights * 25000;
// Printing outputs
System.out.printf("Number of intersections : " + numberOfIntersections + "\n");
System.out.printf("Number of stoplights : " + numberOfStoplights + "\n");
System.out.printf("Cost of stoplights : " + "$%.2f\n", costOfStoplights);
}
}