






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







Abba a = new Abba("Kim"); Bar b = new Bar("Devon"); Goo g = new Goo("Chris"); a.one(); // __________________________________ System.out.println("\n"); a.two(); // __________________________________ System.out.println("\n"); b.one(); // __________________________________ System.out.println("\n"); b.two(); // __________________________________ System.out.println("\n"); b.three();// _________________________________ System.out.println("\n"); g.one(); // __________________________________ System.out.println("\n"); g.two(); // __________________________________ System.out.println("\n"); g.three();// __________________________________ System.out.println("\n"); class Abba extends Object { private String id; public Abba(String ID) { id = ID + " "; } public String getID() { return id; } public void one() { System.out.print("A1 " + getID()); } public void two() { System.out.print("A2 "); three(); } public void three() { System.out.print("A3 " + getID()); } } //////////////////////////////////// class Bar extends Abba { public Bar(String id) { super(id); } public void one() { two(); } public void three() { System.out.print("B3 " + getID()); } } //////////////////////////////////// class Goo extends Bar { public Goo(String ID) { super("X" + ID + "X"); } public void two() { System.out.print("G2 "); super.three(); } public void three() { System.out.print("G3 "); } }
public class First { public void method2() { System.out.println("First2"); } public void method3() { method2(); } } public class Second extends First { public void method2() { System.out.println("Second2"); } } class Third extends Second { public void method1() { System.out.println("Third1"); super.method2(); } public void method2() { System.out.println("Third2"); } } public class Fourth extends First { public void method1() { System.out.println("Fourth1"); } public void method2() { System.out.println("Fourth2"); } }
public class StandardAccount { private String name; private ArrayList items; public StandardAccount(String name) { name = name; items = new ArrayList(); } public void add(Item i) { items.addElement(i); } public String getName() { return name; } public Item get(int i) { return (Item)items.elementAt(i); } public int length() { return items.size(); } public double getBill() { double bill = 5.0; for (int i = 0; i < items.size(); i++) { Item next = (Item)items.elementAt(i); bill += next.getPrice(); } return bill; } public void print() { System.out.println("Standard Customer "
3a. Write Background as if it were in its own file. 3c. Complete OvalBackground around the method given as if it were in its own file. The single drawBackground method is provided below to remind you of methods that will help you complete the other Background class. public void drawBackground(JFrame f) { Graphics g = f.getContentPane().getGraphics(); Graphics2D g2 = (Graphics2D)g; // Clear old background g2.setPaint(f.getBackground()); g2.fill(new Rectangle(f.getHeight(), f.getHeight())); // Clear old background g2.setColor(my_color); for(double r = 5.0; r < f.getHeight() - 40.0; r += 5.0) g2.draw(new Ellipse2D.Double(r, r, my_width, my_height)); } } // end class OvalBackground
<
3d. Completely write SquareBackground as if it were in its own .java file. 3e. Describe what you would have to do to add a third background strategy to your system. Do NOT write the new strategy.