// Class used to hold a list of Strings interpreted as web site addresses. public class URLList {

Similar documents
CS 134 Midterm Fall 2009

CS 134 Midterm Solutions Fall 2009

CS 134 Midterm Fall 2006

CS 134 Midterm Solutions Spring 2013

Lab 5 TOC to Me. Class Structure. IM Client Implementation --- Part 2 Due: 23:00 Monday 13 October. CS 150, Profs. Lawson and Szajda Fall 2008

CS 134 Midterm Spring 2013

A set, collection, group, or configuration containing members regarded as having certain attributes or traits in common.

CS 134 Midterm Fall 2006

Lab 5 TOC to Me. IM Client Implementation --- Part 2

Lab 5 Classy Chat. XMPP Client Implementation --- Part 2 Due Oct. 19 at 11PM

Probing Questions. Chapter Accessor Methods

Final Examination --- SAMPLE SOLUTIONS May

Final Examination May

Programming Project. Remember the Titans

Postfix Notation is a notation in which the operator follows its operands in the expression (e.g ).

CS 209 Spring, 2006 Lab 8: GUI Development Instructor: J.G. Neal

Midterm Programming Project Encryption for IM Client

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

Assignment3 CS206 Intro to Data Structures Fall Part 1 (50 pts) due: October 13, :59pm Part 2 (150 pts) due: October 20, :59pm

You Can Make a Difference! Due April 11/12 (Implementation plans due in class on 4/9)

DEMYSTIFYING PROGRAMMING: CHAPTER SIX METHODS (TOC DETAILED) CHAPTER SIX: METHODS 1

Assignment 5. Introduction

Documenting Advanced Programming Techniques

CIS 120 Midterm II November 8, 2013 SOLUTIONS

Chapter 4 Defining Classes I

Object-Oriented Design Lecture 3 CSU 370 Fall 2007 (Pucella) Friday, Sep 14, 2007

Page 1 of 7. public class EmployeeAryAppletEx extends JApplet

16 Multiple Inheritance and Extending ADTs

CIS 120 Midterm II November 8, Name (printed): Pennkey (login id):

CS171 Midterm Exam. October 29, Name:

3.Constructors and Destructors. Develop cpp program to implement constructor and destructor.

CS 3114 Data Structures and Algorithms READ THIS NOW!

CSIS 10B Lab 2 Bags and Stacks

Computing Science 114 Solutions to Midterm Examination Tuesday October 19, In Questions 1 20, Circle EXACTLY ONE choice as the best answer

CS 151. Linked Lists, Recursively Implemented. Wednesday, October 3, 12

CS 3360 Design and Implementation of Programming Languages. Exam 1

CMSC 150 Lab 8, Part II: Little PhotoShop of Horrors, Part Deux 10 Nov 2015

Midterm Test II Object Oriented Programming in Java Computer Science, University of Windsor Fall 2014 Time 2 hours. Answer all questions

Overview. Lecture 7: Inheritance and GUIs. Inheritance. Example 9/30/2008

Due: 9 February 2017 at 1159pm (2359, Pacific Standard Time)

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

CMSC131. Inheritance. Object. When we talked about Object, I mentioned that all Java classes are "built" on top of that.

Model answers/marking scheme in bold, additional comments in bold italic.

Graphics User Defined Forms, Part I

Birkbeck (University of London) Software and Programming 1 In-class Test Mar 2018

ECE 4450:427/527 - Computer Networks Spring 2017

All code must follow best practices. Part (but not all) of this is adhering to the following guidelines:

Guessing Game with Objects

Networking Technologies and Applications

Software Testing Prof. Meenakshi D Souza Department of Computer Science and Engineering International Institute of Information Technology, Bangalore

College of Computer and Information Sciences Department of Computer Engineering CEN444 Computer Networks Midterm 2 Exam Second Semester 1434/1435

AP Computer Science Chapter 10 Implementing and Using Classes Study Guide

PROGRAMMING FUNDAMENTALS

