Answers for Practice Midterm B 1a. public static void main(String[] args) { int x; x = Integer.parseInt( JOptionPane.showInputDialog("Enter an int.")); if(x % 10 == 7) System.out.println("The number ends in 7."); else System.out.println("The number does not end in 7."); } 1b. public static void main(String[] args) { String x; x = JOptionPane.showInputDialog("Enter a string.")); if(x.charAt(0) == 'T' || x.charAt(0) == 't') System.out.println("The string begins in T or t."); else System.out.println("The string does not begin in T or t."); } 2a. public static void main(String[] args) { int x, count = 0; x = Integer.parseInt( JOptionPane.showInputDialog("Enter an int.")); while(x > 0) { if(x % 10 == 7) count++; x = Integer.parseInt( JOptionPane.showInputDialog("Enter an int.")); } System.out.println("The count of numbers ending" + " in 7 is " + count); } 2b. public static void main(String[] args) { String x; boolean isLength4 = false; x = JOptionPane.showInputDialog("Enter a string.")); while(x > 0) { if(x.length() == 4) isLength4 = true; x = JOptionPane.showInputDialog("Enter a string.")); } if (isLength4) System.out.println("There is a string of length 4"); } 2c. public static void main(String[] args) { int hoursWorked; double hourlyWage, totalWages = 0; hoursWorked = Integer.parseInt( JOptionPane.showInputDialog("Enter hourly wage.")); while(hoursWorked > 0) { hourlyWage = Double.parseDouble( JOptionPane.showInputDialog("Enter a hours worked.")); totalWages += hoursWorked * hourlyWage; hoursWorked = Integer.parseInt( JOptionPane.showInputDialog("Enter hourly wage.")); } System.out.println("Total wages = " + totalWages); } 2d. public static void main(String[] args) { String name, gender, maxName; double salary, maxSalary; name = JOptionPane.showInputDialog("Enter the name.")); while(!name.equals("endoflist") { gender = JOptionPane.showInputDialog("Enter the gender.")); salary = Double.parseDouble( JOptionPane.showInputDialog("Enter salary.")); if (salary > maxSalary && gender.equals("F")) { maxSalary = salary; maxName = name; } name = JOptionPane.showInputDialog("Enter the name.")); } System.out.println("The woman with the " + "largest salary is " + maxName); }