



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: Fall 2000;
Typology: Exams
1 / 7
This page cannot be seen from the preview
Don't miss anything!




class One { public String toString() { return "one"; } public void methodOne() { System.out.println("aaa"); methodTwo(); } public void methodTwo() { System.out.println("bbb"); } } class Two extends One { public String toString() { return "two/" + super.toString(); } public void methodOne() { System.out.println("ccc"); super.methodOne(); } public void methodTwo() { System.out.println("ddd"); } } class Three extends One { public void methodOne() { System.out.println("eee"); } public void methodThree() { System.out.println("fff"); } } // Initialize some objects One aOne = new One(); One aTwo = new Two(); Two anotherTwo = new Two(); Three aThree = new Three(); //////////////////////////////////////////////////////////// System.out.println(aOne); ///////////////////////////////////////////////////////// /// System.out.println(aTwo); ///////////////////////////////////////////////////////// /// System.out.println(aThree); ///////////////////////////////////////////////////////// /// aOne.methodOne(); ///////////////////////////////////////////////////////// /// aTwo.methodOne(); ///////////////////////////////////////////////////////// /// aThree.methodOne(); ///////////////////////////////////////////////////////// /// aOne.methodTwo(); ///////////////////////////////////////////////////////// /// aTwo.methodTwo(); ///////////////////////////////////////////////////////// /// aThree.methodTwo(); ///////////////////////////////////////////////////////// /// Two obj1 = new One(); ///////////////////////////////////////////////////////// /// aTwo.methodThree(); ///////////////////////////////////////////////////////// /// aOne.methodThree(); ///////////////////////////////////////////////////////// /// One obj2 = (One) aTwo;
// Complete the code on the next page import javax.swing.; import java.awt.; import java.awt.event.*; public class CashRegisterGUI extends JFrame { public static void main(String[] args) { CashRegisterGUI aWindow = new CashRegisterGUI(); aWindow.show(); } private ItemList sale = new ItemList(); // ItemList is the Model private JButton enterButton = new JButton("Enter"); // All three Labels will be right justified when used as initialized here private JLabel quantityLabel = new JLabel("Quantity ", JLabel.RIGHT); private JTextField quantityField = new JTextField(); private JLabel priceLabel = new JLabel("Price ", JLabel.RIGHT); private JTextField priceField = new JTextField(); private JLabel subtotalLabel = new JLabel("Sub total ", JLabel.RIGHT); private JLabel currentTotalLabel = new JLabel("0.00"); private JButton showTotalButton = new JButton("Show all items"); public CashRegisterGUI() { setTitle("Cash Register"); setSize(160, 150); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container cp = getContentPane();
private class EnterListener implements ActionListener { public void actionPerformed(ActionEvent e) { private class TotalListener implements ActionListener { public void actionPerformed(ActionEvent e) {
Suggested Readings: The refactoring catalogue http://www.refactoring.com/catalog/index.html Presentation 8 http://www.cs.arizona.edu/classes/cs335/fall04/presentations/08-ObjectRelationships.ppt Section Handout http://www.cs.arizona.edu/classes/cs335/fall04/Misc/SectionRefactorings-Answers.doc
public class Course { private String number; private double units; public Course(String courseNumber, double courseUnits) { number = courseNumber; units = courseUnits; } public double getUnits() { return units; } public String toString() { return number + " " + units; } } ////////////////////////////////////////////////// // A Collection of these are stored in CourseDataBase public class RegisteredCourse { private RegisteringStudent student; private Course course; public RegisteredCourse(RegisteringStudent s, Course c) { student = s; course = c; } public String toString() { return "<" + student.toString() + " " + course.toString() + ">"; } }