SOURCE CODE FILES FOR Debugging EXAMPLES ==================================================================== // Project WagesForMonth // Class Main import java.util.StringTokenizer; import java.text.DecimalFormat; public class Main { public static void main(String[] args) { String inputString; int hours; double hourlyWage, paymentForMonth = 0.0, totalForMonth = 0.0; System.out.print("Payments for month:"); inputString = JOptionPane.showInputDialog( "Enter hours and hourly wage."); while(inputString != null && !inputString.equals("")) { StringTokenizer st = new StringTokenizer( inputString, " "); hours = Integer.parseInt(st.nextToken()); hourlyWage = Integer.parseInt(st.nextToken()); if (hours <= 40) totalForMonth = 40 * hourlyWage + 1.5 * hourlyWage * hours - 40; else totalForMonth = hourlyWage * hours; inputString = JOptionPane.showInputDialog( "Enter hours and hourly wage."); } System.out.println("/n/nTotal for month: " + paymentForMonth); } } ==================================================================== // Project MetricConverter // Class English public class English { // Instance variables for English length object. private int yards; private int feet; private int inches; private int numerator; private int denominator; // Usual parameterized constructor. public English(int y, int i, int f, int n, int d) { yards = y; feet = f; inches = i; numerator = n; denominator = d; } public English(int meters) { double yardsDouble, feetDouble, inchesDouble, yardsRemainder, feetRemainder, inchesRemainder; yardsDouble = 1.0936133; yards = (int) yardsDouble; yardsRemainder = yardsDouble - yards; feetDouble = 3 * yardsRemainder; feet = (int) feetDouble; feetRemainder = feetDouble - feet; inchesDouble = feetRemainder * 12; inches = (int) inchesDouble; inchesRemainder = inchesDouble - inches; denominator = 64; numerator = (int) (inchesRemainder * 64 + 0.5); } public double getMeters() { return (yards + feet / 3.0 + (inches + numerator / denominator) / 36.0) * 1.0936133; } public String toString() { return yards + "yd " + feet + "ft " + inches + "-" + numerator + "/" + denominator + "in" ; } } ==================================================================== // Project Twin Primes // Class Main public class Main { public static void main(String[] args) { int n; for(n = 3; n <= 1000; n++) if(isPrime(n) && isPrime(n + 2)) System.out.println(n + " " + (n + 2)); } public static boolean isPrime(int n) { int factor, sqrtn; sqrtn = (int) Math.sqrt(n); for(factor = 2; factor <= sqrtn; factor++) if (factor % n == 0) return false; return true; } } ==================================================================== // Project MaxSalary // Class Main import javax.swing.JOptionPane; import java.util.StringTokenizer; public class Main { public static void main(String[] args) { String aName, s; double aSalary; StringTokenizer st; MaxSalary ms = new MaxSalary("", -1.0); s = JOptionPane.showInputDialog( "Enter name and salary."); while(s != null && !s.equals("")) { //StringTokenizer st = new StringTokenizer(s, " "); aName = st.nextToken(); aSalary = Double.parseDouble(st.nextToken()); ms.update(aName, aSalary); s = JOptionPane.showInputDialog( "Enter name and salary."); } System.out.println(s); } } -------------------------------------------------------------------- // Project MaxSalary // Class MaxSalary public class MaxSalary { String name; double salary; public MaxSalary(String aName, double aSalary) { name = aName; salary = aSalary; } public void update(String aName, double aSalary) { if (aSalary > salary) { aSalary = salary; aName = name; } } public String toString() { return "Maximum salary is $" + salary + "\nPerson with maximum salary is " + name + "."; } } ====================================================================