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,one must replace the array’s physical length with it logical size of loop.

 


 

Add comment February 25, 2008 rita1012

9.4

1. Declare and instantiate array variables for the following data:– double[] abc = new double[15]     string[] abcd = new string[20] 2. What is an initializer list? – It is another way to initialize the array, it assign the exact values to the array’s element. 3. Use an initializer list to create the following arrays:a. five test scores of 100, 90, 75, 60, and 88.    int [] aaa = {100, 90, 75, 60, 88}b. three interest rates of 0.12, 0.05, and 0.15    double[] bbb = {0.12, 0.05, 0.15}c. two strings, your first name and last name   string[] ccc = {david, chen} 4. Why is it better to use the form <type> [] <variable> instead of <type> <variable>[] when declaring an array variable. – It’s more confusing.  


 

Add comment February 19, 2008 rita1012

9.3

1. aWrite a loop that prints all of the items in an array a to the terminal screen. – int i = 0      for (i==0, i<a.length, i++)          System.out.print(a[i]) 2. Repeat Question 1 put but print the items in reverse order. – 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. Describe what the following code segments do:    a. It will change all the negative values of a to positive value by taking the absolute values of them.    b.  5. What is the advantage of using the instance variable length variable length in a loop in a loop with an array.  – 

Add comment February 14, 2008 rita1012

9.2

1. Assume that the array a contains the five integers 34, 23, 67, 89, and 12. Write the values of the following expressions:- a. 34  b. a[a.length -1] =4  c. a[2]+ a[3] = 156What happens when a program attempts to access an item at an index that is less than 0 or greater than or equal to the array’s length?– The JVM checks the values of subscripts before using them and throws an ArrayIndexOutOfBoundsException if they are out of bound. 

 

 

Add comment February 14, 2008 rita1012

9.1

 A Program needs many variables to store and process data, How does an array solve this problem?– An array can group similar data with one array that contains many elements2. How does the programmer access an item in an array?– They use the name and the index to access it.3. Mary is using an array of doubles to store an employee’s wage amounts for each day of the week(Monday through Friday). Draw a picture of this array with sample items and references to each one.–  

Add comment February 14, 2008 rita1012

Chapter 8

8.11) A hypertext is a structure consisting of nodes and the links between them. Each node is a document or chunk of text. Normally, links to other nodes are displayed  to the user as embedded, highlighted terms within  a given chunk of text. The user moves to the node by using an arrow key or mouse o select an associated term.2) Hypermedia is like hypertext, but adds GUI, Images,Sound, Animation,andApplication 3)URL is the address on the page for the World Wide Web8.21. HTML stand for Hypertext markup language2. 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>       </HTML> 4.HTML is a comment for the creator to review.It is information that only the creator could see and the browser does not interpret or show i to the reader8.31. The HTML programmer need to use forced line break because a web page author or designer wants to display several lines of test without word trap.2.We use preformatted text in an HTML document when we want the browser to display text, with line breaks, extra spaces, and tabs.8.41. 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 purpose of the escape sequence in HTML is to let the browser to display these characters rather than interpret them.8.51. the three types of HTML are:Unordered (bulleted) lists a bulleted list Numbered (ordered) can be nested within other lists to any depth,but more than three levels deep can be difficult  to readDefinition( association) displays terms and their associated definition2. 8.6  1. text in  the link 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.8.71. An inline images are graphical images that are displayed when the user opens a page. External images are not displays until the user click on a link.2. The from of the markup tag for an inline image is <IMG src=” ImageLocation”> 3. <IMG src=”mypicture.gif” HEIGHT=200 WIDTH=2004. Two ways of tagging an external image<A href=”mypicture.gif”>Sample picture</A><A href=”mypicture.gif”><IMG src=”mythumbnail.gif”></A8.9 1. An HTML document that contains an applet markup tag and a byte code file for the applet-That is, a compiled Java applet in a .class file 2. 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.                                                                                                

Add comment January 25, 2008 rita1012

Chapter 7

