Chapter Four listings: 11 classes public class GameApp { /** Play the basic game repeatedly until the user tires. */ public static void main (String[ ] args) { BasicGame game = new BasicGame(); game.playManyGames(); System.exit (0); } //====================== } import javax.swing.JOptionPane; public class NameChange { /** Ask the user for his/her first name, then for the last * name, then print them out in the opposite order. */ public static void main (String[ ] args) { JOptionPane.showMessageDialog (null, "Illustrate the use of JOptionPane methods"); String firstName = JOptionPane.showInputDialog ("What is your first name?"); String lastName = JOptionPane.showInputDialog ("What is your last name?"); JOptionPane.showMessageDialog (null, "Reversed it is " + lastName + ", " + firstName); System.exit (0); // needed when using JOptionPane } //====================== } import javax.swing.JOptionPane; public class BasicGame extends Object { private String itsSecretWord = "duck"; private String itsUsersWord = "none"; public void playManyGames() { do { playOneGame(); }while (JOptionPane.showConfirmDialog (null, "again?") == JOptionPane.YES_OPTION); } //====================== public void playOneGame() { askUsersFirstChoice(); while (shouldContinue()) { showUpdatedStatus(); askUsersNextChoice(); } showFinalStatus(); } //====================== public void askUsersFirstChoice() { itsUsersWord = JOptionPane.showInputDialog ("Guess the secret word:"); } //====================== public void askUsersNextChoice() { askUsersFirstChoice(); // no need to write the coding again } //====================== public boolean shouldContinue() { return ! itsSecretWord.equals (itsUsersWord); } //====================== public void showUpdatedStatus() { JOptionPane.showMessageDialog (null, "That was wrong. Hint: It quacks."); } //====================== public void showFinalStatus() { JOptionPane.showMessageDialog (null, "That was right. \nCongratulations."); } //====================== } public class Person extends Object { private String itsFirstName; private String itsLastName; public Person (String first, String last) // constructor { super(); itsFirstName = first; itsLastName = last; } //======================= public String getFirstName() { return itsFirstName; } //======================= public String getLastName() { return itsLastName; } //======================= } public class Patient extends Person { private String itsDoctor; public Patient (String first, String last, String doc) { super (first, last); itsDoctor = doc; } //======================= } public class Time extends Object { private int itsHour; // always in the range 0 to 23 private int itsMin; // always in the range 0 to 59 /** Create an object for the given hour and minute. If min * is negative, adjust the values to make 0 <= min < 60. */ public Time (int hour, int min) // constructor { super(); itsHour = hour; for (itsMin = min; itsMin < 0; itsMin = itsMin + 60) itsHour--; } //======================= /** Return the time expressed in military time. */ public String toString() { if (itsHour < 10) return ("0" + itsHour) + itsMin; else return ("" + itsHour) + itsMin; } //======================= public Time add (Time that) { Time valueToReturn = new Time (this.itsHour + that.itsHour, this.itsMin + that.itsMin); if (valueToReturn.itsMin >= 60) { valueToReturn.itsMin = valueToReturn.itsMin - 60; valueToReturn.itsHour++; } valueToReturn.itsHour = valueToReturn.itsHour % 24; return valueToReturn; } //======================= } import javax.swing.JOptionPane; public class TimeTester { public static void main (String[] args) { Time t1 = new Time (13, 25); Time t2 = new Time (8, -150); JOptionPane.showMessageDialog (null, "1 " + t1.toString()); JOptionPane.showMessageDialog (null, "2 " + t2.toString()); Time t3 = t1.add (t2); JOptionPane.showMessageDialog (null, "3 " + t3.toString()); t1 = t2.add (t3); JOptionPane.showMessageDialog (null, "1 " + t1.toString()); System.exit (0); // needed when using JOptionPane } //======================= } import javax.swing.JOptionPane; public class GuessNumber extends BasicGame { private java.util.Random randy; private int itsSecretNumber; private int itsUsersNumber; public GuessNumber() { super(); randy = new java.util.Random(); } //======================= public void askUsersFirstChoice() { itsSecretNumber = 1 + randy.nextInt (100); askUsersNextChoice(); } //======================= public void askUsersNextChoice() { String s = JOptionPane.showInputDialog ("Guess my number from 1 to 100:"); if (s != null && ! s.equals ("")) itsUsersNumber = Integer.parseInt (s); else itsUsersNumber = -1; // just to have a value there } //====================== public boolean shouldContinue() { return itsUsersNumber != itsSecretNumber; } //====================== public void showUpdatedStatus() { if (itsUsersNumber > itsSecretNumber) JOptionPane.showMessageDialog (null, "Too high"); else JOptionPane.showMessageDialog (null, "Too low"); } //======================= // inherited from BasicGame: // playManyGames // playOneGame // showFinalStatus } public class BigVic extends Looper { private int itsNumFilled; // count this's filled slots private int itsNumEmpty; // count this's non-filled slots public BigVic() // constructor { // left as an exercise } //====================== /** Tell how many of the executor's slots are filled. */ public int getNumFilled() { return itsNumFilled; } //====================== /** Tell how many of the executor's slots are empty. */ public int getNumEmpty() { return itsNumEmpty; } //====================== /** Do the original putCD(), but also update the counters. */ public void putCD() { if ( ! seesCD() && stackHasCD()) { itsNumFilled++; itsNumEmpty--; super.putCD(); } } //====================== /** Do the original takeCD(), but also update the counters.*/ public void takeCD() { if (seesCD()) { itsNumFilled--; itsNumEmpty++; super.takeCD(); } } //====================== } import javax.swing.JOptionPane; public class Nim extends BasicGame { private java.util.Random randy = new java.util.Random(); private int itsNumLeft; private int itsMaxToTake; public void askUsersFirstChoice() { itsNumLeft = 20 + randy.nextInt (21); itsMaxToTake = 3 + randy.nextInt (3); askUsersNextChoice(); } //======================= public void askUsersNextChoice() { int choice = 0; do { String s = JOptionPane.showInputDialog (itsNumLeft + " left. Take 1 to " + itsMaxToTake); if (s != null && ! s.equals ("")) choice = Integer.parseInt (s); }while (choice < 1 || choice > itsMaxToTake); itsNumLeft = itsNumLeft - choice; } //======================= public boolean shouldContinue() { return itsNumLeft > itsMaxToTake; } //====================== public void showFinalStatus() { if (itsNumLeft == 0) super.showFinalStatus(); else JOptionPane.showMessageDialog (null, "I take " + itsNumLeft + " and so I win."); } //======================= public void showUpdatedStatus() { int move = itsNumLeft % (itsMaxToTake + 1); if (move == 0) move = 1 + randy.nextInt (itsMaxToTake); itsNumLeft = itsNumLeft - move; JOptionPane.showMessageDialog (null, "I take " + move + ", leaving " + itsNumLeft); } //======================= } import javax.swing.JOptionPane; import java.util.Random; public class Mastermind extends BasicGame { private Random randy; private int itsFirst; // 100's digit of secret number private int itsSec; // 10's digit of secret number private int itsThird; // 1's digit of secret number private int usersFirst; // 100's digit of user's guess private int usersSec; // 10's digit of user's guess private int usersThird; // 1's digit of user's guess public Mastermind() { super(); randy = new Random(); } //======================= public void askUsersFirstChoice() { itsFirst = randy.nextInt (10); itsSec = randy.nextInt (10); itsThird = randy.nextInt (10); askUsersNextChoice(); } //======================= public void askUsersNextChoice() { String s; do { s = JOptionPane.showInputDialog ("Enter a three-digit integer:"); }while (s == null || s.equals ("")); int guess = Integer.parseInt (s); usersThird = guess % 10; usersFirst = guess / 100; usersSec = (guess / 10) % 10; } //======================= public boolean shouldContinue() { return usersFirst != itsFirst || usersSec != itsSec || usersThird != itsThird; } //======================= public void showUpdatedStatus() // in Mastermind { int numRight = 0; int numWrong = 0; if (usersFirst == itsFirst) numRight++; else if (usersFirst == itsSec || usersFirst == itsThird) numWrong++; if (usersSec == itsSec) numRight++; else if (usersSec == itsFirst || usersSec == itsThird) numWrong++; if (usersThird == itsThird) numRight++; else if (usersThird == itsSec || usersThird == itsFirst) numWrong++; JOptionPane.showMessageDialog (null, " You have " + numRight + " in the right place and " + numWrong + " in the wrong place."); } //====================== } All information Copyright (c)1999 - 2001 Dr. William C. Jones, Jr. Layout and Design Copyright © Psumonix, LLC. All Rights Reserved. Chapter Five listings: 9 classes /** Class methods that do useful things with numbers. */ public class MathOp { /** Return the value of 2 to the power expo. */ public static int powerOf2 (int expo) { int power = 1; for (; expo > 0; expo--) power = power * 2; return power; } //====================== /** Return sum divided by count, rounded to the nearest int.*/ public static int average (int sum, int count) { if (sum >= 0) return (sum + count / 2) / count; else return (sum - count / 2) / count; } //====================== /** From Listing 6.1. */ /** Precondition: interestRate is positive. */ public static int yearsToDouble (double interestRate) { double balance = 1.0; int count = 0; while (balance < 2.0) { balance = balance * (1.0 + interestRate / 100.0); count++; } return count; } //====================== } public class Person extends Object { private static int theNumPersons = 0; // initialize num ///////////////////////////////// private String itsFirstName; private String itsLastName; private int itsBirthYear; /** Construct a new Person with given names and birth year. */ public Person (String first, String last, int year) { super(); theNumPersons++; // update num itsFirstName = first; itsLastName = last; // initialize last name itsBirthYear = year; } //======================= /** Tell how many different Persons exist. */ public static int getNumPersons() // access num { return theNumPersons; } //====================== /** Return the birth year. */ public int getBirthYear() { return itsBirthYear; } //======================= /** Return the first name. */ public String getFirstName() { return itsFirstName; } //======================= /** Return the last name. */ public String getLastName() // access last name { return itsLastName; } //======================= /** Replace the last name by the specified value. */ public void setLastName (String name) // update last name { itsLastName = name; } //======================= } public class Vic extends Object { private static final String NONE = "0"; ///////////////////////////////// private String itsSequence = ""; private int itsPos = 1; private final int itsID; // so tracing output can identify it public String getPosition() { return itsPos + "," + itsID; } //====================== public static void say (String message) { System.out.println ("SAYS: " + message); } //====================== private void trace (String action) { System.out.println ("Vic# " + itsID + ": " + action + itsPos + "; sequence= " + itsSequence); } //====================== public void backUp() { if (itsPos == 1) System.exit (0); itsPos--; trace ("backUp to slot "); } //====================== public void moveOn() { if ( ! seesSlot()) System.exit (0); itsPos++; trace ("moveOn to slot "); } //====================== public boolean seesSlot() { return itsPos < itsSequence.length(); } //====================== public boolean seesCD() { if ( ! seesSlot()) System.exit (0); String s = itsSequence.substring (itsPos, itsPos + 1); return ! s.equals (NONE); } //====================== // public class Vic continued: using the stack private static String theStack = ""; // initially empty public static boolean stackHasCD() { return theStack.length() > 0; } //====================== public void takeCD() { if (seesCD()) { theStack = theStack + itsSequence.substring (itsPos, itsPos + 1); itsSequence = itsSequence.substring (0, itsPos) + NONE + itsSequence.substring (itsPos + 1, itsSequence.length()); } trace ("takeCD at slot "); } //====================== public void putCD() { if ( ! seesCD() && stackHasCD()) { int atEnd = theStack.length() - 1; itsSequence = itsSequence.substring (0, itsPos) + theStack.substring (atEnd, atEnd + 1) + itsSequence.substring (itsPos + 1, itsSequence.length()); theStack = theStack.substring (0, atEnd); } trace ("putCD at slot "); } //====================== // public class Vic completed: constructor and reset private static final java.util.Random randy = new java.util.Random(); private static final String LETTERS = " abcdefghijkl"; private static int theNumVics = 0; private static String[ ] theTableau = {"", "", ""}; public static void reset (String[ ] args) { if (theNumVics == 0 && args.length > 0) theTableau = args; } //====================== public Vic() { super(); // 1 if (theNumVics < theTableau.length) // 2 { itsSequence = theTableau[theNumVics]; // 3 if (itsSequence.length() == 0) // 4 for (int k = 3 + randy.nextInt (6); k >= 1; k--) // 5 if (randy.nextInt (2) == 0) // 6 itsSequence = NONE + itsSequence; // 7 else // 8 itsSequence = LETTERS.substring (k, k + 1)// 9 + itsSequence; // 10 itsSequence = " " + itsSequence; // 11 } // 12 theNumVics++; // 13 itsID = theNumVics; // 14 trace ("constructed "); // 15 } //====================== } import javax.swing.JOptionPane; public class NetApp { /** List all nodes and tell how many there are. */ public static void main (String[ ] args) { Network school = new Network(); int count = 0; for (Position pos = school.nodes(); pos.hasNext(); pos.moveOn()) { Node current = pos.getNext(); JOptionPane.showMessageDialog (null, current.getName() + " is one of the nodes."); count++; } JOptionPane.showMessageDialog (null, "The total number of nodes is " + count); System.exit (0); } //====================== } /** Answer queries about one or two given nodes. */ public class NodeOp { /** Tell whether par connects only to blue nodes. */ public static boolean seesOnlyBlue (Node par) { for (Position p = par.nodes(); p.hasNext(); p.moveOn()) if ( ! p.getNext().isBlue()) return false; return true; } //======================= /** Tell whether from connects to target. */ public static boolean connected (Node from, Node target) { for (Position p = from.nodes(); p.hasNext(); p.moveOn()) if (p.getNext().equals (target)) return true; return false; } //======================= /** Tell whether par connects to any node of the same color.*/ public static boolean seesSameColor (Node par) { return par.isBlue() && ! seesOnlyNonBlue (par) || ! par.isBlue() && ! seesOnlyBlue (par); } //======================= /** Tell whether par connects to no blue node. */ public static boolean seesOnlyNonBlue (Node par) { for (Position p = par.nodes(); p.hasNext(); p.moveOn()) if (p.getNext().isBlue()) return false; return true; } //======================= } import javax.swing.JOptionPane; public class SmartNet extends Network { /** Tell whether par connects to all other nodes in this * network.*/ public boolean connectsToAll (Node par) { for (Position pos = nodes(); pos.hasNext(); pos.moveOn()) { Node current = pos.getNext(); if ( ! (current.equals (par) || NodeOp.connected (current, par))) return false; } return true; } //====================== /** Return the total number of nodes in this network. */ public int getNumNodes() { int count = 0; for (Position pos = nodes(); pos.hasNext(); pos.moveOn()) count++; return count; } //====================== /** List all nodes in this network that connect to * some node of the same color. */ public void printSameColorConnections() { for (Position pos = nodes(); pos.hasNext(); pos.moveOn()) { Node current = pos.getNext(); if (NodeOp.seesSameColor (current)) JOptionPane.showMessageDialog (null, current.getName()); } } //====================== /** Tell whether every node is reachable from * the given node. */ public boolean allReachableFrom (Node source) { checkOut (source); // sets a mark of 2 on source boolean foundNodeToCheckOut; do { foundNodeToCheckOut = false; for (Position pos= nodes(); pos.hasNext(); pos.moveOn()) { Node current = pos.getNext(); if (current.getMark() == 1) { foundNodeToCheckOut = true; checkOut (current); } } }while (foundNodeToCheckOut); return allNodesAreMarked(); } //====================== /** Mark 2 on par; mark 1 on all nodes reachable from par * except for those already marked 1 or 2. */ private static void checkOut (Node par) { par.setMark (2); for (Position p = par.nodes(); p.hasNext(); p.moveOn()) { Node current = p.getNext(); if (current.getMark() == 0) current.setMark (1); } } //====================== private boolean allNodesAreMarked() { boolean valueToReturn = true; for (Position pos = nodes(); pos.hasNext(); pos.moveOn()) if (pos.getNext().getMark() == 0) valueToReturn = false; else pos.getNext().setMark (0); return valueToReturn; } //====================== /** Tell whether it is possible to travel through n nodes, * all different and all marked 0, starting from Node base. * Precondition: base is marked 0. */ public static boolean canTravelFrom (Node base, int n) { if (n <= 1) return true; base.setMark (1); for (Position p = base.nodes(); p.hasNext(); p.moveOn()) { Node current = p.getNext(); if (current.getMark() == 0 && canTravelFrom (current, n - 1)) { base.setMark (0); // restore original state return true; } } base.setMark (0); // restore original state return false; } //====================== } public class Position extends Object { private int itsCurrent; // Node at current position on list private int itsLast; // Node at last position on list public Position (int first, int last) { super(); itsCurrent = first; itsLast = last; } //====================== public Node getNext() { if (itsCurrent > itsLast) return null; else return new Node (itsCurrent % Network.NUM_NODES); } //====================== public boolean hasNext() { return itsCurrent <= itsLast; } //====================== public void moveOn() { itsCurrent++; } //====================== } public class Network extends Object { public static final int NUM_NODES = 100; /////////////////////////////////////// public Position nodes() { return new Position (0, NUM_NODES - 1); } //====================== } public class Node extends Object { private int itsID; // ranges from 0 to NUM_NODES - 1 public Node (int index) { super(); itsID = index; } //====================== public Position nodes() { return new Position (itsID + 1, itsID + 4); } //====================== public boolean equals (Node par) { return this.itsID == par.itsID; } //====================== public boolean isBlue() { return itsID % 2 == 1; } //====================== public String getName() { return "Darryl"; } //====================== private int itsMark = 0; public void setMark (int par) { itsMark = par; } //====================== public int getMark() { return itsMark; } //====================== } All information Copyright (c)1999 - 2001 Dr. William C. Jones, Jr. Layout and Design Copyright © Psumonix, LLC. All Rights Reserved. Chapter Six listings: 8 classes import javax.swing.JOptionPane; public class GrowthRates { /** Calculate time to double your money at a given rate. */ public static void main (String[ ] args) { JOptionPane.showMessageDialog (null, "Calculating growth for various interest rates"); String input = JOptionPane.showInputDialog ("Annual rate? 0 if done:"); double rate = Double.parseDouble (input); while (rate > 0.0) { JOptionPane.showMessageDialog (null, "It takes " + MathOp.yearsToDouble (rate) + " years for \nyour money to double."); input = JOptionPane.showInputDialog ("Another rate (0 when done):"); rate = Double.parseDouble (input); } System.exit (0); } //====================== } // The yearsToDouble method is in MathOp in the Chapter 5 file import javax.swing.JOptionPane; public class IO { /** Display a message to the user of Jo's Repair Shop. */ public static void say (Object message) { JOptionPane.showMessageDialog (null, message, "Jo's Repair Shop", JOptionPane.PLAIN_MESSAGE); } //====================== /** Display the prompt to the user; wait for the user to enter * a string of characters; return that String (not null). */ public static String askLine (String prompt) { String s = JOptionPane.showInputDialog (prompt); if (s == null) return ""; else return s; } //====================== /** Display the prompt to the user; wait for the user to enter * a number; return it, or return -1 if ill-formed. */ public static double askDouble (String prompt) { String s = JOptionPane.showInputDialog (prompt); return new StringInfo (s).parseDouble (-1); } //====================== /** Display the prompt to the user; wait for the user to enter * a whole number; return it, or return -1 if ill-formed. */ public static int askInt (String prompt) { String s = JOptionPane.showInputDialog (prompt); return (int) new StringInfo (s).parseDouble (-1); } //====================== } public class TestOrdered { /** Tell what kind of order the 3 values are in. */ public static String ordered (Comparable first, Comparable second, Comparable third) { if (first.compareTo (second) == 0) return second.compareTo (third) >= 0 ? "in ascending order" : "in descending order"; else if (first.compareTo (second) < 0) return second.compareTo (third) > 0 ? "not in order" : "in ascending order"; else // first comes after second return second.compareTo (third) < 0 ? "not in order" : "in descending order"; } //======================= } public class StringInfo extends Object implements Comparable { private String itself; public StringInfo (String given) { super(); itself = (given == null) ? "" : given; } //======================= public String toString() { return itself; } //======================= public int compareTo (Object ob) { return itself.compareTo (((StringInfo) ob).itself); } //======================= /** Remove all characters before index n, plus any * whitespace immediately following those characters. */ public void trimFront (int n) { while (n < itself.length() && itself.charAt (n) <= ' ') n++; itself = n > itself.length() ? "" : itself.substring (n); } //======================= /** Return the first word of the String, down to but not * including the first whitespace character. */ public String firstWord() { for (int k = 0; k < itself.length(); k++) if (itself.charAt (k) <= ' ') return itself.substring (0, k); return itself; // since the string has no whitespace } //======================= /** Strip out all non-digits from the StringInfo object. */ public void retainDigits() { String result = ""; for (int k = 0; k < itself.length(); k++) if (itself.charAt(k) >= '0' && itself.charAt(k) <= '9') result += itself.charAt (k); itself = result; } //======================= /** Return the numeric equivalent of itself. * Ignore the first invalid character and anything after it. * If the part of the string before the first invalid * character is a numeral, return the double equivalent, * otherwise return the value of badNumeral. */ public double parseDouble (double badNumeral) { if (itself.length() == 0) return badNumeral; boolean hasNoDigit = true; // until a digit is seen int pos = (itself.charAt (0) == '-') ? 1 : 0; for ( ; hasDigitAt (pos); pos++) hasNoDigit = false; if (pos < itself.length() && itself.charAt (pos) == '.') for (pos++; hasDigitAt (pos); pos++) hasNoDigit = false; return hasNoDigit ? badNumeral : Double.parseDouble (itself.substring (0, pos)); } //======================= private boolean hasDigitAt (int pos) { return pos < itself.length() && itself.charAt (pos) >= '0' && itself.charAt (pos) <= '9'; } //======================= } import javax.swing.*; public class PrintSquares { /** Print a table of integers 1..10 and their squares. */ public static void main (String[ ] args) { JTextArea area = new JTextArea (10, 15); // 1 JScrollPane scroller = new JScrollPane (area); // 2 String table = "Table of integers and their squares"; // 3 for (int k = 1; k <= 100; k++) // 4 table += "\n" + k + "\t" + k * k; // 5 area.append (table); // 6 JOptionPane.showMessageDialog (null, scroller); // 7 System.exit (0); // 8 } //====================== } import javax.swing.*; public class View extends Object { private JTextArea area; private JScrollPane scroller; public View (int rows, int columns) { area = new JTextArea (rows, columns); scroller = new JScrollPane (area); } //====================== /** Show the message in a scrolled text area of a dialog. */ public void display (String message) { area.append (message); IO.say (scroller); } //====================== } public class RepairOrder extends Object { private String itsFirstName = ""; private String itsLastName = ""; private String itsRepairJob = ""; private double itsEstimatedTime = 0.00; public RepairOrder (String par) { super(); if (par != null) { StringInfo si = new StringInfo (par); si.trimFront (0); // remove any leading whitespace this.itsFirstName = si.firstWord(); si.trimFront (this.itsFirstName.length()); this.itsLastName = si.firstWord(); si.trimFront (this.itsLastName.length()); this.itsRepairJob = si.toString(); } } //====================== public String getClient() { return itsFirstName + " " + itsLastName; } //====================== public String getRepairJob() { return itsRepairJob; } //====================== public double getEstimatedTime() { return itsEstimatedTime; } //====================== public void setEstimatedTime (double time) { if (time > 0.0 && time < 20.0) itsEstimatedTime = time; } //====================== public String toString() { return itsLastName + ", " + itsFirstName + ": " + itsRepairJob + ", time= " + itsEstimatedTime; } //====================== } public class RepairShop { private static final String ENTER = "Enter first name, last name, and description of job"; private static final String TIMEPROMPT = "Estimate the time to complete the repair job"; private static final String CHOICES = "Enter A to add another" + " job, X to exit, anything else to process a job"; /** Repeatedly get repair jobs from the foreman or display * the next repair job to the foreman, until there are no * more jobs to be done. */ public static void main (String[] args) { View output = new View (40, 25); //1 Queue jobQueue = new Queue(); //2 RepairOrder nextJob = new RepairOrder (IO.askLine (ENTER)); double totalTime = IO.askDouble (TIMEPROMPT); //4 nextJob.setEstimatedTime (totalTime); //5 jobQueue.enqueue (nextJob); //6 String input = IO.askLine (CHOICES); //7 while ( ! input.equals ("X") && ! input.equals ("x")) //8 { if (input.equals ("A") || input.equals ("a")) //9 { nextJob = new RepairOrder (IO.askLine (ENTER)); //10 nextJob.setEstimatedTime (IO.askDouble (TIMEPROMPT)); jobQueue.enqueue (nextJob); //12 totalTime += nextJob.getEstimatedTime(); //13 output.display ("\nHours remaining: " + totalTime); } //15 else if (jobQueue.isEmpty()) //16 IO.say ("No jobs currently in the queue!"); //17 else //18 { nextJob = (RepairOrder) jobQueue.dequeue(); //19 totalTime -= nextJob.getEstimatedTime(); //20 output.display ("\nNext job: " + nextJob.toString() + "\nHours remaining: " + totalTime); } //23 input = IO.askLine (CHOICES); //24 } //25 System.exit (0); //26 } //====================== }