Fall 2017 Mentoring 9: October 23, Min-Heapify This. Level order, bubbling up. Level order, bubbling down. Reverse level order, bubbling up

Definition of DJ (Diminished Java)

CSCI 1301: Introduction to Computing and Programming

CS 314 Exam 2 Spring

Tips from the experts: How to waste a lot of time on this assignment

Multiple Access Protocols

CMP 326 Midterm Fall 2015

Introduction to Software Development (ISD) Week 3

Assignment 4 Publication date: 27/12/2015 Submission date: 17/01/ :59 People in-charge: R. Mairon and Y. Twitto

Queues. CITS2200 Data Structures and Algorithms. Topic 5

Ethernet. Introduction. CSE 3213 Fall 2011

Java Programming Lecture 7

ext Total Score /20 /20 /15 /20 /25 /5 Grader

Switched LANs A Set of Local Area Networks Interconnected by Switches

King Fahd University of Petroleum and Minerals College of Computer Sciences and Engineering Department of Computer Engineering

Boolean Expressions and if 9/14/2007

CSCI Lab 9 Implementing and Using a Binary Search Tree (BST)

SINGLE EVENT HANDLING

Programming Problems 22nd Annual Computer Science Programming Contest

Chapter 13 Lab Advanced GUI Applications

First Name: AITI 2004: Exam 2 July 19, 2004

Networking. Melissa Winstanley

Subclassing for ADTs Implementation

CS 1316 Exam 1 Summer 2009

Discrete Structures Lecture 14

FINALTERM EXAMINATION Fall 2009 CS301- Data Structures Question No: 1 ( Marks: 1 ) - Please choose one The data of the problem is of 2GB and the hard

Collections, Maps and Generics

INCORPORATING ADVANCED PROGRAMMING TECHNIQUES IN THE COMPUTER INFORMATION SYSTEMS CURRICULUM

Table of Contents Date(s) Title/Topic Page #s. Chapter 4: Writing Classes 4.1 Objects Revisited

Final Examination Semester 3 / Year 2008

COMP19612 exam performance feedback 2014

LAN PROTOCOLS. Beulah A AP/CSE

Points Missed on Page page 1 of 8

12/22/11. Java How to Program, 9/e. public must be stored in a file that has the same name as the class and ends with the.java file-name extension.

Computer Science Engineering Sample Papers

CS 211 Programming Practicum Fall 2018

CSE 143 SAMPLE MIDTERM

l Determine if a number is odd or even l Determine if a number/character is in a range - 1 to 10 (inclusive) - between a and z (inclusive)

Data Link Layer, Part 3 Medium Access Control. Preface

Defining Your Own Classes

CS 2505 Computer Organization I

ECE 4450:427/527 - Computer Networks Spring 2017

Part 3. Why do we need both of them? The object-oriented programming paradigm (OOP) Two kinds of object. Important Special Kinds of Member Function

CS/ENGRD 2110 SPRING Lecture 7: Interfaces and Abstract Classes

String Theory. Chapter Cut and Paste

Introduction to Computer Science II (ITI 1121) Midterm Examination

Networks Homework # 2

Transcription:

