Prov på delkurs Objekt-orienterad Programmering



Relevanta dokument
Recitation 4. 2-D arrays. Exceptions

Denna vecka. Idag. Grafiskt användarsnitt. Vi kommer att se


Webbregistrering pa kurs och termin

Support Manual HoistLocatel Electronic Locks

Workplan Food. Spring term 2016 Year 7. Name:

12.6 Heat equation, Wave equation

Make a speech. How to make the perfect speech. söndag 6 oktober 13

Writing with context. Att skriva med sammanhang

1. Compute the following matrix: (2 p) 2. Compute the determinant of the following matrix: (2 p)

Preschool Kindergarten

6 th Grade English October 6-10, 2014

Module 1: Functions, Limits, Continuity

Kungliga Tekniska Högskolan Ämneskod 2D4134 Nada Tentamensdag aug - 23 Tentamen i Objektorientering och Java Skrivtid 5 h

ITK:P1 Lektion 4. Lektion 4. Lektion 4. Att implementera en spelidé i Java. DSV Peter Mozelius

Webbreg öppen: 26/ /

Materialplanering och styrning på grundnivå. 7,5 högskolepoäng

Chapter 1 : Who do you think you are?

Isometries of the plane

Information technology Open Document Format for Office Applications (OpenDocument) v1.0 (ISO/IEC 26300:2006, IDT) SWEDISH STANDARDS INSTITUTE

Boiler with heatpump / Värmepumpsberedare

Vad kännetecknar en god klass. Vad kännetecknar en god klass. F12 Nested & Inner Classes

Beijer Electronics AB 2000, MA00336A,

Schenker Privpak AB Telefon VAT Nr. SE Schenker ABs ansvarsbestämmelser, identiska med Box 905 Faxnr Säte: Borås

1. Varje bevissteg ska motiveras formellt (informella bevis ger 0 poang)

DVG C01 TENTAMEN I PROGRAMSPRÅK PROGRAMMING LANGUAGES EXAMINATION :15-13: 15

Blueprint Den här planeringen skapades med Blueprints gratisversion - vänligen uppgradera nu. Engelska, La06 - Kursöversikt, 2015/2016.

Tentamen FYTA11 Javaprogrammering

Schenker Privpak AB Telefon VAT Nr. SE Schenker ABs ansvarsbestämmelser, identiska med Box 905 Faxnr Säte: Borås

Tentamen i Matematik 2: M0030M.

PROG2 Tenta Gäller SP:PROG2, DSK2:PROG2, FK:PROG2, FK:OOP, DSV1:P2 och ITK:P2

ITK:P1 Föreläsning 4. Grafiska gränssnitt i Java. AWT-komponenter

Styrteknik: Binära tal, talsystem och koder D3:1

MVC-mönstret. model-view-control i Swing

Module 6: Integrals and applications

8 < x 1 + x 2 x 3 = 1, x 1 +2x 2 + x 4 = 0, x 1 +2x 3 + x 4 = 2. x 1 2x 12 1A är inverterbar, och bestäm i så fall dess invers.

Isolda Purchase - EDI

Lösningsförslag till tentamen FYTA11 Javaprogrammering

Java-concept och Swing. Swing low, sweet chariot

Vässa kraven och förbättra samarbetet med hjälp av Behaviour Driven Development Anna Fallqvist Eriksson

BOENDEFORMENS BETYDELSE FÖR ASYLSÖKANDES INTEGRATION Lina Sandström

27. GUI Programming. Java. Summer 2008 Instructor: Dr. Masoud Yaghini

SI-pass 4. Johan Brook och Jesper Persson. 25 september Diskutera och svara på om påståendena nedan är äkta sanningar eller listiga lögner.

FÖRBERED UNDERLAG FÖR BEDÖMNING SÅ HÄR

Lösningsförslag till tentamen

How to format the different elements of a page in the CMS :

