




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Exam; Class: Object-Oriented Programming and Design; Subject: COMPUTER SCIENCE; University: University of Arizona; Term: Unknown 1989;
Typology: Exams
1 / 8
This page cannot be seen from the preview
Don't miss anything!





ArrayList list = new ArrayList(); list.add("a"); list.add("b"); list.add("c"); ArrayList list2 = new ArrayList(); list2.add("d"); list2.add(list); list2.add("e"); System.out.println(list2);
String s1 = "abc"; Object o1 = new Object(); // Compiles? ______ Object o2 = s1; // Compiles? ______ Integer anInt = new Object(); // Compiles? ______ Integer int2 = (Integer)o1; // Compiles? ______ String s2 = o2; // Compiles? ______ System.out.println((String)o2); // Compiles? ______ System.out.println((Integer)s2); // Compiles? ______
ArrayList list = new ArrayList(); list.add(new Integer(3)); list.add(new Integer(5)); list.add(new Integer(1)); list.add(new Integer(4)); Iterator itr = list.iterator(); System.out.println(itr.hasNext()); System.out.println(itr.next()); System.out.println(itr.next()); System.out.println(itr.next());
JTextField inputField = new JTextField("123point4"); double input = 0.0; try { input = Double.parseDouble(inputField.getText()); System.out.println("Good"); } catch (RuntimeException rte) { System.out.println("Bad"); } System.out.println("Ugly");
public class SearcherGUIWorks extends JFrame { public static void main(String[] args) { new SearcherGUIWorks().setVisible(true); } private JList listView = new JList(); private Object[] wordArray = null; public SearcherGUIWorks() { setUpLayout(); setUpModel(); setUpListeners(); } private void setUpListeners() { } private void setUpModel() { ArrayList myWords = new ArrayList(); Scanner readWords = null; try { readWords = new Scanner(new File("dictionary.txt")); } catch (FileNotFoundException e) { e.printStackTrace(); } while (readWords.hasNext()) myWords.add(readWords.nextLine()); wordArray = myWords.toArray(); listView.setListData(wordArray); } private void setUpLayout() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(200, 300); setTitle("WordSearcher"); Container cp = this.getContentPane(); cp.add(inputField, BorderLayout.NORTH); cp.add(new JScrollPane(listView), BorderLayout.CENTER); }
// BorrowCommand attaches a specific book copy to a specific subscriber, both, the book // copy’s and the subscriber’s objects are supplied by the programmer. The BorrowCommand // must have its receivers supplied in the constructor. public class BorrowCommand implements Command { protected Borrower theBorrower; protected Book theBook; public BorrowCommand(Borrower aBorrower, Book aBook) { theBorrower = aBorrower; theBook = aBook; } // When the Borrow button is clicked, execute this public boolean execute() { System.out.println(theBorrower + " attempts to BORROW " + theBook); } public boolean undo() // a borrow by returning { System.out.println(theBorrower + " undo a Borrow" + theBook); } }