Question 1. The analysis of Ethernet performance in the paper by Metcalfe and Boggs makes the simplifying assumption that each computer will transmit during a given slot with probability 1 N where N is the number of stations trying to transmit. In reality, we know that the probability that a station will transmit depends on the number of collisions it has experienced rather than on N. If a computer has experienced K collisions, it chooses a random delay value from the set {0, 1S, 2S,..., (2 K 1)S. Therefore, the probability it transmits in any given slot is 1. 2 K Metcalfe and Boggs make this simplifying assumption in order to obtain a formula that approximates the expected number of slots that will be wasted either by being left idle or because a collision occurs during the slot. Any formula for the expected number of wasted slots that accurately reflects the actual dynamics of the exponential backoff algorithm would be extremely complicated. To appreciate this, we would like you to determine a formula for the expected number of slots that would be wasted in a single round of a very specific collision resolution scenario. Suppose that two computers, A and B, attempt to transmit simultaneously on an idle Ethernet. The process of collision resolution in which they will participate can be divided into rounds. In round 0, both stations transmit immediately and collide. In round 1, they both randomly choose a delay from the set {0, S and transmit after this delay. In this round, the probability of a collision is 1 2. If they collide again in round 1, then they engage in another round (round 2) in which they choose delays from the set {0, S, 2S, 3S. The total number of slots wasted during this process will be the sum of the slots wasted in each round. It is obvious that the maximum number of slots wasted in round K is 2 K. The actual number of slots wasted in a given round, however, depends on the random delays selected. For example, in round 1, there are four equally likely outcomes. Station A may choose delay 0 while station B chooses S. In this case, A will immediately transmit successfully and no slots will be wasted.. Similarly, if B chooses delay 0 and A chooses S, no slots will be wasted. On the other hand, if both A and B choose 0, they will both transmit immediately and collide. After this collision, they will both move on to round 2 immediately, so round 1 will only waste 1 slot. On the other hand, if the both choose a delay of S, one slot will be wasted by being left idle and another slot will be wasted due to collision. To compute the expected number of slots wasted in round 1, we simply sum the number of slots wasted in each of the four possible outcomes time the probability of each outcome ( 1 4 ) to obtain: 0 1 4 + 0 1 4 + 1 1 4 + 2 1 4 = 3 4 That is, the expected number of slots that will be wasted during round 1 will be 3 4. Assuming that A and B do collide during round 1 and move on to round 2, determine the expected number of slots that will be wasted during round 2. Justify your answer. Question 2. The code for most of the URLList class we discussed in class is shown below. // Class used to hold a list of Strings interpreted as web site addresses. public class URLList { private boolean isempty = false; // true if nothing in list private String firstsite; // The first web site in the list private URLList restofsites; // The rest of the list of web sites // Create an empty list public URLList( ) { isempty = true; // Create a larger list from a new website and an existing list public URLList( String newsite, URLList existinglist ) { firstsite = newsite; restofsites = existinglist; 1

// determines whether the collection contains a given entry public boolean contains( String site ) { if ( isempty ) { else if ( firstsite.equals( site ) ) { return true; else { return restofsites.contains( site );... // a few other methods we do not care about in this question... For this question, we want you to consider several alternative definitions for contains that might have been used in this class. For each alternative, indicate whether it would i) work fine, ii) work, but not as efficiently as the original, iii) compile but not work correctly, or iv) not even compile. Briefly explain your answer. Hint: Although URLList is certainly an example of a recursive class, dont panic. This question is more about if statements than about recursive classes. a) public boolean contains( String site ) { if ( firstsite.equals( site ) ) { return true; else if ( isempty ) { else { return restofsites.contains( site ); b) public boolean contains( String site ) { if ( isempty ) { else if (! restofsites.contains( site ) ) { return firstsite.equals( site ); else { return true; c) public boolean contains( String site ) { return!isempty && ( firstsite.equals(site) restofsites.contains(site) ); d) public boolean contains( String site ) { if ( isempty ) { else if (! firstsite.equals( site ) ) { return restofsites.contains( site ); Question 3. On the following two pages, you will find definitions of two classes that could be used in the Java IM clients you constructed in labs 4 and 5. The first is a definition of a ChatWindow class. It should look very similar 2

to what you used in lab. The second class is named TOCSendIMPacket. It is not quite complete. It is missing the declarations of its instance variables, local variables, and formal parameters. For this problem, we want you to add the missing declarations. We have placed shaded bubbles at all the points in the code where the missing declarations could go. You will not need to fill in all of the bubbles we have provided, but you should not need to place declarations anywhere outside these bubbles. Each name should be declared as locally as possible. That is, if the program would work if a given name was declared either as a local variable or an instance variable, then you should declare it as a local variable. The names for which declarations must be provided are: destination buddysname message messageinhtml lesspos greaterpos original updated You should be able to complete this problem without fully understanding what the classes do, but to help you out, we provide the following explanation. The TOCSendIMPacket constructor expects parameter values that specify the essential details required to send an IM message, the screen name of the person the message should be sent to and the text of the message. The tostring method associated with the class then returns the packet that should be sent to the AOL server. That is, if you created a TOCSendIMPacket by saying packet = new TOCSendIMPacket( thommurtagh, Hi Tom ); you could later sent the appropriate text to the server by saying toserver.out.printpacket( packet.tostring() ); Real IM clients encode the messages they send in HTML. The programs you created in lab did not do this. The TOCSendIMPacket fixes this by adding some simple HTML to the messages being sent. It adds html body to the beginning of each message and /body /html to the end. In addition, if any less than signs were included as part of the original message, they are replaced by the characters HTML uses to encode less than signs, <. Similarly, any greater than signs are replaced by >. As a result, if you created a TOCSendIMPacket by saying packet = new TOCSendIMPacket( thommurtagh, Hi >Tom< ); and then later said String text = packet.tostring(); the variable text would be associated with the String: toc2_send_im thommurtagh <html><body>hi >Tom<</body></html> 3

import TOCtools.*; import squint.*; import javax.swing.*; public class ChatWindow extends GUIManager { private final int WINDOW_WIDTH = 550, WINDOW_HEIGHT = 350; // Dimensions of GUI components for text private final int TEXT_WIDTH = 40; private final int TEXT_AREA_HEIGHT = 15; // Area used to display IM messages (and other messages send by server) private JTextArea dialogue = new JTextArea( TEXT_AREA_HEIGHT, TEXT_WIDTH ); // The connection to the server private FLAPConnection toaol; // Field used to enter messages private JTextField message = new JTextField( TEXT_WIDTH - 10 ); // Buddy s name private String buddy; // User s name private String user; // Create a new chat window public ChatWindow(String screenname, String buddyname, FLAPConnection connection ) { this.createwindow( WINDOW_WIDTH, WINDOW_HEIGHT, buddyname ); buddy = buddyname; user = screenname; toaol = connection; dialogue.seteditable( false ); contentpane.add( new JScrollPane( dialogue ) ); contentpane.add( new JLabel( "Message: " ) ); contentpane.add( message ); // Send a message to the window s buddy public void textentered( ) { TOCServerPacket packet; dialogue.append( user + ": " + message.gettext() + "\n" ); packet = new TOCSendIMPacket( buddy, message.gettext() ); toaol.sendflapdata( packet.tostring() ); // Display a message received from the buddy public void messagereceived( String message ) { dialogue.append( buddy + ": " + message + "\n" ); 4

public class TOCSendIMPacket { // Create a new packet public TOCSendIMPacket( ) { destination = buddysname; messageinhtml = addhtml( message ); // Return the packet in text form public String tostring( ) { return "toc2_send_im " + destination + " \"" + messageinhtml + "\""; // Place HTML tags around the message body and replace and < and > in the orignal // message with the HTML sequences used to encode them ( < and >). private String addhtml( ) { // Look for the first < and > signs lesspos = original.indexof( "<" ); greaterpos = original.indexof( ">" ); updated = ""; while ( lesspos!= -1 greaterpos!= -1 ) { // Replace the first < or > found if ( lesspos!= -1 && (lesspos<greaterpos greaterpos == -1) ) { // a < was found before any > updated = updated + original.substring(0, lesspos ) + "<"; original = original.substring( lesspos + 1 ); else { // a > was found before any < updated = updated + original.substring(0, greaterpos ) + ">"; original = original.substring( greaterpos + 1 ); // Look for the first remaining < and > signs lesspos = original.indexof( "<" ); greaterpos = original.indexof( ">" ); // Add the tags to indicate the beginning and end of the HTML for the message return "<html><body>" + updated + original + "</html></body>"; 5

6