for the equality test for M and N. The question concerns how to represent multisets of strings
Question:
for the equality test for M and N. The question concerns how to represent multisets of strings within ML. For each of the given data representations (a), (b) and (c) describe how you would implement occs, mplus and mequal. If possible, incorporate simple efficiency improvements. In each case state the approximate running time of occs(x, M), mplus(M, N) and mequal(M, N) using O-notation. (a) Represent multisets using lists of strings, for example {a, b, a}m by [a, b, a]. (b) Represent multisets by lists of pairs of the form (x, k), for example {a, b, a}m by [(a, 2),(b, 1)]. (c) Represent multisets using binary trees. Compare the representations (a), (b) and (c), stating the advantages and drawbacks of each. [Answers need not contain ML code. You may refer to algorithms and data structures from the notes Problem Solving in ML.] SECTION D 10 What is an operating system kernel, and what runtime services does an executable binary program expect from a typical time-sharing kernel? How may transfer of control (program flow) between the loaded application and the resident kernel be achieved? 5 [TURN OVER CST.93.2.6 11 Describe and compare the following two programming approaches: (a) execution of a compiled and linked set of modules; (b) using an interpreter. Include examples of each, showing when one method is preferable to the other. Is there an absolute distinction between the two methods or is there a spectrum of approaches? 12 Outline the data protection principles set down in the Data Protection Act, and discuss the possible justifications for them.
Compare the purely graphical properties of these two notations, and the ways in which the graphical properties of each display correspond to the information structure being defined. Describe three ways in which the graphical correspondences are different. [2 marks each] (b) What analytic approach could be used to compare the usability implications that arise from considerations such as those in part (a)? [1 mark] (c) On the basis of the approach in part (b), suggest three specific usability issues relevant to the design of programming environments, in each case contrasting the implications for programming in UML and Java. [3 marks each] (d) Describe an empirical approach that could be used to evaluate the usability of a new environment, with respect to one or more of the issues identified in part (c). Consider both the collection and analysis of data. [4 marks] 6 CST.2011.7.7 8 Mobile and Sensor Systems Consider a vehicular network where cars are equipped with a Wi-Fi radio (802.11) interface. Assume a number of Wi-Fi basestations scattered around an area. The basestations provide only very sparse coverage of the area, but are connected to the Internet through a backbone network. (a) Explain what effects the mobility of the vehicles can have on communication. In particular, describe short- and long-term fading effects. [3 marks] (b) Illustrate the essential aspects of the MAC layer of 802.11. [3 marks] (c) Consider RTS and CTS packets used in 802.11. Describe what problem they solve and indicate where this approach is incomplete] (d) Assume that information about traffic needs to be disseminated from the basestations to all vehicles. Explain what routing protocol(s) would be suitable for a vehicular scenario like the one described (do not consider GPSR): justify your selection and the trade-offs of your choices. [6 marks] (e) Now assume that vehicles collect traffic information (such as their speed and position) and want to forward this information to a server. Also assume that nodes adopt GPSR to route messages geographically to the closest basestation (position known). Explain how GPSR can be used for this purpose and under what conditions it would not work.
(a) A key/value store holds pairs of strings in a non-volatile memory (NVM). The NVM is mapped as a memory region between two hardcoded virtual addresses, NV START and NV END. This memory is all set to zero as manufactured and can be freely read, but any write operations result in a logical ORing of the new data with the old data at the addressed location. Bits can never be cleared. Strings representing keys and values will be fewer than 250 characters long. Eventually the memory will fill up, but sufficient is available for the intended application. The API provides the following two operations: int store(char *key, char *value) // returns non-zero on error, and char *lookup(char *key) // returns NULL if not found. Provide a full C implementation of the store routine, explaining how the lookup function and changes to values under a given key would work, if this is not obvious from your code. Code efficiency is not important. Hint: You can directly access the non-volatile store using a construct such as ((char *)NV_START)[offset]. [10 marks] (b) The following text almost constitutes both a C++ and Java program: class Foo { public: int x, y; }; class Test { private: void f1(Foo p) { p.x = 1; } private: void f2(Foo &q) { q.y = 2; } //[Java]: ignore '&' public: void test() { Foo p; //[Java]: replace with: 'Foo p = new Foo();' p.x = p.y = 99; f1(p); Foo q = p; p = q; f2(q); print("HERE"); } }; (i) Explain the storage structure accessible from variables x and y when control reaches print("HERE") following a call to test(), both in the Java and the C++ interpretations. [3 marks] (ii) For the C++ interpretation, show how adjustments only to the definition of class Foo can cause (useful) debugging-style output to be produced at as many places as possible during the execution of method test(). [7 mark
(a) ButtonCanvas could be built using multiple inheritance. What does this mean in this context? [2 marks] (b) Give two reasons why this might be desirable. [2 marks] (c) Give two complexities that arise in this case. [2 marks] (d) Java interfaces originally contained only abstract methods and static final fields. How did this restriction avoid the complexities of extending multiple classes? [3 marks] (e) Draw a UML diagram for building ButtonCanvas using abstract interfaces rather than multiple inheritance. Explain how your design attempts to preserve the desirable properties arising from multiple inheritance. You do not need to recall the exact UML specification, instead you may provide a key explaining your notation. [9 marks] (f ) Recent versions of Java added default methods to interfaces. What is the impact of this with respect to multiple inheritanc
(a) Describe the differences between primitive types and objects in Java. Consider: (i) the values they contain [1 mark] (ii) where they are stored in memory [1 mark] (iii) how they interact with Java references [1 mark] (b) What are auto-boxing and auto-unboxing? Give an example of how they might cause an exception to be thrown. [4 marks] (c) Consider the following code in which any arbitrary Java type (primitive or object) could be substituted for T. void f(T t) { /* ... */ } T t1 = /* ... */ f(t1); For which substitutions of T can we guarantee that the value in t1 is unchanged after the invocation of f(t1)? Justify your answer. [3 marks] (d) Explain how Java's implementation of generics precludes substituting T with a primitive type. [2 marks] (e) You are asked to redesign the standard library to incorporate an immutable list. Explain the relative merits of: (i) MutableList being a subtype of ImmutableList [2 marks] (ii) ImmutableList being a subtype of MutableList [2 marks] (iii) ImmutableList and MutableList having no common supertype [2 marks] (iv) ImmutableList and MutableList both subtyping CommonList [2 marks]
(a) You are given the following implementation for an element of a list: class Element { int item; Element next; Element(int item, Element next) { super(); this.item = item; this.next = next; } @Override public String toString() { return item + " " + (next == null ? "" : next); } } (i) What does the statement super() mean? [1 mark] (ii) What is the meaning of this in the line this.item = item? [1 mark] (iii) What is the purpose of the annotation @Override? [2 marks] (iv) Rewrite the class to be immutable. You may assume that there are no sub-classes of Element. [2 marks] (b) Use the immutable Element class to provide an implementation of an immutable class FuncList which behaves like an int list in ML. Your class should include a constructor for an empty list and methods head, tail and cons based on the following functions in ML. Ensure that your class behaves appropriately when the list is empty. [6 marks] fun head x::_ = x; fun cons (x,xs) = x::xs; fun tail _::xs = xs; (c) Another developer changes your implementation to a generic class FuncList that can hold values of any type T. (i) This means that FuncList is no longer immutable. Explain why and what could be done to remedy this. [2 marks] (ii) Java prohibits covariance of generic types. Is this restriction necessary in this case? Explain why with an example
(a) What is an object? [2 marks] (b) Give four examples of how object-oriented programming helps with the development of large software projects and explain why each one is helpful. [8 marks] (c) Explain the meaning of the Open-Closed principle. [2 marks] (d) Draw a UML diagram for a design satisfying the Open-Closed principle and explain why it satisfies it. [8 marks]
(a) Explain why it is bad practice for member variables such as x to be public. [2 marks] (b) For each of the lines 6-12, explain its purpose. Illustrate your answer with examples. [7 marks] (c) What could result from a call to c.equals(null), assuming c is a reference to a Child object? [3 marks] (d) What would be the consequences of replacing the equals signature with public boolean equals(Child obj)? [4 marks] (e) Explain why Child should also override the hashCode() method. [4 marks
I need your help with my questions below. I am a beginner at Java programming, so I don't know how I can do the following steps and add them to my code: http://sendanywhe.re/P7BV706M. I am stuck on them.
So I need your help with the following questions below.
If you can give detail feedback on each of my questions and help me solve them.
It will be really appreciable.
Required:
Newest IntelliJ IDEA Community Edition with default settings
Question Number 1: How do I design this part below in GitHub and IntelliJ?
Update the @authors fields in Main.java to have full names; Build project and check that math game works correctly; Select whole project, then use VCS / Commit... to commit changes into the local GIT repository. This will bring up a dialog box that allows to select which changes want to add into GIT index and then commit into GIT repository. Make sure Main.java file is ticked, so it will be added; Enter a useful Commit message Click the Commit button (just a simple Commit at this stage, not Commit and Push...). If IntelliJ reports errors in code, should cancel the commit and fix them. If it reports warnings, can review them and fix some if like, but then go ahead with the Commit; Now go to GitHub repository in browser and refresh the page to see if that Commit has been copied up to GitHub? should find that it has NOT been pushed up to GitHub yet - commit has been added to local GIT repository (in the .git folder inside project), but has not been pushed yet; Use IntelliJ menu: VCS / Git / Push... to push all the recent commits up to the GitHub servers; Refresh the browser again and should now see commit changes appear on GitHub.
Question Number 2: How do I implement this part in Intellij?
The Java code inside the main() method is getting too long. It is time to start breaking up that code into objects, and use object-oriented programming.
So in this section, Will be adding Question objects to the program, and then changing the main method (in Main.java) so that it cooperates with those Question objects and gets them to do most of the work of the game.
This will make our main method smaller and easier to understand. It also opens up more possibilities for reuse of our code and objects:
Could reuse these Question objects in other quiz programs in the future; or Could reuse them together with a different kind of Main program such as a Graphical User Interface (GUI). This process of restructuring our program to make it cleaner and more reusable is called refactoring.
Question Number 3: How do I implement this part in Intellij?
Want to design a new type of object: each Question object will represent one math question. For example, one question like "3 + 11 = 14". This question object will have to know the input values (3 and 11) and the operator (plus) of the question, as well as the expected answer (14). Should be able to ask a Question object to do things like:
prints itself as a quiz question (without showing the answer!); check to see if a student answer is correct or not; [maybe?] print a message saying what the correct answer was?
There are lots of possible ways could design the Question class, some good, some not so good. Below is a UML class diagram of one possible design, which should be a reasonably good design for our math game.
Note: there are two different constructors shown in this class diagram:
The lower-level constructor takes the input values and operator as arguments. This makes the constructor easy to write, but requires more work from the client code (the code that calls the constructor) to generate all those values. The higher-level constructor takes just a random number generator and uses that to generate all the values it needs. This makes the constructor a bit harder to write, but makes the client code easier.
Implement both, and compare them.
Question
-value1 : int
-value2 : int
-operator : String
-answer : int
+showQuestion() // to System.out
+checkAnswer(int response) : bool
+Question(v1:int, v2:int, op:String)
+Question(rand : Random)
Now should implement this Question class in the program, and then use it to generate all the question objects that need in the game. Here are the steps to design this Question class:
In IntelliJ, right-click on the package where want to add the Question class and do: New / Java Class. Type in Question as the name of the class, and then create it. Inside new class, add the four data fields shown above. For example: private int value1; Add the showQuestion() method. This has no return type, so it's type will be void. The '+' in the UML class diagram means it is public, so will need: public void showQuestion() { }. Then fill in the code inside that method, so that it prints the question out to System.out, with a question mark on the end. Add the constructor (whichever one 've chosen). This must also be public, will have no return type (because it always returns a new Question object), and its name must be Question. The input parameters will be the parameters shown in the UML class diagram, but will have to translate that UML notation into Java variable declarations (type, then variable name). The job of the constructor is to initialise all the data fields. As a temporary first version of code inside the constructor, suggest just set them to fixed values, like this: value1 = 3; value2 = 5; etc.
. Write program to print all alphabets from a to z. - using while loop a program to read data using CL register and check whether it's positive or negative.
Now comes the exciting bit: using new objects!
Go into Main class, in the main(...) method, and see where are generating the question inputs. Just after that point, add a line like the following one to design a new Question object (the '???' parameters will be different, depending upon which constructor 've chosen to use): Question q1 = new Question( ??? );
q1.showQuestion();
Run game to see what it does now. It probably prints the question twice? Once because the q1 object is printing the question, and once because old code in main() is also printing the question. So, should now be able to delete the lines of old code that print the question. Run the program again to make sure only print the question once. Time to fix up that temporary constructor inside the Question class. Edit the code inside the constructor so that it sets up the data fields with the correct values - either the values given as parameters, or by using the rand object to generate the values it needs. Now try to call the checkAnswer(response) method of r q1 object. Design this just after have read the response from the child playing the game. Ah, will have to implement the checkAnswer method inside Question class before can call it! I suggest that make that method responsible for checking the response against the correct answer, and also printing either a message to congratulate them on getting the correct answer, or to commiserate with them for getting the wrong answer. Run program again and see what it does. should be able to remove even more code from r main method now, since all the answer checking is done inside the Question.checkAnswer method.
Can extend main method a bit more so that it keeps track of the score? Each time a Question is answered correctly, the score should be incremented by one.
Hint: to know when to increment this score, could save the result of the checkAnswer(...) call into a variable called good, and then add a Java if statement to increment r score only when good is true.
Question Number 4: How do I implement this part in Intellij?
So far, the game only does additions, and maybe subtractions, which is a bit boring. Now extend it so that we get a random mix of addition, subtraction multiplication, and division questions.
There is less guidance in this section, so more room for to problem solve when hit issues. Here are some general guidelines:
should use new Question objects for all these kinds of questions; The code for choosing (randomly) between different kinds of questions could go inside r Question constructor if are using the constructor with the Random generator parameter, or inside main method if are using the other Question constructor with just integer and String values. An easy way of choosing between the four different kinds of questions is to use Random number generator to generate an integer from 0..3 as follows, and then decide that 0 means addition, 1 means subtraction, 2 means multiplication, and 3 means division.