1 import java.util.Scanner;
2
3 /**
4 This program prints the price per ounce for a six-pack of cans.
5 */
6 public class Volume2
7 {
8 public static void main(String[] args)
9 {
10 // Read price per pack
11
12 Scanner in = new Scanner(System.in);
13
14 System.out.print("Please enter the price for a six-pack: ");
15 double packPrice = in.nextDouble();
16
17 // Read can volume
18
19 System.out.print("Please enter the volume for each can (in ounces): ");
20 double canVolume = in.nextDouble();
21
22 // Compute pack volume
23
24 final double CANS_PER_PACK = 6;
25 double packVolume = canVolume * CANS_PER_PACK;
26
27 // Compute and print price per ounce
28
29 double pricePerOunce = packPrice / packVolume;
30
31 System.out.printf("Price per ounce: %8.2f", pricePerOunce);
32 System.out.println();
33 }
34 }