Practical Exam – PRO192
Duration: 60’
======================================================================
Software Requirements
Netbean 8.2 or later, JDK 8, Notepad, Command Prompt, WinRAR / WinZip with Windows
Explorer (File Explorer) on Windows 7 and above.
Students are ONLY Allowed to use:
His / her study materials like sample codes and program examples are stored on his / her
computer only.
Instructions
Step 1: Students download the given materials from the exam software.
Step 2: Students read questions and prepare answers in the given template.
Step 3: Prepare to submit the answer:
o For each question (e.g., question 1), please create two sub-folders: run and src.
o Copy the *.jar file into the run folder, and the entire project source code file into the
src folder.
Step 4: Submit a solution for each question:
o Choose the question number (e.g., 1) in PEA software, and then attach the
corresponding solution folder (e.g., 1). Click the Submit button to finish submitting
this question.
o
Note:
o Solutions will be marked by Automated Marking Software.
o The use of tools other than those allowed in the above section whether intentionally or
unintentionally, is considered a violation of the exam rules, and the exam result will be 0.
o Do not change the names of the folders and files specified (or required ) in the exam and the
name of the submit folders in Step 04 must be correct. If you change it (incorrectly), the
marking software can not find the execute file (.jar) to mark, thus the exam result will be 0.
======================================================================
Question 1: (2 marks/methods)
Write a class JavaBasic (in the default package of the NetBean) with the following information:
1
JavaBasic Where:
isPerfectNumber(number: int): boolean -
check if the number is perfect or not.
+ isPerfectNumber(number: int): avgOddArray(a: int[]): double – return
boolean averaged of odd number in array a, if none
odd number return 0.00
+ avgOddArray(a: int[]): double
getSecondSmallest(a: int[]): int – return the
+ getSecondSmallest(a: int[]): int
second smallest in array
+ removeAllSpace(s: String): String
removeAllSpace(s: String): String – return a
+ findLongestWord(s: String): String string is s after remove all space
findLongestWord(s: String): String – return
the longest word in s
Do not format the result.
The program output might look something like this:
[Link] isPerfectNumber() [Link] isPerfectNumber() [Link] isPerfectNumber()
[Link] avgOddArray() [Link] avgOddArray() [Link] avgOddArray()
[Link] getSecondSmallest() [Link] getSecondSmallest() [Link] getSecondSmallest()
[Link] removeAllSpace() [Link] removeAllSpace() [Link] removeAllSpace()
[Link] findLongestWord() [Link] findLongestWord() [Link] findLongestWord()
Enter TC(1/2/3/4/5):1 Enter TC(1/2/3/4/5):2 Enter TC(1/2/3/4/5):3
Enter a number:6 Enter a[0]:1 Enter a[0]:1
OUTPUT: Enter a[1]:2 Enter a[1]:2
true Enter a[2]:3 Enter a[2]:3
Enter a[3]:4 Enter a[3]:4
Enter a[4]:5 Enter a[4]:5
OUTPUT: OUTPUT:
3.00 2
[Link] isPerfectNumber() [Link] isPerfectNumber()
[Link] avgOddArray() [Link] avgOddArray()
[Link] getSecondSmallest() [Link] getSecondSmallest()
[Link] removeAllSpace() [Link] removeAllSpace()
[Link] findLongestWord() [Link] findLongestWord()
Enter TC(1/2/3/4/5):4 Enter TC(1/2/3/4/5):5
Enter a string: P r o 19 2 Enter a string:I love you
OUTPUT: OUTPUT:
Pro192 love