COSC 420 – Spring 2003 - Faculty



COPPIN STATE COLLEGE

COSC 420 – Spring 2005

TAKE HOME FINAL

(Your answers should be submitted in type format, NO handwritten)

NOTE: Your FINAL EXAM is scheduled on Tuesday, 05/17/05, 2-3:20 pm. However, this take home exam is due on THURSDAY, 05/19/05 by 3:20 pm POSITIVELY. On Thursday (05/19/05), I’ll be in my office. You make an appointment with me in advance for your convenient time (between 2-3:20pm) to see me with your SOLUTIONS of this Take Home Final. You have to convince me that you did this work by yourself. Failure to follow this instruction, you will end up with Fail grade. Submit hardcopies of all your programs and outputs as well as a floppy disk containing all programs.

TASK 1 Programming with Java (80pts)

(a) (20pts) Text File Operations:

Write an Object-Oriented class for the following problem in Java. Provide appropriate constructors, accessors, and mutators. Write the test class with main() method separately. Read the input file name using the appropriate constructor of the class from the test class.

Read two numbers from a text file until they are exhausted. Compute their quotients and remainders. Print out the numbers, their quotients and remainders in tabular format. Create an input data file with followings using Notepad and save the file using name “YourNameInFile.txt” in A:drive, where YourName is your last name. Give the output file name “YourNameOutFile.txt” and create the output file also in A: drive. Also, provide provision in your program for a standard output. The input data are

5 2

24 5

102 23

7 9

221 45

72 8

996 79

56 32

8 3

20 7

Your Out put should look like below

Number1 Number2 Quotient Remainder

5 2 2 1

… … … …

(b) User Interface

Type, compile, and Run the Java UI program Exercise 13.8 of page 613 from your textbook. The exercise is a solved program available from your textbook CD.

a) (25pts) Add another window to the program that should perform the task of Exercise 13.5 (p.612). Create a color selector on the window as shown in Exercise 13.9. The purpose of providing the color selector is that the user should able change to his/her desired color of any geometric figure.

b) (25pts) Add another window to perform the temperature conversions from Fahrenheit to Celsius temperatures and from Celsius to Fahrenheit temperatures. The pop-up window should be similar to that of Simple Calculator (of Ex. 13.8). Also add two more buttons on the window in the second row naming “Add to InFile” and “Add to OutFile” to record your input data and the results in input text files and output text files. Provide appropriate menu similar to “Operation” and “Exit”

c) (10pts) On the Multiple Windows Demo window, provide with appropriate buttons to operate those two additional pop-up windows that you have to create in items (a) and (b). Give appropriate names of those two buttons.

EXTRA CREDIT POINTS (20pts)

d) Add another window to perform the task of RadioButton Demo, but change the radio buttons with animation. Provide only two radio buttons “Start” and “Stop”. When user clicks the Start button, the stop light should show Red, Yellow, and Blue colors in sequence. Give display times for Red 1 minute, Yellow 30 seconds, and Blue for 2 minutes. The “Stop” button” should enable the user to stop the animation. For animation, you may use multithreading or timer class (Chapter 18). On the Multiple Windows Demo window, provide with appropriate button to operate this additional pop-up window. Give appropriate name of this button.

C. (6pts) General Questions on programming and Object-Orientd programming. Circle the correct answers for the following questions:

1. Which of the following statement(s) are equivalent to this Boolean statement:

if(i < 0) if (j < 0) x = 0; else if (k < 0) y = 0; else z = 0;

(Note: All variables are type int)

I if(i < 0)

if (j < 0)

x = 0;

else if (k < 0)

y = 0;

else

z = 0;

II if(i < 0)

{

if (j < 0)

x = 0;

else if (k < 0)

y = 0;

}

else

z = 0;

III if(i < 0)

if (j < 0)

x = 0;

else if (k < 0)

y = 0;

else

z = 0;

A. I and II

B. I and III

C. II and III

D. I, II, and III

E. II only

2. A Java program has three following classes. What this program will do?

public class XClass

{

// Constructor

public XClass( )

{

System.out.println (“You have invoked the default constructor of XClass.”) ;

}

}

public class YClass extends XClass

{

// Constructor

public YClass(String str)

{

System.out.println(str);

}

}

public class ZClass

{

public static void main(String[] args)

{

YClass objY = new YClass("This is the constructor of YClass.");

}

}

A. The default constructor of class YClass is not defined; error will be detected during bytecode generation.