7.21. The key to this pseudocode is the String variable doItAgain. 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.Browse into the String class in Sun’s Java API documentation. Expain how the method toLowerCase could be used to simplify the loop control condition of the query-driven loop in the example program.–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 letter and the capital case letter.

 

7.31. The role that the menu plays is to display a list of options. so that the user can select the one that he or she needs.2. The loop first display a range of options to choose from. After choosing a direction, the program then proceed into a loop. After the loop run through, it display another menu that user can choose whether to stay in that loop or to terminate it. In some program, there may be multiple loops. 3. Public class Various toppings {Public static void main (String [ ] args) {  Scanner reader = new Scanner (System.in); String menu; int menu Option; menu = “\n1)mushrooms “                      + ”\n2) peppers”              +”\n3) sausages”             +”\n4) Quit”            +”\Enter your option of the toppings you want: “;menu option = 5;while (menu Option ! = 4){      system.out.print(menu);      menuOption = reader. nextInt ();     System.out.println(” “);if (menuOption == 1){System.out.println(“Mushroom “);}else if (menuOption ==2)System.out.println(“peppers”);}else if (menuOption == 3)System.out.println(“sausage”);}else if ( menu Option ==4)System.print ln(“Goodbye! “);elseSystem.out.println(“Invalid Option”);    7.4 1. a.” One space” “%11s”b.” Two spaces” “%12s”c.”Three spaces ” “%-15″d.The value of int variable i, right-justified in a field of six columns: System.out.printf(”%6o”, i)e.The value of double variable d, right-justified in a field of 10 columns with a precision of 2: System.out.printf(%10.2f) 2a. String.format(”%-10s%,10.2f”, “Price”, 10000.50)Price 10,000.50b. String.format(”%6d%7d”, 45, 632) 45 632c. String.format(”%5.2f”, 34.543)34.547.51.The program will halt and give an error message.   2. The programmer embeds the call to an input method in a try-catch statement. The statements within the try clause are executed until one of them throws an exception.Alternatively, If no statements throws an exception.If that happens, an exception object is created and sent immediately to the catch clause. the code within the the try clause, the catch clause is skipped. 3.Double x;while (continue.equals(”y”)|| continue.equals(”Y”)){while (true)try{System.out.print(”Enter a well-formed double value: “);x= reader.nextDouble();break;}catch(Exception e){System.out.println(”Error in number format!”);reader.nextLine();}System.out.println(x);}

Add comment January 8, 2008 rita1012

6.6

1a) I would test the number 1, 0, -1    #  1 should work because it agrees with the code segment   # 0 and -1 should not work because it does not agrees with the code segmentb)  i would test the # 1,0,-1 and # 101,100,99   the # 1, and 99 should work because it agree with the code segmentthe 0. -1, 101,and 100 should not work because it does not agree with the code segment2. the test data that should be use are  # 2, 0, and -2 for the growth rate , the # of hours it takes to achieve that rate and # of hours during that the population grows. 3. the reasonable test date for a loop that does not exclude a fixed number of times is any number that is less than or equal to 0, which mean  negative #s and 0.  4. Robust Program is a program that tolerates errors in user inputs and recover gracefully. ex) the best way to use a robust program is to check user inputs immediately on entry and reject those that are invalid.   

Add comment December 5, 2007 rita1012

6.5

1. a) out puts will be 2,3 run for three times which is 23 23 23     b) out puts will be  1,2,3 , 1,2,3 ,1,2,3 run for three times  2.     a.Output the numbers 1 to 25 in consecutive order, using five rows of five numbers each.- for(i=1, i<=5, i++)for(j=1, j<=25, j++)System.out.print(k + “”)System.out.println(””)

Add comment November 30, 2007 rita1012

6.4

1. it should be grater than equal or less than and equal2. if (income > 10000)rate =0.10;else if (income > 20000 && income <= 50000)rate=0.18;else if (income >  50000)rate = 0.40;elserate =0.0;     

Add comment November 30, 2007 rita1012

Previous Posts Next Posts

Pages

Categories

Links

Meta

Calendar

November 2009
M T W T F S S
« May    
 1
2345678
9101112131415
16171819202122
23242526272829
30  

Most Recent Posts