// compute travel time by highway vs. city streets // This version uses dialogs for the prompts and output import javax.swing.JOptionPane; public class TravelGUI { public static void main(String[] args) { String distance_string = JOptionPane.showInputDialog("Enter distance in miles: "); double distance = Double.parseDouble(distance_string); double highway_time = distance / 40.0 * 60; JOptionPane.showMessageDialog(null, "Time to travel by highway: " + highway_time + " minutes"); distance_string = JOptionPane.showInputDialog("Enter city street distance in miles: "); distance = Double.parseDouble(distance_string); double city_time = distance / 15.0 * 60; JOptionPane.showMessageDialog(null, "Time to travel by city streets: " + city_time + " minutes"); if ( highway_time + 5 < city_time ) { // the savings has to be greater than 5 minutes to take the highway JOptionPane.showMessageDialog(null, "We recommend taking the highway."); } else { JOptionPane.showMessageDialog(null, "We recommend taking the city streets."); } } }