Chapter 7-6

1.)Write a code segment that obtains an input from a text field called inputField, converts the input to an integer, and outputs the square root of the integer to a text field called outputField.

2.)Assume that an action listener has been added to button. Which method runs when the user clicks the button.

3.)Describe the roles and responsibilities of the model, view, and controller classes in a GUI program.

Published in: on April 30, 2008 at 4:09 pm  Leave a Comment  

Chapter 6-8

1.)Describe how to set up a timer and explain what it does.
When the timer is sent the start message, its clock starts ticking, when each interval of time passes, the listener’s actionPerformed method is triggered. This method runs the operations to move the object and repaint the panel, because the timer uses the computer’s clock to measure the intervals, they will not vary with the execution speed of the computer.
2.)Describe the factors that affect our perception of the movement of a graphical object.

3.)What causes flicker? How can flicker be eliminated.

4.)How do the direction and velocity of an object determine where it will be placed after a given unit of time

Published in: on April 30, 2008 at 3:58 pm  Leave a Comment  

Chapter 4-10

1.)write a code segment that uses an I/O dialog box to prompt the user for her name.

2.)write a code segment that display your name and address in a message box, name an address should be formatted on separate lines by using the “\n” character.

3.)why we need to used the methods Integer.parseInt and Double.parseDouble when receiving numeric input from an I/O dialog box.

4.)give an example of a situation where you would want a panel to set its preferred size, rather than allow the size of the main window to determine that.

Published in: on April 23, 2008 at 2:39 pm  Leave a Comment  

Chapter 3-7

1-a.)a filled rectangle with corner point(45, 20) and size 100 by 50
-g.drawRectangle(45, 20, 100, 50)
b.)a line segment with end points(20, 20) and (100, 100)
-g.drawSegment(20, 20, 100, 100)
c.)a circle with center point(100, 100) and radius 50
-g.drawCircle(150, 150, 50, 50)
d.)a triangle with vertices (100, 100), (50, 50), and (200, 200)
-g.drawTriangle(100, 100, 50, 50, 200, 200)
2.)describe the design of a program that displays a filled blue rectangle on a red background
-The program uses a modified version of the have added a paintComponent method that draws a blue regtangle containing a red text message when the window opens and whenever it is refreshed. The paintComponent methid first calls the same method in the superclass, using the reserved word super. The reason is that the method in the superclass paints the background of the panel.
3.)how does one compute the center point of a panel
-The method getWidth() and getHight() return the current width and hight of a panel, respectively. It will compute the center point of a panel. If the methods are called before the window is opened, they return a default value of 0.
4.)list the three properties of a text font
-color, font size, font style

Published in: on April 23, 2008 at 2:31 pm  Leave a Comment  

Chapter 2-7

1-a.)White-new Color(255, 255, 255)
b.)Black-new Color(0, 0, 0)
c.)Highest Intensity Blue-new Color(200, 200, 255)
d.)Medium Gray-new Color(128, 128, 128)
2.)A frame is a class which the code for application windows in Java is located. A panel is a flat, rectangular area suitable for displaying other objects such as geometric shapes and images. A layout manager is an object which a frame or a panel uses in container object in Java.
3.)When we have more than one penal or other objects to display in a window, we have to be concern about how they are organized or laid out.
4.)write a code used to set the layout for adding panels to a 5-by-5 grid in a window
import javax.swing.*;
import java.awt.*;
public class GUIWindow{
public static void main(String[] args){
JFrame theGUI = new JFrame ();
theGUI.setTitle(“Fourth GUI Progrgam”);
theGUI.setSize(300, 200);
theGUI. setDefaultCloseOperation(JFrame.EXIT_OM_CLOSE_);
JPanel.panel1 = new JPanel();
panel1.setBackground(Color.white);
JPanel.panel2 = new JPanel();
panel2.setBackground(Color.black);
JPanel.panel3 = new JPanel();
panel3.setBackground(Color.gray);
JPanel.panel4 = new JPanel();
panel4.setBackground(Color.white);
Container pane = theGUI.getContentPane ();
pane.setLayout(new GridLayout (5, 5));
pane.add(panel1);
pane.add(panel2);
pane.add(panel3);
pane.add(panel4);
theGUI.setVisible(true);
}
}

Published in: on April 22, 2008 at 3:35 pm  Leave a Comment  

Chapter 12-1

EX 12-1
1.)what keeps a recursive definition from being circular
-The fact that sum(1) is defined to be 1 without making reference to further invocations of sum saves the process from going on forever and the definition fro being circular.
2.)what are two parts of any recursive method
-A method is said to be recursive if it calls itself. First, some function f(n) is expressed in term of f(n-1) and perhaps f(n-2) and so no. Second, to prevent the definition from being circular, f(1) and perhaps f(2) and so on are defined explicitly.
3.)why is recursion more expensive than iteration
-
4.)what are the benefits of using recursion
-

