Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Quiz 6 Worksheet - Object Oriented Programming I | CMSC 132, Quizzes of Computer Science

Material Type: Quiz; Professor: Padua-Perez; Class: OBJECT-ORIENTED PROG II; Subject: Computer Science; University: University of Maryland; Term: Unknown 1989;

Typology: Quizzes

Pre 2010

Uploaded on 02/13/2009

koofers-user-l7t
koofers-user-l7t 🇺🇸

10 documents

1 / 1

Toggle sidebar

Related documents


Partial preview of the text

Download Quiz 6 Worksheet - Object Oriented Programming I | CMSC 132 and more Quizzes Computer Science in PDF only on Docsity!

CMSC 132 Quiz 6 Worksheet

The next quiz of the course will be on Wednesday, November 29 during your lab (discussion) session. The

following list provides more information about the quiz:

• The quiz will be a written quiz (no computer).

• Closed book, closed notes quiz.

• Answers must be neat and legible. We recommend that you use pencil and eraser.

The following exercises cover the material to be included in this quiz. Solutions to these exercises will not

be provided, but you are welcome to discuss your solutions with TAs and instructors during office hours.

Regular Expressions

1. Write a Java regular expression that represents any number of a’s, followed by any number of b’s.

2. Write a Java regular expression that represents valid phone numbers. A valid phone number has

an area code, a dash, a three-digit number, a dash, and a four-digit number.

3. Write a Java regular expression that represents a valid e-mail address.

4. What language is represented by the following Java regular expression?

abcd*[0-9]+

Inner Classes

1. What is the difference between an inner class and a nested class?

2. An interface named ElectricDevice declares the following method:

public int getWatts();

Using anonymous classes, replace the comment in the following main with an object that

implements the ElectricDevice interface. The getWatts() method should return 100.

public static void main(String[] args) {

ElectricDevice device = /* PUT YOUR CODE HERE */

}

3. Modify the following class, so the ActionListener used for the postButton is defined using an

inner class instead of an anonymous inner class.

public class GuiExample extends JPanel { public GuiExample() { JFrame frame = new JFrame("Example"); frame.setContentPane(this); // adds the panel JButton postButton = new JButton("Post"); add(postButton);

postButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent evt) { System. out .println("Posting message"); } }); frame.pack(); frame.setVisible(true); } }