Lösningsförslag till omtentamen för TDA540 Objektorienterad Programmering


Read Texterna består av enkla dialoger mellan två personer A och B. Pedagogen bör presentera texten så att uttalet finns med under bearbetningen.

LULEÅ TEKNISKA UNIVERSITET

Adding active and blended learning to an introductory mechanics course

Kungliga Tekniska Högskolan Ämneskod 2D4134 Nada Tentamensdag maj - 19 Tentamen i Objektorientering och Java Skrivtid 5 h

Föreläsnings 11 - GUI, Händelsestyrda program, MVC

Detta dokument är ett exempel, cirka andra hälften av en tentamen för TDA545 Objektorienterad programvaruutveckling

TDDE10 m.fl. Objektorienterad programmering i Java Föreläsning 7 Erik Nilsson, Institutionen för Datavetenskap, LiU

Pre-Test 1: M0030M - Linear Algebra.

Föreläsning 15 (16) Historik (java.awt) Historik (javax.swing) Introduktion till Swing

TDDC30. Kursledning Kursledare: Jonas Lindgren. Labassistent: Jonas Lindgren Labassistent: Niklas Holma Labassistent: Erik Nilsson

1. Unpack content of zip-file to temporary folder and double click Setup

INSTALLATION INSTRUCTIONS

Problem som kan uppkomma vid registrering av ansökan

Listen to me, please!

Schenker Privpak AB Telefon VAT Nr. SE Schenker ABs ansvarsbestämmelser, identiska med Box 905 Faxnr Säte: Borås

2.1 Installation of driver using Internet Installation of driver from disk... 3

samhälle Susanna Öhman

Grafisk teknik IMCDP IMCDP IMCDP. IMCDP(filter) Sasan Gooran (HT 2006) Assumptions:

Hur fattar samhället beslut när forskarna är oeniga?

Lösningsförslag till tentamen

Högskolan i Skövde (SK, JS) Svensk version Tentamen i matematik

Installation av F13 Bråvalla

Consumer attitudes regarding durability and labelling

Kvalitetsarbete I Landstinget i Kalmar län. 24 oktober 2007 Eva Arvidsson

Libers språklåda i engelska Grab n go lessons

Här kan du checka in. Check in here with a good conscience

c = s[2]; /* move chars around */ p = &s[2]; *p = *(p-1); --p; *p = *(p-1); s[0] = c; printf("%s\n",s); /* print the string */ English version

Objektorienterad Programkonstruktion. Föreläsning 3 9 nov 2015

Objektsamlingar i Java

Registrerade / Registered 14/05/2009. No Ordförande / The President. Wubbo de Boer REGISTRERINGSBEVIS CERTIFICATE OF REGISTRATION

Lösningar till tentamen i EDAF25

EXTERNAL ASSESSMENT SAMPLE TASKS SWEDISH BREAKTHROUGH LSPSWEB/0Y09

TDDC30. Objektorienterad programmering i Java, datastrukturer och algoritmer. Föreläsning 1 Jonas Lindgren, Institutionen för Datavetenskap, LiU

Lösenordsportalen Hosted by UNIT4 For instructions in English, see further down in this document

Föreläsning 3: Händelsestyrda program och användargränssnitt

Tentamen Programmering fortsättningskurs DIT950

VAD SKULLE DU HA VALT PDF

LARS. Ett e-bokningssystem för skoldatorer.

JAR som tar eller zip. Java. Exekvering

Examination i. PROGRAMMERINGSTEKNIK F1/TM1 TIN212 (Dugga) Dag: Onsdag Datum: Tid: (OBS 3 tim) Rum: V

Lösningsförslag till tentamen

Solowheel. Namn: Jesper Edqvist. Klass: TE14A. Datum:

Scalable Dynamic Analysis of Binary Code

EXPERT SURVEY OF THE NEWS MEDIA

Provlektion Just Stuff B Textbook Just Stuff B Workbook

