/* Revises Example 4.2 to separate the services of the addValidScore * method into getNextScore, isValid, and updateTotal methods. * It is a design alternative. */ import javax.swing.*; public class Zero100 { private int total = 0; private int score = 0; public void getNextScore() { String input = JOptionPane.showInputDialog ("Enter the score, -1 to quit"); score = Integer.parseInt(input); } private boolean isValid() { if (score >= 0 && score <= 100) return true; else return false; } public void updateTotal() { if (isValid()) total += score; } public int getTotal() { return total; } public static void main(String [] args) { Zero100 test = new Zero100(); test.getNextScore(); while (test.isValid()) { test.updateTotal(); test.getNextScore(); } JOptionPane.showMessageDialog(null,"The total is " + test.getTotal()); System.exit(0); } }