Lab # 7 Part I. Experiment. (20%) (There is no Lab7Experiment on the web.) For this lab…

Lab # 7

Part I. Experiment. (20%) (There is no Lab7Experiment on the web.)

For this lab experiment you are given several code segments that illustrate some of the new concepts discussed in Chapter 8. You should first "hand-run" the code and then double check your accuracy and understanding by checking output using System.out.println. Answer each of the following questions by providing the output generated. If there is an error in the code that prevents it from compiling or executing to completion explain the error.

1. Give the output generated by the following code segment. If the code does not execute, explain why.

?int sum = 0;?int i = 10;?

?do?

?{?

?if (i % 2 == 0)?

?{?

?sum += i;??

?System.out.println("i = "+i+" sum = "+sum);?

?}?

?i–;?

?}?

?while (i > 0);

2. Give the output generated by the following code segment. If the code does not execute, explain why.

?int sum = 0;?

?for (int i = 1; i

?{?

?int j;?

?for (j = 1; j

?{?

?sum += i+j;?

?System.out.println("i, j, & sum = "+i+" "+j+" "+sum);?

?}?

?}

3. a) How would execution change if a ";" was placed immediately after the boolean expression of the inner loop of the code given for question # 2? Give the output generated.

?for (j = 1; j

b) How would execution change if the declaration of j was removed from its current location and placed inside the for loop header and the modification in part 3 a) was made? Explain.

?int sum = 0;?

?for (int i = 1; i

?{?

?for (int j = 1; j

?{?

?sum += i+j;?

?System.out.println("i, j, & sum = "+i+" "+j+" "+sum);?

?}?

?}

4. a) Give the output generated by the following code segment.

?double values [] = {62, 85, 55, 68, 45, 70};?

?int i = 0, count = 0;?

?final int CUTOFF = 60;?

?while (i

?{?

?if(values[i] >= CUTOFF)?

?count++;?

?i++;?

?}?

?System.out.println("count = "+count);

b) Modify the code as shown and explain the output (or error). (You should save all your work first!)

?double values [] = {62, 85, 55, 68, 45, 70};?

?int i = 0, count = 0;?

?final int CUTOFF = 60;?

?while (i

?{?

?if(values[i] >= CUTOFF)?

?{?

?count++;?

?i++;?

?}?

?}?

?System.out.println("count = "+count);

c) Modify the code as shown and explain the output (or error).

?double values [] = {62, 85, 55, 68, 45, 70};?

?int i = 0, count = 0;?

?final int CUTOFF = 60;?

?while (i

?{?

?if(values[i] >= CUTOFF)?

?count++;?

?i++;?

?}?

?System.out.println("count = "+count);

5. Give the output generated by the following code segment.

?int [] num = new int [6];?

?JTextField tf [] = {new JTextField("62",3), new JTextField("80",3), new JTextField("55",3),

?new JTextField("69",3), new JTextField("81",3), new JTextField("46",3)};?

?int sum = 0;

?double avg;?

?for (int i=0; i

?{?

?num[i] = Integer.parseInt(tf[i].getText().trim());?

?sum += num[i];?

?}?

?avg = (double)sum/num.length;??

?for (int i=0; i

?if (num[i] > avg)?

?System.out.println("num at position "+i+" is > "+avg);?

?else?

?System.out.println("num at position "+i+" is

Part II. Programming. (80%)

For thisassignment using arrays and for loopsyou willdevelop and applet to create your own selection of paintings from the collection we provide you.Again you will use the MVC approach but now with an extra class PaintingInfo, where you will store the information of the paintings you like from the MMA collection. Once in the database you will be able to display, sort and delete them.Thefourclassesneeded for this Lab are:Lab7.java(the Controller) Lab7View.java ( the View) Lab7Model.java ( the Model) &PaintingInfo.java ( where you store your selected paintings ). To help you in your development we give you the starting code for thesefourclasses,study them and use them as your starting code.

The information for thepaintings/painters/files and yearis provided by the followingString[]andint[]arrays, the images are also provided in the attached zip file, you can use them using the properfor orswitchjava statement.These arrays are already given in Lab7 java classes we include for this homework.

String[] paintingsMMA = { "SelectaPainting","Portrait of a Man Holding Gloves",

?"Self-Portrait","Herman Doomer","Nini in the Garden",

?"Young Girl in a Pink-and-Black Hat","A Young Girl with Daisies",

?"A Forest at Dawn with a Deer Hunt","Venus and Adonis",

?"Wolf and Fox Hunt","First Steps, after Millet","Self-Portrait with a Straw Hat",

?"Wheat Field with Cypresses","Camille Monet on a Garden Bench","Bridge over a Pond of Water Lilies",

?"Rouen Cathedral","Seated Peasant","Mont Sainte-Victoire and the Viaduct","The Gulf of Marseilles",

?"Henri-Gabriel Ibels","The Englishman","Madame Thadee Natanson","Three Miracles of Saint Zenobius","Madonna and Child with Two Angels",

?"The Last Communion of Saint Jerome","Wooded Upland Landscape","Mrs. Grace Dalrymple Elliott","Captain George K. H. Coussmaker",

?"The Vision of Saint John","View of Toledo","Christ Healing the Blind","Mother and Child","Young Mother Sewing",

?"Portrait of a Young Girl","George Washington","Horatio Gates","Captain John Gell"};

String[] paintersMMA = {" ","Rembrandt","Rembrandt", "Rembrandt","Renoir","Renoir", "Renoir",

? "Rubens","Rubens", "Rubens","Van Gogh","Van Gogh","Van Gogh","Monet","Monet","Monet",

? "Cezanne","Cezanne","Cezanne","Toulouse-Lautrec","Toulouse-Lautrec","Toulouse-Lautrec",

? "Botticelli","Botticelli","Botticelli","Gainsborough","Gainsborough","Gainsborough",

? "El Greco","El Greco","El Greco","Mary Cassatt","Mary Cassatt","Mary Cassatt","Gilbert Stuart","Gilbert Stuart","Gilbert Stuart" };

String[] filesMMA = {"0MMA.jpg","1a.jpg","1b.jpg", "1c.jpg","2a.jpg","2b.jpg", "2c.jpg", "3a.jpg","3b.jpg", "3c.jpg","4a.jpg","4b.jpg","4c.jpg","5a.jpg",

? "5b.jpg","5c.jpg","6a.jpg","6b.jpg","6c.jpg","7a.jpg","7b.jpg","7c.jpg","8a.jpg","8b.jpg","8c.jpg","9a.jpg","9b.jpg","9c.jpg", "10a.jpg",

? "10b.jpg","10c.jpg","11b.jpg","11c.jpg","11a.jpg", "12a.jpg","12b.jpg","12c.jpg"

? };

int[] yearMMA = {0,1648, 1660,1640,1876,1891,1889,1635, 1630,1616,1890, 1887,1889,1873, 1899, 1894, 1892,1882,1885,1892,1892,1895,1500,

? 1505,1490,1783,1778,1782,1609,1598,1570,1899,1914, 1900,1795,1793,1785};

Specifically the functionality required for this lab is given below:1)The ability to create aselecteddatabase of paintings based on the MMA collection2)List and sort the images selected according to name, painter or year3)Display or delete a given painting from your database

You may observe these new functions by testing my applet shown below:

Starting Lab 7

After selecting a painting

After addingitto database and listing it

After sorting by year

Select a painting in database

Deleting a painting

Displaying a painting

 

Looking for a Similar Assignment? Hire our Top Uk Tutors while you enjoy your free time! All papers are written from scratch and are 100% Original. Try us today! Active Discount Code FREE15