Published in: on April 18, 2008 at 5:10 pm  Leave a Comment  

Chapter 9

EX 9-1
1.)An array can group similar data with on array that contains many elements.
2.)They use the name and the index to access it.
3.)

EX 9-2
1-a.)34
b.)4
c.)156
2.)The JVM checks the values of subscripts before using them and throws an ArrayIndexOutBoundsException if they are out of bound.

EX 9-3
1.)int i = 0 for (i==0, i=0; i –) System.out.print(a[i])
2.)int i = a.length – 1 for (i == a.length – 1; i>=0; i –) System.out.print(a[i])
3.)int index; for (int i =0; i < a. length; i ++){if (a[i] <0 ){index = i; break; } else {index = a.length;} System.out.print (index) ;
4-a.)It will change all the negative values of a to positive value by taking the absolute values of them.
b.)The loop will just get the sum of all elements of the a array.
5.)It tells the operator precisely how many elements inside the array.

EX 9-4
1-a.)double[] abc = new double[15]
b.)string[] abcd = new string[20]
2.)It is another way to initialize the array, it assign the exact values to the array’s element.
3-a.)int [] aaa = {100, 90, 75, 60, 88}
b.)double[] bbb = {0.12, 0.05, 0.15}
c.)string[] ccc = {nina, lu}
4.)

EX 9-5
1.)The programmer will try to solve the problem by tracking the array’s logical size with a separate integer variable.
2.)When the array is not full, it must replace the array;s physical length with its logical size in the loop.

EX 9-6
1.)A parallel array is situations in which it is convenient to declare.
2.)One array should contain the exponent and the other array should contain 2 raised to that power.
3.)String [] name = new String[50]int [] age = new int [50]int [] security = new int [50]String searchPerson;int correspondingAge = -1, correspondingSecurity = -1searchName = …for (int i = 0, i<name.length; i ++) if (searchName.equal (name[i]))correspondingAge = age [i]correpondingSecurity = security [i]break;}
4.)
5.)int[] exponent = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
int[] powers = new int[10];
for (int i = 0; int < 10; i++){
power [i] = math.pow(2, exponent[i])
} ;

EX 9-7
1.)An array in which each data item is accessed by specifying a pair of indices.
2.)If an application require the variable tale reference an array of four elements. Each of these elements in turn reference and array of five integers. And the application will need to use two dimensional arrays.
3.)
4.)

Published in: on February 14, 2008 at 5:10 pm  Leave a Comment  

Chapter 8

EX 8-1
1.)A hypertext is a structure consisting of nodes and the link between them. Each node is a document or chunk of text. During the late 1960s, the technology for realizing Bush’s dream became available, so Nelson coined the term hypertext to refer to Bush’s machine.
2.)Hypermedia is like hypertext but add more things inside, GUIs, Images, Sound, Animation, and Application.
3.)The address on the page for World Wide Web.
EX 8-2
1.)The HTML stand for hypertext markup language.
2.)The HTML text can indicate the format of textual elements or links to other nodes.
3.)<HTML> <HEAD> <TITLE>the title goes here</TITLE> </HEAD> <BODY> the text for the document goes here </BODY> </HTML>
4.)The HTML is a comment for the creator to reviews.
EX 8-3
1.) The HTML programmer need to use forced line break because a web page author or designer wants to display several lines of text without words wrap.
2.)We are preformatted next in an HTML document when we want the browser to display text, with line breaks, extra spaces, and tabs.
EX 8-4
1.)If you forget to close the markup tag for italics on a piece of text everything after the first quote will be italics.
2.)The purposes of the escape sequence in HTML is to let browser to display these characters rather than interpret them.
EX 8-5
1.)The three types of HTML are: Unordered(bulleted) lists-a bulleted list. Numbered(ordered) lists-can be nested within other lists to any depth, but more than three deep can be difficult to read. Definition(association) lists-display terms and their associated definition.
2.)
EX 8-6
1.)
2.)An absolute path name because it sepcifies the exact or absolute position of the file in the computer’s directory structure.
3.)We can use absolute or relative path names to specify the location of a target document.
4.) 
EX 8-7
1.)Inline images increase a document’s size and slow its transfer across the Internet. External images which are not display until the user clicks on a link.
2.)<IMG src=”ImageLocation”>
3.)<IMG SCR=”mypicture.gif”HEIGHT=200 WIDTH=200>
4.)<A href=”mypicture.gif”>Sample picture</A> <A href=”mypicture.gif”><IMG src=”mythumbnail.gif”></A>
EX 8-9
1.)An applet is a Java application that runs in a Web page, an HTML document that contains an applet markup tag. Example:<APPLET CODE=”byte code file name” WIDTH=width HEIGHT=height></APPLET>
2.)Applications that use a specialized view class for the main window, the conversion to an applet is surprisingly simple. First, replace the name JFrame with the name JApplet at the begining of the class definition. Second, replace the class’s constructor by the method init: public void init(){ }
3.)An applet cannot access files on the ensure security on the user’s machine.
4.)The images must reside on the Web server from which the applet’s byte code was sent. The JApplet method getDocumentBase() locates and returns the URLof the applet’s Web server. The JApplet method getImage expects this URL and the filename of an image as parameters. The method downloads the image from the Web server and returns an object of the class Image. This object can be converted to an ImageIcon object for further processing by using the ImageIcon(anImage) constructor.

