inputField.addActionListener(listener); } private class NumberListener implements ActionListener { public void actionPerformed(ActionEvent ae) { try { double num = Double.parseDouble(inputField.getText()); myLabel.setText("You entered: " + num); } catch (NumberFormatException nfe) { myLabel.setText("!!ERROR"); } } } } 12 @Test public class MyInteger public void testMyInteger() { implements Comparable<MyInteger> { MyInteger a = new MyInteger(2); MyInteger b = new MyInteger(5); private int val; assertEquals(-3, a.compareTo(b)); assertEquals(3, b.compareTo(a)); public MyInteger(int value) { assertEquals(0, a.compareTo(a)); val = value; } } public int compareTo(MyInteger other) { return this.val - other.val; } 13. Candidate Objects and Major Responsibility BookStore: Coordinates Activities (Check out student, collect payment, update inventory) Student: Keeps track of CatCard number, address, sales confirmation order ShoppingBasket: Keeps track of desired purchases Item: one the books that can be purchased Shelf: Shows books for purchase, with browse/search Inventory: Keeps inventory levels of all items
inputField.addActionListener(listener); } private class NumberListener implements ActionListener { public void actionPerformed(ActionEvent ae) { try { double num = Double.parseDouble(inputField.getText()); myLabel.setText("You entered: " + num); } catch (NumberFormatException nfe) { myLabel.setText("!!ERROR"); } } } } 12 @Test public void testMyInteger() { MyInteger a = new MyInteger(2); MyInteger b = new MyInteger(5); assertEquals(-3, a.compareTo(b)); assertEquals(3, b.compareTo(a)); assertEquals(0, a.compareTo(a)); } public class MyInteger implements Comparable<MyInteger> { private int val; public MyInteger(int value) { val = value; } public int compareTo(MyInteger other) { return this.val - other.val; } 13. Candidate Objects and Major Responsibility BookStore: Coordinates Activities (Check out student, collect payment, update inventory) Student: Keeps track of CatCard number, address, sales confirmation order ShoppingBasket: Keeps track of desired purchases Item: one the books that can be purchased Shelf: Shows books for purchase, with browse/search Inventory: Keeps inventory levels of all items
335PracticeTest1Answers.docx