-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVolume.java
More file actions
38 lines (28 loc) · 1.05 KB
/
Copy pathVolume.java
File metadata and controls
38 lines (28 loc) · 1.05 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
import java.util.Scanner;
/**
This program prints the price per liter for a six-pack of cans and
a two-liter bottle.
*/
public class Volume
{
public static void main(String[] args)
{
// Read price per pack
Scanner in = new Scanner(System.in);
System.out.print("Please enter the price for a six-pack: ");
double packPrice = in.nextDouble();
// Read price per bottle
System.out.print("Please enter the price for a two-liter bottle: ");
double bottlePrice = in.nextDouble();
final double CANS_PER_PACK = 6;
final double CAN_VOLUME = 0.355; // 12 oz. = 0.355 l
final double BOTTLE_VOLUME = 2;
// Compute and print price per liter
double packPricePerLiter = packPrice / (CANS_PER_PACK * CAN_VOLUME);
double bottlePricePerLiter = bottlePrice / BOTTLE_VOLUME;
System.out.printf("Pack price per liter: %8.2f", packPricePerLiter);
System.out.println();
System.out.printf("Bottle price per liter: %8.2f", bottlePricePerLiter);
System.out.println();
}
}