CS F213

You might also like

Download as pdf
Download as pdf
You are on page 1of 8
Birla Institute of ee Science, Pilani - K.K. Birla Goa Campus partment of CS-IS First Semester, 2015-16 CS F213 Object Oriented Programming 24.09.2015 Time: 10:30 AM - 11:30 AM Test - | (Closed Book) Max. Marks: 60 instructions 1. Start each answer on a new page and answer alll parts of a question at one place. 2. Write legibly for complete credit. Clearly state all your assumptions. 3. Make an index on the back side of the front page of the main answer sheet. Food outlets on Campus: A Case Study ‘As community member of the BITS Goa campus, you must have gone to various food outlets available on cam- pus. Some of the available food outlets on the campus are: Food King, Mess, Persian Court, Institute Cafeteria, Ice n Spice, Monginis, and Gajalakshmi Snacks. You have been given the task of developing software to man- age the regular activities at each of the restuarants. Not wanting to repeat the development task many times ‘over, you chose to adopt an object oriented software development process to complete the development. One of your team members, a business analyst, went around the campus to observe the typical activities and Participants at each of these eateries. The analyst gave the following summary. ‘A few places of interest in each of the eateries are: Store this is where alll the ingredients and finished items are kept for overnight storage. Display display section holds items on display cum sale, Some stores like Monginis can only sell items that are on display. Seating plan each food outlet may have a seating plan. customer may or may not occupy a seat. If all seats are full and the customer wants to sit, customer will be turned away. A ew roles that are enacted in the eateries are: Cooking team one or more cooks help prepare items given on order; item preparation can be very elaborate (Tandoori chicken) or none (veg putt in Monginis). Serving team collects order from customer, gives it to cooking team if need be; Once the item is ready, delivers it to the customer. Sometimes customers ask for take aways and home deliveries. Once the customer is finished, the responsible service team member will present the bill and collect money from customer. Sometimes, it is possible to collect the money at the time of ordering (ex: Mess). Delivery team responsible for deliverying telephone orders to the customers’ premises. Some eateris may not provide remote delivery facility, Cleanup team responsible for keeping the premises clean. Cashier responsible for collecting money; sometimes part of service team, especially in a scenario where the cash is paid before the order is fulfilled. Customer orders the food and some times may have to pay the bill ahead of the service. Sometimes a group ‘of customers come to the eatery, but usually a single bill is presented and paid for by the group collectively. The service team and cashier do not keep track of the group members except to accommodate the group in the available seating capacity. The only restriction is that if the group can't be accommodated in the eatery, then the group should not be allowed to order / pay for any on-premises eating. The group can still give a take away type of order. All the above mentioned roles except for customer may be played by one or more employees. Based on context, an employee can take on more than one role simultaneously. ‘A few other items of interest are: Bill bill generated either at the time of ordering or after the service is complete. Order consists of list of items the customer has asked for. More items can be added to the order while the customer is being serviced. Finally the order gets billed and customer pays the bill. The software must keep track of the status of an order. The order can be in one of the following stages: new order, take away, additions, billed, paid, serviced, completed. When a customer orders food item(s), a new order is created. During the course of the service, if the customer wants more items, the existing order is augumented (new items added to existing order). If an order is paid typically before its serviced, then order augumentation is prohibited. Once the customer completes his order and service team finishes the service, order is billed. Customer verifies the bill and pays the bill after which we can say that the order is paid for. An order once its’ fulfilled attains a serviced status. If a customer leaves the premises or the food package is delivered to customer, the order attains a completed status, In case of a telephone order, the order and delivery address are taken from the customer. The food items of the order are prepared, packed and sent for delivery through the delivery team. At the customer premises, the delivery team member delivers the order, collects the money and then comes back to deposit the money with the cashier. The above description is incomplete. You can fill the gaps in description based on your experiences at the above mentioned eateries. Using the given case study, answer the questions Q1 to Q4. 1. Write a use case for the "order and take away a birthday cake in Monginis". (10M) 2. Draw the CRG cards of classes that would help fulfill the use case given in Qt. (15M) 8. Consider the given package diagram. Identify the object model concepts that are applicable at each of the numbered locations. (14M) Delivery [FdeliverOrdersi) fist serve mui Jaustomers simuterecusly Toute - Stringll ‘computeOptimaiRoute() : String TT) ‘> CashHandler FgiveChangeiBil bill) : Change }+reckonBills() |+reckonBills( Bill (1) : void 4. Draw a state diagram for the Order class. (16M) 5. (a) Draw the XP SDP lifecycle. (b) Name any six XP practices. (c) Draw the unified process model discussed in the class. Briefly mention the activities undertaken in each stage. (3M + 3M + 4M) Nye BIRLA INSTITUTE OF TECHNOLOGY & SCIENCE PILANI, K KBIRLA, GOA CAMPUS. First Semester 2015-2016 Course Title:CS F213 Object Oriented Programming Max. Marks: 60 marks ‘Component: Test II (CB) Date:30-10-2015 (10:30AM to 11.30AM) Instructions:1. Overwritten answers will not be considered for recheck. For all the questions the relevant header files are included. Papers without Name and IdNo will not be evaluated. Questions 1 to 16 are of 2-3 Marks. Write output of following programs in question 1 to 5? abstract class Bike{ Bike() { System. out printin("bike created"); } abstract void run); voidchangeGear() { System.out.printin("'gear changed"); } } class Honda extends Bike{ void run() { System.out.printin("running safely.."); } 3 class Test{ public static void main(String args[]){ Bike obj = new Honda(); obj.runQ); obj.changeGear; } I What keyword is required to run following code: class MotorBike { abstract void run(); } B.public class test { public static void main(String argsf]) { ing: > 1) its} catch(ArithmeticException €) { Sy stem.out printin(0); ih catch(ArrayindexOutOfBoundsException e) { ‘System.out.printin(1); } catch(Exception e) { System.out printin(2); } finally { System.out-printin(3); } ‘System. out println(4); } } 4.public class test { public static void main(String args{]) { String 1 = "abo"; String s2 = new String("abe"); iffs1 = 52) { ‘System.out.printin(1); } else System. out.printin(2);} if(s1 equals(s2)){ System. out.printin(3);} elsef System.out.printIn(4);} } } S.try{ intx=0; inty=5/x;} catch (Exception e) { System. out printin("Exception is caught"); } catch (ArithmeticE:xception ae) { System.out printin(" AE is caught"); } System.out.printin("I'm finished"); 6. Which of the three keywords are valid when preceding the keyword int in the following code? publicinterface MyTest{ int TEST= 1000;} (a) public (b) private (©) protected (d) abstract (e) static ® final 7. Which of the following lines of code would NOT compile if placed on the commented line? public interface printMe{ /* insert code here */} (a) public static final int id = 10; (b) public final id = 10; (c) public final static int id = 10; (d) public static final int = 10; (e) public static id = (f) public static final id; 8.Name the access modifier which when used with a method, makes it available to all the classes in the same package and to all the subclasses of the class. 9, Name the collection interface used to represent collections that maintain unique elements. 10. Given the following Java code, what would be the result of compiling and running the class? public class myWorld { public static void main(String args(]) { Iongabe = 99; int x = 100; boolean flag = true; booleanonSwitch = false; if (!flag) { System.out print(flag); } if (onSwitch) { System.out.print(onSwitch); } if (abe< x) { System.out.print(“less"); } else { System.out print("more"); } tt (a) The console would print trueless (b) The console would print falseless (c) The console would print truemore (d) The console would print falsemore (e) The code would not compile (6) The code would compile but not run 11.The name of Collection interface used to represent elements in a sequence (in a particular order) is___(@)Collection __(b)Set_ (c)List_ (4) Map 12. Assume that class A extends class B, which extends class C. All the three classes implement the method test(). How can a method in a class A invoke the test() method defined in class C (without creating a new instance of class ©), Select the one correct answer. (a) test(); (b) super.test(); (©) super.super.test0; (@) stest0; (©) Ctest0; (£) It is not possible to invoke test() method defined in C from a method in A. 13.Which of these statements are true? Select the two correct answers. (a) For each try block there must be at least one catch block defined. (b) A try block may be followed by any number of finally blocks. (©) A try block must be followed by at least one finally or catch block. (@) If both catch and finally blocks are defined, catch block must precede the finally block. 14, Which of the following are valid constructors within a class Test. Select the two correct answers. (a) test() { } (b) Test() { } (©) void Testo { } (@) private final Test) { } (©) abstract Test() { } (O Test(Test t) { } 15, Programmatically in Java, how would you express the fact that a cup sometimes has coffee in it? (#9 public class Cup extends Coffee{ } \ public class Coffe extends Cup { } (©) public class Cup { Coffee coffee;} (@ public class Coffee { Cup cup; } 16. For question 8, write the meaning of above options (a),(b),(c),(d) in one line. 17.public class MyTreeMap{ publie static void main(String a{]){ (Create a TreeMap "tm" with Key as Emp] object and /Nalue as alphanumeric Employee Id.TreeMap "tm" uses /SalaryCompComparator(2M), tm= i7a.@M) | Ri naan / Insert following entries in TreeMap "tm" in given order // Empl : Name :John, Salary: 10 and Emplld : El; // Empl2 : Name ‘Mary, Salary: 80 and Emplld : E2; 7b.) Geta set OF entTes "CS" TreeMap Set es = [I'7¢.(1M) J/Get an ite a jes“ Iterator itr= [17d.(1M) /MDisplay elements of “tm , [i7e.(4M) //Complete the definition ofSalaryComp class which ‘implements Comparator for Empl class by overriding /eompared. ‘/compare() function should insert entries in TreeMap "ts" in /fincreasing order of salary [4M] class SalaryComp [17%,M) { [t7¢.(3M) } class Empl { private String name; private int salary; public Empl(String n, int s){.name = n; salary public intgetSalary() {return salary;} public voidsetSalary int salary) {salary = salary;} public String toStringQ{return "Name: "+name+" Salary: "+.salary;}} 18. Answer following question behind this page (Max 100 Words) (Each 5 Marks) a. When is a method said to be overloaded and when is a method said to be overridden? Explain with example. b. What is the difference between final, finally and finalize() in Java? Explain with example code, Explain up casting vs. down casting with suitable example? 17g 1 i 3 4 5 7 8 9 10 2 13, 14 15 16b 16 16d a 17b i7e 17e 17d 17f Birla Institute of re Rercgs & Science, Pilani - K.K. Birla Goa Campus epartment of CS-IS First Semester, 2015-16 CS F213 Object Oriented Programming 03.12.2015 Time: 2:00 PM - 5:00 PM Comprehensive Exam (Closed Book) Max. Marks: 90 Instructions is a self-contained question paper; Use main answer booklet for rough work. 2. Write answers in the allocated space; No additional sheet shall be provided 3, Write the steps clearly for complete credit. Clearly state all your assumptions. 4. Answers written with pencil shall not be accepted for recheck. 1D No= Name: Recheck Request: 1. Class Diagram a 5M) Draw a class diagram with appropriate attributes (operations need not be shown) for the credit card system outlined below. Clearly show the multiplicity and qualifiers, if any of each association. AAn institution may issue many credit card accounts, each identified by an account number. Each account has a maximum credit limit, a current balance, and a mailing address. The account serves one or more customers who reside at a mailing address. The institution periodically issues a statement for each account. The statement lists a payment due date, finance charge, and minimum payment. The statement itemizes various transactions that have occured throughout the billing interval: cash advances, interest charges, purchases, fees, and adjustments to the account. The name of the merchant is printed for each purchase. Provide answer on the backsi of this sheet 2. Sequence Diagram a OM) In modeling a course of a university, lets say that you decided to put course feedback collection process in feed- back() method of Course class. The method ends up using studentRep, students, and forms objects. ARC acts as a Static class with a useful method named feedbackDeposit(). Both students (a collection) and studentRep are objects of type Student. interesting methods of Student class are: emptyForm(),filForm() and filledForm(). Only studentRep object can issue empty forms and collect filled forms. student objects take empty form ft studentRep, fil the form and return the filled form to studentRep again. studentRep waits for return of filled for from all students and then deposits the filled forms in ARC. Draw a sequence diagram for the work done in feedback() method. Provic ron ksi 3. Objects and Interfaces Correct the mistakes in the given Java code. Provide your answers in the space given below. from rms (am) @) public interface Sonethinglswrong { void aMethod(int aValue) { System.out.printin( "Ht Mom"); | + + B) public class Somethinglewrong 1 public static void main(String{] args) { Rectangle myRect; nyRect.width = 40; nyRect height = 50; System.out.println("myRect’s area is ” + myRect.area()); 4. Objects (3 x 2M = 6M) Identify the following statements as TRUE/FALSE. Circle the appropriate answer for each question. (a) Java downcasts automatically, but you must explicitly upcast. (vr) (b) The rules for upcasting and downcasting depend upon whether classes are declared public, protected, or private. (TF) (6) As the foString() method is defined in the Object class, System.outprintin can be used to print any object. (TF) 5. Local Classes and Exceptions (10M) Write code in the identified locations (a), (b), (c) and (d) to print the required output. Each method can't have more than one print statement. abstract class Musician { abstract public void createRaga(); protected void recite(){ System. out.printIn("Mustcsan:Rectte”) ; } public void concert (){ createRaga(); recite(); } se Ma) class AdaptableMusician { private String genre; public AdaptableMusician(String genre){ this.genre public void createMusic() ______(b)--->,. genre; } Mc)-~-> + public atatic void main(String(] args) _ (a)--->. AdaptableMusician salim = new AdaptableMusician( Classical”); salim.createMusic(); AdaptableMusician coltrane = new AdaptableMusician("Joz2"); coltrane. createMusic(); Hany other music genre results in "UnSupportedGenre” eaception AdaptableMusician elvis = new AdaptableMusician("Rock"); elvis.createMusic(); ye output: Classical anonymous: Experimental, Create Raga, Recite Jazz anonymous: Create Quartet, Recite Eaception in thread "main" UnSupportedGenre at AdaptableMusician.createMusic .... 7 Provide answer on the backside of this sheet 6. Collections (10m) Draw the class diagrams of HashMap, ArrayList classes, and Listlterator interface. Clearly show alll the appropriate methods. Provide answer on the backside of this sheet 7. Generics + Inner classes (20M) Write Java code to satisty the given class diagram; next() method of ReverseArraytterator must throw No- SuchElementException exception if the stack is empty; remove() method of ReverseArrayiterator must always throw UnsupportedOperationException exception. fang Fl ee ir Saintertaces> [— a Iterable +hasNext( : boolean Henext() : E +remove() : void [Fiterator() : Rerator Fa: item{) LN: int [ReverseArrayiterator [+FixedCapacktyStack(capacity = int) Fi: int = NT }+isEmpty() : boolean pushtitem : item) : void pop) : Item +iterator() : Iterator Provide answer on the backside of this sheet 8. Concurrency (5M-Bonus) Write Java code to protect the operation of pop() method using Lock. Similarly, protect the operation of push() method using synchronized, . ‘pop() method: push() method: 9. Concurrency (15M) Consider the JumbleNames.java program given in the next sheet. The task is to print firstName, makes the thread sleep for delay time period, and then prints secondName in an inf le loop. The task must handle any interrupts received by the thread. Upon receiving an interrupt, the task must come out of infinite loop and finish its work. Create three threads to drive three tasks, namely JumbleNames\ JumbleNames("Krishna ", “Devaraya ", 300L), and new JumbleNam« “Chandi ‘James pta", "Maurya", 200L), ‘Carse", 500L). Auport java.io. 10Exception; public class JumbleNanes implements Runnable { private String firetNane,secondNane private long delay; public JumbleNames (String firstName, String secondName, long delay) { thie.firetlame = firstNane; this.secondifame = secondNane; this.delay = delay; 2 public void run() { //éefine the task W(a)---> ; public static void main(String{] args) { /fereate three threads to drive three tasks 11 ()~=-> //set threads in daemon mode MMe---> //start the threads Wa)---> System.out.printin("Press Enter uhen you have had enough...\n"); //try-catch block waiting for any key press to end the main try { System. in.read(); Systen.out.printin( "Enter pressed...\n"); } catch (IOException e) { Systen.err.printin(e); } System.out.printin( "Ending main()"); return; + ? Provide answer on the backside of this sheet 10. Concurrency (8M-Bonu Ignoring the daemon status requirement of pari-(c) of question #9, rewrite parts-(b) and (d) using Executors. Make sure you use the cached thread pool option and provide for graceful shutdown.

You might also like