辅导案例-COMPS311F

欢迎使用51辅导,51作业君孵化低价透明的学长辅导平台,服务保持优质,平均费用压低50%以上! 51fudao.top
COMPS311F – Online Exam (Sample)
xx May 2020
Time Allowed: 2.5 hours (9:30 - 12:00)
Instructions:
- You should attempt ALL questions of the paper within the prescribed time.
- The total mark is worth 100 marks.
- Accept minor syntax errors.
- No need to include import statements.
- No need to handle exception except the questions are on exception or used as part of the
program logic.
- Submit a report containing answers to ALL the required questions. Your report must include
all the Java programs. Your report should be stored in a Word format (.doc or .docx).
Answers not included in your document file will not be marked.
- Put your name and student number on every page of your report.
- Name the document file in the format of COMPS311F-Exam-SXXXXXXX.doc (or .docx),
where XXXXXXX is your ID.
- Submit the document file to the “Take-home Exam” on the OLE (DO NOT put it in the
“Discussion Board”).
o
o “Multiple submission” is NOT allowed. It means that you can only submit your
answer file to the system once.
o You are strongly advised to try out the Trial Take-home Examination to familiarize
yourself with the submission process before the exam.
- You should click the “Save & Submit” button after your document file has been uploaded.
o
- Without specification, the submitted version on the “Take-home Exam” of the OLE will be
used for marking.
- Zero mark will be given for those who complete the submission after the prescribed time.
- Open book examination rules are applied. You are only allowed to use the internet to access
the OLE and the relevant Java API. You will be disqualified if you access to any shared
drives or social networking websites. Also, according to the regulation, cheating is
prohibited, includes but is not limited to “aiding or attempting to aid another candidate, or
obtaining or attempting to obtain aid from another candidate”.
Page 2 of 9
Question 1 [5 marks]
State whether each of the followings is true or false about Java:
(a) A protected method in a class cannot be overridden in a subclass.
(b) All variables are reference variables.
(c) A private attribute cannot be accessed anywhere.
(d) All methods must have at least one return statement.
(e) When a thread has successfully invoked a synchronized method of an object, no other
threads can invoke any of the methods of the object at the same time.
[5]
Question 2 [6 marks]
Write a class for a simple game. The game starts with generating two random integers. Then
the first who can give the sum of the two integers wins.
The class looks like this:
public class Game {
.....
public Game() {...}
syncrhonized public int[] getNumber() {...}
synchronized public boolean answer(int i) {...}
}
The constructor is to generate two random integers between 0 and 100 inclusive. The
getNumber method is for a player to get the two numbers. If someone has already given the
correct answer, then null will be returned. The answer method is used by a player to give
the answer. It will return true if no one else has provided the true answer and the answer
provided by the player is correct.
[6]
Question 3 [5 marks]
Write a program CountIntegers to read a number of files that contain only integers. The
integers have been written to the files using writeInt of DataOutputStream. You need
to use a separate thread to read in one file. Then, you need to write out the number of integers in
each file in ascending order.
For example, after executing the command:
java CountIntegers file1 file2 file3
May generate the output:
file3 has 256 integers
file2 has 345 integers
file1 has 1024 integers
Note that you need a data structure to store the numbers of integers in the files. The thread
which finished last is responsible for sorting and outputting the result.
[5]
Page 3 of 9
Question 4 [6 marks]
(a) In a static scoping language, when a subprogram encounters a non-local variable, where should
this be found?
[1]
(b) Consider the following Pascal code:
program A;
var a1:integer;
procedure E; forward;
procedure B;
var b1:integer;
procedure C;
var c1: integer;
begin {C begins}
......
end; {C ends}
procedure D;
var d1:integer;
begin {D begins}
......
end; {D ends}
begin {B begins}
......
end; {B ends}
procedure E;
var e1:integer;
begin {E begins}
......
end; {E ends}
begin {A begins}
......
end. {A ends}
Write the ARI records in the stack when the following procedure calls are made:
- Program A calls procedure B
- Procedure B calls procedure D
- Procedure D calls procedure E
- Procedure E calls procedure B
[5]
Question 5 [5 marks]
Write a Java class which models some online resources. The resources can only be used by at
most three users at a time. The resources are represented as the Java class Resource which has
been defined elsewhere. Now, you need to implement the class that control the use of the
resource:
Page 4 of 9
public class ControlResources {
private Resource resources[]=new Resource[3]; // the three
instances of resource
...
synchronized public Resource get(boolean waitToGet) {.....}
synchronized public void returnResource(Resource res) {....}
}
The get() is invoked by a user who wants to get a resource. It accepts a boolean parameter. If
the parameter is true, then the user will wait if at the moment no resource is available. If the
parameter is false, then the user does not want to wait. In this case, if there is no available
resource, the method will just return null. The returnResource() method is used for a
user to return a resource to the ControlResources object. You can assume that only those
users who have got a resource from the object will call this method to return it.
[5]
Question 6 [5 marks]
A database contains information regarding students and courses studied in a university.
Student (Information of students)
Attribute Data type
Name varchar(50)
StudentID varchar(10)
Address varchar(100)
Study (Study records of students)
Attribute Data type
StudentID varchar(10)
CourseID varchar(10)
Grade varchar(2)
Course (Information of courses)
Attribute Data type
CourseID varchar(10)
Title varchar(50)
Complete the following JSP that displays the student who failed a particular course (Grade F).
The id of the course should have been passed as the parameter named courseid.
<%
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://192.168.62.100:3306/2014exam";
Connection con = DriverManager.getConnection(url,
"comps311f3", "comps311f3");
%>