B. Standard output: This is the constructor of YClass.

C. Standard output (two lines): This is the constructor of YClass.

You have invoked the default constructor of XClass.

D. Standard output: You have invoked the default constructor of XClass.

E. Standard output (two lines): You have invoked the default constructor of XClass.

This is the constructor of YClass.

(Note: A “Standard output” means a Console output)

3. A purchase system gives discounts, but only to frequent purchasers. If a customer has purchased more than $20.00 of goods to date, a discount of 5% is given, while if they have purchased more than $50.00 of goods to date a discount of 10% is given.

Procedure Discount

begin

reduction = 0%;

if purchasesToDate >= $20.00

reduction = 5%;

else if purchasesToDate >= $50.00

reduction = 10%;

return reduction;

end Discount

Before the implementation of the procedure (or method) Discount from the problem statement of the purchase system, one of your team members wrote the pseudocode for the procedure as above. Identify your correct observation:

A. purchasesToDate >= $20.00 is not correct

B. purchasesToDate >= $50.00 is not correct

C. else if never executed

D. The procedure Discount will execute correctly.

E. The procedure will not execute correctly due to the problems of A, B, and C.

Task 2: (20pts) Review Chapter 11, 12, 13, 14, 15, and 16 and answers the following questions: (1 pts each)

1. What method do you use to set the location of a frame on the screen?

a. setPosition

b. setLocation

c. setSize

d. setDimention

2. What layout manager do you use to place three components in a frame so that all the components have the same size?

a. BorderLayout

b. FlowLayout

c. GridLayout

d. None of the above

3. What is the default layout manager for the content pane of a JFrame?

a. FlowLayout

b. BorderLayout

c. GirdLayout

d. No default layout manager

4. What is the default layout manager for a JPanel?

a. FlowLayout

b. BorderLayout

c. GirdLayout

d. No default layout manager

5. ____________ sets a background of a JPanel object p to yellow.

a. p.setColor(Color.yellow)

b. p.setBackground(Color.yellow)

c. p.setBackgroundColor(Color.yellow)

d. p.setBackGroundColor(Color.yellow)

6. _______________ draws a circle whose center position is (400, 400) and whose radius is 50.

a. g.drawCircle(350, 350, 100, 100)

b. g.drawOval(350, 350, 100, 100)

c. g.drawCircle(400, 400, 50, 50)

d. g.drawOvale(400, 400, 50, 50)

7. What method do you use to set the text to the right of the icon in an instance jbt of JButton?

a. jbt.setHorizontalAlignment(SwingContants.RIGHT)

b. jbt.setVerticalAlignment(SwingContants.RIGHT)

c. jbt.setHorizontalTextPosition(SwingContants.RIGHT)

d. jbt.setVerticalTextPosition(SwingContants.RIGHT)

8. Suppose you want to display a text in multiple lines, which component should you use?

a. JButton

b. JLabel

c. JTextField

d. JTextArea

9. What method do you use to disable editing on an instance jtf of JTextField?

a. jtf.setEditing(false)

b. jtf.setEditable(false)

c. jtf.enableEditing(false)

d. jtf.setEdit (false)

10. Since JButton is an instance of Container, is it possible to add another button inside an instance of JButton?

a. Yes

b. No

11. Can a JComboBox instance generate the following events?

a. ComponentEvent

b. MouseEvent

c. ActionEvent

d. ItemEvent

e. All above

12. The method that executes immediately after the init() method in an applet is __________.

a. destroy()

b. start()

c. stop()

d. run()

13. Which of the following statements is not true?

a. A panel can be placed inside a panel.

b. A frame can be placed inside a frame.

c. A source object and a listener object can be the same.

d. A source object can register many listeners.

14. What should you use to position a button within an application frame so that the size of the button is NOT affected by the frame size?

a. a FlowLayout

b. a GridLayout

c. the center area of a BorderLayout

d. the East or West area of a BorderLayout

e. the North or South area of a BorderLayout

15. Does the following operation cause an exception? If so, what exception is thrown?

1.0 / 0

16. What happens if you attempt to open a nonexistent file using FileInputStream?

17. How do you check if file test.dat exists?

18. What stream do you use to store numeric data in text format in a file?

19. How do you detect end-of-file when reading the data using the read() method?

20. Suppose you use the read() method to read data byte-by-byte from a file, how do you know you have reached the end of file?

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download