Published in: on January 23, 2008 at 6:10 pm  Leave a Comment  

Chapter 7 Exercise

EX 7-2
1.)The structure of a query-controlled loop that processes repeated sets of inputs is the String variable doInAgain. This variable controls how many times the loop repeats, initially, the variable equals “y”. As soon as the user enters a string other than “y” or “Y”, the program terminates.
2.)Since the input of a lower case letter and a capital case letter count two different input, the toLowerCase() method avoid the problem of entering a same letter with wrong and get the wrong result. Therefore, the toLowerCase facilitate the program by indiscriminate between the lower case and the capital case letter.

EX 7-3
1.)The role the menu plays is to display a list of options, after this, the user can select the one they needs.
2.)The menu-driven programs prompts fro additional inputs related to that option and performs the needed computations, after which it displays the menu again.

EX 7-4
1-a.)%11s
b.)%12s
c.)%-15
d.)System.out.printf(”%6o”, i)
e.)System.out.printf(%10.2f)
2-a.)10,000.50
b.)45 632
c.)34.54

EX 7-5
1.)The program will halt and give an error message.
2.)The programmer embeds the call to an input method in a try-catch statement, as its name implies, this statement consists of two parts. The statement within the try clause are executed until one of them throws an exception. If that happens, an exception object is created and sent immediately to the catch clause. The code within the catch clause is then executed. Alternatively, if no statement throws an exception within the try clause, the catch clause is skipped.

Published in: on January 8, 2008 at 1:49 pm  Leave a Comment  

Chapter 6 Exercise 2, 3, 4, 5, 6, 7

EX 6-11.) P Q ! ((P // Q) && (P && Q))T T FFT FF TFT F TF F T T2-a.) Trueb.) Falsec.) Trued.) False4.) ! > && > //5.) if (min <= x && x<= max)System.out.println(“x is within the min and the max.”) EX 6-21-a.) If the number is bigger than 0,action 1 will work, if the number is smaller than 0, action 2 will work.b.) If the number is bigger than 0 and smaller than 100, action 1 will work. If the number is smaller than 0 or bigger than 100, action 2 will work.2.) Every line in a program is executes at least once, but is not the same thing as testing all possible logical paths through the program, this would provide a more thorough test, and also might require considerably more test data.3.) Equivalence Class is all the sets of test data that exercise a program in the same manner.EX-when the employee type is 1, test data for the payroll program fall into just two equivalence classes: hours between 0 and 40 and hours greater than 40.4.) Boundary Conditions are a value at which two equivalence classes meet.EX-when the employee type is 1, the hourly rate will be 10 and the hours worked will be 39, 40, and 41.5.) Extreme Conditions are data at limits of validity.EX-when the employee type is 1, the hourly rate will be 10 and the hours worked will be 0 and 168.6.) EX 6-3 1.) P: Time is before noon Q: It’s Monday Action TakenTT Take the computer science quizT F Go to gym classF T Go to gym class F F Throw a frisbee in the quad2.) A nested if statement used within another selection statement, a multiway statement is nested selection in which additional if-else statement are used in the else opinion.EX 6-41.) (income > 20000) need to change to (income > 20000 && income 50000)2.) if (income > 10000)rate = 0.10;else if (income > 20000 && income 50000)rate = 0.40;elserate = 0.0;EX 6-51-a.) Output will be 2, 3, run for three times which is 2,3 2,3 2,3  b.) out put will be 1,2,3 1,2,3 1,2,3 run for three times.EX 6-61.-a) To test the number, we must test number that is bigger than 0, for example 1, 2, 3. But if the number is smaller than 0, the test is wrong.b.) Test the number that is bigger than 0 and smaller than 100, fro example, 1, 2, 3, 99, 98, 97. The number that is bigger than 100 or smaller than 0 will not be the test number.2.) 3.) When a loop that does not executes a fixed number of times, it’s test data should be cover all three possibilities.4.) A program that tolerates errors in user inputs and recovers gracefully is robust program. EX- EX  6-71-a.) b.) 2.) 3.) 

Published in: on November 28, 2007 at 3:39 pm  Leave a Comment  
Follow

Get every new post delivered to your Inbox.