Course records


<%
Page 5 of 9
// Add code here
%>



The following example shows the content when the request URL is:
http://plbpc001.ouhk.edu.hk/jsp/get.jsp?courseid=comps311
Only 3 students have failed this course. The title of the course is “Java Application
Development”.
[5]
Question 7 [5 marks]
(a) List one advantage and one disadvantage of passing parameters by value.
[2]
(b) Consider the following C like code:
#include
int a=3;
int b=4;
void fun(int x, int y) {
a=2*x;
x=y/2;
y=a;
}
void main() {
fun(b,b);
printf("%d %d\n",a,b);
}
What is the output of the program if the parameter passing method is:
(i) Pass-by-value.
(ii) Pass-by-value-result.
(iii) Pass by reference.
[3]
Page 6 of 9
Question 8 [6 marks]
Consider the following xml file:


The Big Love
David Au
Park Kiu


Calculus
Ma Ko


In each , there are a number of s. can be empty. In ,
there must be one and at least one <author>. </br>Write down the XML Schema for this XML file. </br>[6] </br>Question 9 [6 marks] </br>(a) Describe the difference between the reserved words "throw" and "throws" in Java. </br>[2] </br>(b) Rewrite the following method without using any boolean expression. (Hint: use try-catch </br>blocks to handle any exception.) </br>static public int set(int a[], int i) { </br> if (i>=0 && i<a.length) { </br> a[i]=i*2; </br> return a[i]; </br> } </br> else { </br> return 0; </br> } </br>} </br>[4] </br>Question 10 [6 marks] </br>State the problem in each of the following Java code fragments. </br>(a) </br>... </br>switch (a) { </br> case 0: i=4; </br> case 1: i=5; </br>Page 7 of 9 </br>} </br>... </br>(b) </br>... </br>int a[]=new int[10]; </br>for (int i=1;i<=10;i++) { </br> a[i]=...; </br> ... </br>} </br>... </br>(c) </br>public class ABC extends DEF1, DEF2 { </br> int a=3; </br> public ABC() {...} </br>} </br>(d) </br>public class ABC extends DEF1 { </br> int a=3; </br> public DEF1() {...} </br>} </br>(e) </br>abstract public class ABC { </br> int a=3; </br> abstract public ABC(); </br> ... </br>} </br>(f) </br>abstract public class ABC { </br> abstract int a; </br> public ABC() {...} </br>} </br>[6] </br>Question 11 [15 marks] </br>(a) Consider the following code that has syntax similar to C: </br>int a[5][4][4][4]; </br>a[3][3][1][3]=3; </br>a[1][2][3][1]=4; </br>a[4][0][1][1]=5; </br>a[2][3][2][3]=6; </br>Given that an int has a size of 4 bytes. Assume that a[0][0][0][0] is at the address of </br>2000. Find the address of </br>(i) a[3][3][1][3] if row major is used. </br>(ii) a[1][2][3][1] if row major is used. </br>(iii) a[4][0][1][1] if column major is used. </br>(iv) a[1][2][1][2] if column major is used. </br>Page 8 of 9 </br>[4] </br>(b) Write a multithreaded Java server which is used to handle public voting: </br>- It listens to requests at port 12345. </br>- The system allows 100 users to cast a vote on an issue. </br>- When a client request arrives at the port, a new thread is created to serve it. </br>- The server then send a string using the writeUTF method of DataOutputStream </br>to the client depending on the number of received votes: </br>o If already 100 votes have been received, then the string to be sent to the client </br>is "The vote has ended, xx people say yes, yy people </br>say no." Then the connection will be closed. xx and yy are the number of </br>yes votes and no votes respectively. </br>o Otherwise, the string to be sent is: "Please cast your vote which </br>should be either yes or no." Then the client should either send in </br>"yes" or "no" using the writeUTF method. The server should then register </br>the vote and close the connection. </br>You can assume that all users behave normally and do not need to handle exceptional cases. </br>[Hint, you should make sure your server is thread safe.] </br>[11] </br>Question 12 [15 marks] </br>(a) Compare the readability, writability and reliability of two languages A and B in the following </br>aspects: </br>(i) </br>In A, there is no need to declare a variable before using it. In B, a variable must be declared </br>before using it. </br>(ii) </br>In A, the loop counter in a for loop can be assigned a different value anywhere in the loop. In B, </br>the loop counter can only be changed in the predefined way after each iteration. </br>[6] </br>(b) Consider the following Java code: </br>public class ABC { </br> private static int a=4; </br> private int b=5; </br> public int meth() { </br> return a+b; </br> } </br>} </br>Write down whether each of the followings is done during language design time, language </br>implementation time, compile time, load time or run time. </br>(i) The type of the identifier ABC is fixed. </br>(ii) The address of a is fixed. </br>(iii) The address of b is fixed. </br>(iv) The address of meth is fixed. </br>(v) The meaning of the keyword class is fixed. </br>Page 9 of 9 </br>[5] </br>(c) Consider the following C like code fragment: </br>int x=3; </br>int y=2; </br>void fun() { </br> int x=y*2; </br> y=4-x; </br> printf("fun:%d %d\n",x,y); </br>} </br>void main() { </br> int y=x-3; </br> x=2+y; </br> fun(); </br> printf("main:%d %d\n",x,y); </br>} </br>Write down the output of the program if the language uses: </br>(i) Static scoping. </br>(ii) Dynamic scoping. </br>[4] </br>Question 13 [15 marks] </br>(a) (i) Explain why the public key method is never used to encrypt the contents of a message. </br>(ii) If you want to take advantage of the public key method but want to protect the </br>confidentiality of a message, what can you do? </br>(iii) Explain why message digest alone cannot be used to protect the integrity of a message. </br>What other tools are needed to fulfill this purpose? </br>[6] </br>(b) Write the Java application CreateDigest so that when the following command is executed: </br>- java CreateDigest input.dat output.dat </br>The message digest of the file input.dat will be generated using the SHA-1 algorithm. The </br>message digest will be stored at the file output.dat. The file names should be read from the </br>arguments instead of hardcoded in the program. </br>[9] </br>Please check that you have written your student name and student number on </br>every page of your report. Failure to do so will mean that your work cannot </br>be identified. </br>[END OF TAKE-HOME EXAM (SAMPLE) PAPER] </br></div> </div> </div> <div class="aside"> <aside> <h3>分类归档</h3> <div class="line"></div> <ul class="folder"> <li><a href="/programCase.html"><i></i>ALL</a></li> <li><a href="/programCase.html?categoryId=1"><i></i>C/C++代写</a> </li> <li><a href="/programCase.html?categoryId=2"><i></i>Java代写</a> </li> <li><a href="/programCase.html?categoryId=3"><i></i>Python代写</a> </li> <li><a href="/programCase.html?categoryId=4"><i></i>Matlab代写</a> </li> <li><a href="/programCase.html?categoryId=5"><i></i>数据结构代写</a> </li> <li><a href="/programCase.html?categoryId=6"><i></i>机器学习 /ML代写</a> </li> <li><a href="/programCase.html?categoryId=7"><i></i>操作系统代写</a> </li> <li><a href="/programCase.html?categoryId=8"><i></i>金融编程代写</a> </li> <li><a href="/programCase.html?categoryId=9"><i></i>Android代写</a> </li> <li><a href="/programCase.html?categoryId=10"><i></i>IOS代写</a> </li> <li><a href="/programCase.html?categoryId=11"><i></i>JSP代写</a> </li> <li><a href="/programCase.html?categoryId=12"><i></i>ASP.NET代写</a> </li> <li><a href="/programCase.html?categoryId=13"><i></i>PHP代写</a> </li> <li><a href="/programCase.html?categoryId=14"><i></i>R代写</a> </li> <li><a href="/programCase.html?categoryId=15"><i></i>JavaScript/js代写</a> </li> <li><a href="/programCase.html?categoryId=16"><i></i>Ruby代写</a> </li> <li><a href="/programCase.html?categoryId=17"><i></i>计算机网络代写</a> </li> <li><a href="/programCase.html?categoryId=18"><i></i>数据库代写</a> </li> <li><a href="/programCase.html?categoryId=19"><i></i>网络编程代写</a> </li> <li><a href="/programCase.html?categoryId=20"><i></i>Linux编程代写</a> </li> <li><a href="/programCase.html?categoryId=21"><i></i>算法代写</a> </li> <li><a href="/programCase.html?categoryId=22"><i></i>汇编代写</a> </li> <li><a href="/programCase.html?categoryId=23"><i></i>伪代码代写</a> </li> <li><a href="/programCase.html?categoryId=24"><i></i>web代写</a> </li> <li><a href="/programCase.html?categoryId=25"><i></i>c#</a> </li> <li><a href="/programCase.html?categoryId=26"><i></i>图像处理</a> </li> <li><a href="/programCase.html?categoryId=27"><i></i>Lisp代写</a> </li> <li><a href="/programCase.html?categoryId=28"><i></i>程序代写</a> </li> <li><a href="/programCase.html?categoryId=29"><i></i>留学生代写经验指导</a> </li> </ul> </aside> <aside> <h3>Tag</h3> <div class="line"></div> <ul class="tag"> <li><a href="/programCase.html?tagId=1">java代写</a> </li> <li><a href="/programCase.html?tagId=2">calculator</a> </li> <li><a href="/programCase.html?tagId=3">澳洲代写</a> </li> <li><a href="/programCase.html?tagId=4">Car log book</a> </li> <li><a href="/programCase.html?tagId=5">File System</a> </li> <li><a href="/programCase.html?tagId=6">作业代写</a> </li> <li><a href="/programCase.html?tagId=7">CS代写</a> </li> <li><a href="/programCase.html?tagId=8">作业帮助</a> </li> <li><a href="/programCase.html?tagId=9">数据库代写</a> </li> <li><a href="/programCase.html?tagId=10">database代写</a> </li> <li><a href="/programCase.html?tagId=11">作业加急</a> </li> <li><a href="/programCase.html?tagId=12">代写作业</a> </li> <li><a href="/programCase.html?tagId=13">北美代写</a> </li> <li><a href="/programCase.html?tagId=14">linux代写</a> </li> <li><a href="/programCase.html?tagId=15">Shell</a> </li> <li><a href="/programCase.html?tagId=16">C语言代写</a> </li> <li><a href="/programCase.html?tagId=17">程序代写</a> </li> <li><a href="/programCase.html?tagId=18">英国代写</a> </li> <li><a href="/programCase.html?tagId=19">计算机代写</a> </li> <li><a href="/programCase.html?tagId=20">英文代写</a> </li> <li><a href="/programCase.html?tagId=21">代写Python</a> </li> <li><a href="/programCase.html?tagId=22">It代写</a> </li> <li><a href="/programCase.html?tagId=23">留学生</a> </li> <li><a href="/programCase.html?tagId=24">温度分析</a> </li> <li><a href="/programCase.html?tagId=25">python代写</a> </li> <li><a href="/programCase.html?tagId=26">Assignment代写</a> </li> <li><a href="/programCase.html?tagId=27">chess game</a> </li> <li><a href="/programCase.html?tagId=28">游戏代写</a> </li> <li><a href="/programCase.html?tagId=29">加拿大代写</a> </li> <li><a href="/programCase.html?tagId=30">lab代写</a> </li> <li><a href="/programCase.html?tagId=31">机器学习</a> </li> <li><a href="/programCase.html?tagId=32">汇编</a> </li> </ul> </aside> </div> </div> <footer id="about"> <div class="container"> <div class="content"> <div class="tips"> <span>联系方式</span> </div> <ul> <li><i class="email"></i> 51zuoyejun@gmail.com</li> <!-- <li><i class="www"></i>官方旗舰店:<a target="_blank" href="http://t.cn/EVz6MXf">http://t.cn/EVz6MXf</a></li> --> <li><i class="addr"></i>3551 Trousdale Pkwy,University Park,Los Angeles,CA</li> </ul> <div class="qrcode"> <ul> <li> <img src="/reception3/images/qr2.jpg" alt="客服二"> <p>微信客服:abby12468</p> </li> <li> <img src="/reception3/images/qr1.jpg" alt="客服一"> <p>微信客服:Fudaojun0228</p> </li> </ul> </div> <p>温馨提示:如果您使用手机请先保存二维码,微信识别;或者直接搜索客服微信号添加好友,如果用电脑,请直接掏出手机果断扫描。</p> </div> </div> <div class="bottom"> <div class="main"> <div class="logo"> <img src="/reception3/images/footer-logo.png" alt="51作业君"> </div> <div class="pages"> <ul> <li><a href="index.html">首页</a></li> <li><a href="/program.html">程序辅导</a></li> <li><a href="/paper.html">论文辅导</a></li> <li><a href="#evalute">客户好评</a></li> </ul> <ul> <li>友情链接:</li> <li><a href="https://www.hddaixie.com" target="_blank">HD代写</a></li> <li><a href="https://sanyangcoding.com" target="_blank">三洋技术团队</a></li> <li><a href="http://apluscode.net" target="_blank">apluscode代写辅导</a> </li> <li><a href="https://www.aplusdx.com" target="_blank">Aplus代写</a> </li> </ul> <ul> <li><a href="#case">客户案例</a></li> <li><a href="#about">联系我们</a></li> </ul> <ul> <li>keywords:</li> <li><a href="https://51zuoyejun.com/paper.html" title="论文辅导" target="_blank">论文辅导</a></li> <li><a href="https://51zuoyejun.com/paper.html" title="论文润色" target="_blank">论文润色</a></li> <li><a href="/paper.html" title="论文代写" target="_blank">论文代写</a> <li><a href="/program.html" title="程序辅导" target="_blank">程序辅导</a></li> <li><a href="https://51zuoyejun.com/sitemap.html" title="论文辅导" target="_blank">sitemap</a></li> </ul> </div> </div> </div> </footer> <div class="H5Link"> <ul> <li> <a href="#about"> <img src="/reception3/img/wechat.png" alt="51作业君"> <p>官方微信</p> </a> </li> <li> <a href="/index.html"> <img src="/reception3/img/arrow-up.png" alt="51作业君"> <p>TOP</p> </a> </li> </ul> </div> <div id="code"> <div class="code"> <img src="/reception3/images/qr1.jpg" alt="51作业君"> <p>Email:51zuoyejun</p> <p>@gmail.com</p> </div> </div> <div id="aside"> 添加客服微信: <b>abby12468</b> </div> </body> <script src="/reception3/js/jq-session.js"></script> <!-- <script src="./js/getDetail.js"></script> --> <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script> function change(lang) { $.ajax({ type: 'post', url: '/changeLang', dataType: 'json', data: { lang: lang }, success: function (data) { if (data == "success") { location.reload() } }, err: function (XMLHttpRequest, textStatus, errorThrown) { alert("error") } }); } /** * header */ $('header .nav a').click(function () { var eq = $(this).index() $(this).addClass('light').siblings('a').removeClass('light') }) $("#Menu").click(function () { $("header .nav").css("right", "0"); $("body").css("overflow-y", "hidden"); $(".bg").show() }) $("header .nav").on("click", function () { $("header .nav").css("right", "-3.4rem"); $(".bg").hide(); $("body").css("overflow-y", "auto"); }) $(".bg").on("click", function () { $("header .nav").css("right", "-3.4rem"); $(".bg").hide(); $("body").css("overflow-y", "auto"); }) </script> <!-- Cloudflare Web Analytics --><script defer src='https://static.cloudflareinsights.com/beacon.min.js' data-cf-beacon='{"token": "960d64b0a58f4a6f96f6ee60f14c3d14"}'></script><!-- End Cloudflare Web Analytics -->