/* * Compute volume of water in bottle given depth * * Author: Dr. Yoder et al. * Date: 22-9-2014 * Assignment: Lab N */ package class3_1; import java.util.Scanner; public class Example { public static void main(String[] args) { final double BASE_HEIGHT = 3; final double BASE_WIDTH = 2; final double NECK_WIDTH = 1; // User input Scanner in = new Scanner(System.in); System.out.println("Enter depth: "); double depth = in.nextDouble(); // Compute volume double volume; if (depth > BASE_HEIGHT) { volume = (depth-BASE_HEIGHT)+BASE_HEIGHT*BASE_WIDTH; } else { volume = (depth*BASE_WIDTH); } // Output to user System.out.println("Volume: "+volume); // ... } }