Chapter 9, 9.7

1. What are two-dimesional arrays?

– One array with each element is defined by two numbers.

2. Describe an application in which a two-dimensional array might be used.

– To create a table with numerator and denominator.

3.

– for (row=0; row < table.length; row ++)

for (col = 0; table[row]. length; col++)

if (table[row][col] <0)

break;
4. Describe the contents of the array after the following code segment is run:

– It creates a five by five table and assign a value of the product of rows and colums into each spot.

Chapter 9, 9.6

1. What are parallel arrays?– They are arrays that contains corresponding data in cells of same index. 2. Describe an application in which parallel arrays might be used.– The declaration between people’s name and their age in the school. 3. Declare an instantiate the variables for parallel arrays to track the names, ages, and social security numbers of 50 employees.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;}. 5. Write a code segment that creates parallel arrays containing the first 10 nonnegative powers of 2. One array should contain the exponent and the other array should contain 2 raised to that power.

– 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])

} ;

Chapter 9, 9.5

1. What happens when the programmer tries to access an array cell whose index is greater than or equal to its logical size? — It will give you the default value of zero, and to add another value we just need to expand the size of of the logical size. 2. Describe an application that uses an array that might not be full. — For example, create a class with 5 kids in the class and leave some spaces for upcoming students.

Chapter 9, 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.  

Chapter 9, 9.3

1. Write 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. the loop will just get the sum of all elements of the a array. 5. What is the advantage of using the instance variable length variable length in a loop in a loop with an array.  – It tells the operator precisely how many elements inside the array.

Chapter 9, 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. 

Chapter 9, 9.1

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.–  

Chapter 8, 8.9

1. Describe the simplest format of an HTML applet tag. Give an example.
— below is the HTML code:

2. How is an application converted to an applet?
— Two steps:
a. Replace the name JFrame with the name JApplet at the beginning of the class definition(extends JApplet).
b. Replace the class’s constructor by the method init:
public void init(){
statement
}

3. What can an application do that an applet cannot do ?
— Applets can’t access files on the user machine. More secure.
APPlets and the HTML documents that use them should be placed in the same directory.

4. Describe the steps required to load an image into an applet.
–a. Locate this applet’s web server and load the image.
b. Convert to an image icon for further processing.

Chapter 8, 8.8

1. Describe how you create a table using the HTML table tags.
— First specify that HTML code as table. Then make a caption on the top, then comprise column header and informations about each header below.

2. Write an HTML code segment that displays a 3*3 table with cells that are numbered as follows:
1 2 3
4 5 6
7 8 9

Chapter 8, 8.7

1. What is the difference between an inline image and an external image?
— Inline images are graphical images that are displayed when the user opens a page.

2. Write the simplest version of the format of the markup tag for an inline image.
— The simplest version of the format of the markup tag for an inline image is:

3. Write a markup tag that loads an inline image of the file image.gif, centers the image, and scales its size to 200pixels * 200 pixels.

4. What are two ways of tagging an external image? Give an example of each.
— The two ways are by displaying a text that can be clicked and get you the image. The other one is to display the smaller version of that image and by clicking it, it give you the full version of that image.
Picture

« Older entries