Tentamen FYTA11 Javaprogrammering

Evaluation Ny Nordisk Mat II Appendix 1. Questionnaire evaluation Ny Nordisk Mat II

[HUR DU ANVÄNDER PAPP] Papp är det program som vi nyttjar för att lotta turneringar och se resultat.

Om oss DET PERFEKTA KOMPLEMENTET THE PERFECT COMPLETION 04 EN BINZ ÄR PRECIS SÅ BRA SOM DU FÖRVÄNTAR DIG A BINZ IS JUST AS GOOD AS YOU THINK 05

Chapter 4: Writing Classes/ Att skriva egna klasser.

Kursutvärderare: IT-kansliet/Christina Waller. General opinions: 1. What is your general feeling about the course? Antal svar: 17 Medelvärde: 2.

Modelsvar för Tentamen för Objektorienterad programvaruutveckling, TDA545

Transkript:

Institutionen för Datavetenskap. Lunds Universitet. Dat501: OOP, VT03 Prov på delkurs Objekt-orienterad Programmering Ordinarie tentamen 6. juni 2003 Tillåtna hjälpmedel: Litteratur, egna anteckningar Tentamen består av 3 uppgifter, varje uppgift kan ge 10 poäng. Deluppgifternas poäng anges inom [hakparenteser]. Observera att poänggivningen inte nödvändigtvis avspeglar deluppgiftens svårhetsgrad. Uppgifterna kan besvaras på svenska eller engelska. Behandla högst en uppgift per papper (det går bra att behandla deluppgifter på samma papper). Skriv bara på ena sidan och markera varje sida med dina initialer. Skriv läsligt. a)[0] Hur många uppgifter får man behandla per papper? b)[0] Får man skriva på baksidan? Det går bra att referera till kursböckerna av Schmidt, Hansen och Rischel eller Rosen. Referenser måste ha formen [S: något], [HR: något] eller [R: något], där något är ett avsnittsnummer, en kodbit, en räknad uppgift, etc. Skriv till exempel genom att använda metoden validate från [S: Figure 7 i Chapter 6]. Vill du referera till något annat, måste du ange bokens titel, författere, och förlag. Skriv till exempel genom att använda metoden validate från [Barry Cornelius: Understanding Java, Addison Wesley 2001, p. 254]. Ibland hänger vissa uppgifter ihop. Observera att det går bra att referera till svaret på tidigare uppgifter, även om du inte har löst dem. 1

Exercise 1 (10 points total) Consider the following simple Swing application: The user types some text into the JTextArea on the left and presses the Find JButton. This will locate the letter A in the text, as in the following example: Here is the Java code for this application. import java.awt.*; import java.awt.event.*; import javax.swing.*; public class FindLetterFrame extends JFrame implements ActionListener { JTextField input_text; JButton find_button; JLabel found_text; public FindLetterFrame() { input_text= new JTextField("Type your text here"); find_button= new JButton("Find"); find_button.addactionlistener(this); found_text= new JLabel("No A found"); Container c= getcontentpane(); c.setlayout(new FlowLayout()); c.add(input_text); c.add(find_button); c.add(found_text); pack(); setvisible(true); public void actionperformed(actionevent e) { String S= input_text.gettext(); int pos= S.indexOf( A ); found_text.settext("position of A: "+pos); public static void main(string[] args) { new FindLetterFrame(); 2

a)[2] Whenever the input text does not contain an A the label should read No A found. Change the code to achieve this. We will change this application to follow the MCV paradigm. First we introduce a model to do the searching for us. The model will know about the character to be searched for ( A in our example above, but it should be able to search for other characters instead). The specification is the following: public class SearcherModel Constructor: public SearcherModel(char c) Methods: public int search(string s) b)[1] Implement SearcherModel. Sets the searched-for character Returns the position of the character in the string s, or -1 if the character doesn t appear c)[2] Change FindLetterFrame so as to use a new SearcherModel( A ) as its model. d)[2] Now separate the controller by extending the JButton. e)[2] Write a class diagram of your application. Currently our application does case-sensitive searching (i.e., it treats A and a as different characters). We now what a second button (called Switch ) that switches between case-sensitve and case-insensitive searching. So after pressing the Switch button once, the application now treats A and a as the same letter, no matter how many new texts are entered, or how often the Find button is used. Pressing the Switch button again reverts to the original meaning. 1 f)[2] Add the Switch button to your application and make the necessary changes. It is important that the information about which of the two searching states we are in (case-sensitive or case-insensitive) is kept in the model, not in the controller or the view. Note: To avoid writing a lot of code it is fine to use three-dots notation to quote the original code, instead of copying the corresponding lines of code by hand. For example: input_text=...... // as in FindLetterFrame... new FlowLayout()); 1 Please don t use a JToggleButton just to show how cool you are, even if that probably would produce a nicer user interface 3

