import javax.swing.JOptionPane; public class BaseBallStatsDemo { public static void main( String[] args) { int confirmResponse; do { while (true) { String numHitsStr = JOptionPane.showInputDialog("Enter the number of hits:"); if( numHitsStr == null || numHitsStr.isEmpty() ) { break; } int numHits = Integer.parseInt( numHitsStr ); String numAtBatsStr = JOptionPane.showInputDialog("Enter the number of at bats:"); if( numAtBatsStr == null || numAtBatsStr.isEmpty() ) { break; } int numAtBats = Integer.parseInt( numAtBatsStr ); BaseBallStats stats = new BaseBallStats(); double avg = stats.batAvg(numHits, numAtBats); JOptionPane.showMessageDialog( null, "Batting Average is " + avg); } confirmResponse = JOptionPane.showConfirmDialog( null, "Are you sure you want to exit?"); } while (confirmResponse != JOptionPane.YES_OPTION); } }