Exercise 2 (10 points total) Here is a function that is supposed to compute 2 x on input x: /** Computes two-to-the-power of a given number. * @param x 1 an integer * @return 2 x. */ 1. static int raise(int x) 2. { int i=1; 3. { int r=2; 4. while (i x) 5. // loop invariant: r = 2 i 6. { loop body 7. return r; 8. a)[2] Write the loop body so that it satisfies the invariant (you don t have to prove that). b)[2] Assuming that the loop body satisfies the invariant, prove that raise is partially correct. 2 c)[1] Change raise so that it works with the (weaker) condition that x is an integer with x 0. The integer logarithm base two of x is defined so to be the integer y satisfying 2 y x < 2 y+1. For example, 3 is the integer logarithm of 8, and also of 10. (You can view this function as y = log 2 x if that makes it clearer for you.) Consider the following function /** Computes the integer logarithm of a given number. * @param x a positive integer 1 * @return log 2 x. */ 1. static int ilog(int x) 2. { int y= 1; 3. while (raise(y) < x) 4. y= y+1; 5. return y; 6. d)[1] (Very easy) Find the integer logarithm of 4 and of 5. e)[4] (Harder) Prove that ilog is partially correct (this includes fining a valid invariant), and explain briefly why it terminates. 2 Note that this exercise doesn t ask you to prove that the loop body satisfies the invariant. Please don t waste time doing that. 4

Exercise 3 (5 points total) Consider the following declarations: public interface Animal { public String speak(); public class Dog implements Animal { public Dog() { public String speak() { return "Grrr!"; public void eat() { public class Poodle extends Dog { public Poodle() { public String speak() { return "Vof!"; a)[2] Which of the following subtyping relations are correct? (i) Dog<=Animal, (ii) Poodle<=Animal, (iii) Dog<=Poodle, (iv) Animal<=Poodle b)[2] Some of the following statements won t be accepted by the compiler. Rewrite them as necessary and briefly mention why they were wrong. Animal x= new Dog(); x.speak(); x.eat(); Dog y= x; y.eat(); if (x instanceof Dog) { x.eat(); Now consider the following statements: Dog x= new Dog(); Dog y= new Poodle(); Poodle z= new Poodle(); System.out.println(x.speak()); System.out.println(y.speak()); System.out.println(z.speak()); c)[1] What output is generated by these statements? 5

Exercise 4 (5 points total) Here is a (somewhat silly) class for Strings: public class SillyString { public char first; public SillyString rest; public SillyString(char c, SillyString S) { first= c; rest= S; For example, the String Hi can is created by new SillyString( H, new SillyString( i,null)) a)[1] Create the SillyStrings corresponding to the strings Gnu and the empty string. b)[2] Add a method public int length() to SillyString that returns the number of characters of this SillyString. c)[2] Add a method public void removex() to SillyString that changes this SillyString by removing all occurences of the capital letter X. 6