0% found this document useful (0 votes)
25 views3 pages

Asm 04

The document describes an assignment to create an interface called IUtilities with four methods and a class called MyUtilities that implements the interface. The interface methods are: checkIntegerNumber to validate an integer, removeDuplicatedWords to remove duplicate words from a string, checkFormatString to validate a formatted string, and sumNumbers to sum digits in a string. The class MyUtilities implements these methods. Sample outputs testing the methods are provided.

Uploaded by

baottse182840
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views3 pages

Asm 04

The document describes an assignment to create an interface called IUtilities with four methods and a class called MyUtilities that implements the interface. The interface methods are: checkIntegerNumber to validate an integer, removeDuplicatedWords to remove duplicate words from a string, checkFormatString to validate a formatted string, and sumNumbers to sum digits in a string. The class MyUtilities implements these methods. Sample outputs testing the methods are provided.

Uploaded by

baottse182840
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Assigment 04 – Interface

Duration: 70’
======================================================================
Software Requirements
• Netbean 8.2 or later, JDK 8 or later, Notepad, Command Prompt, WinRAR / WinZip with
Windows Explorer (File Explorer) on Windows 7 and above.
Instructions
• Step 1: Students download the given materials from LMS.
• 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 Q1, Q2, Q3,…), 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 Create a folder named : RollNumber_FullName_ASM0x (x : 1,2,..,6) that contains
folders (created Step 03 ) as the below figure:

o Use WinRAR / WinZip tool to compress the RollNumber_FullName_ASM0x


folder and submit it to LMS
❖ Importance:
o Do not change the names of the folders specified (or required ) in the exam and the name of submit
folder in Step 04 must be correct. If you change it (incorrectly), the grading software can not find
the execute file (.jar) to score, thus the exam result will be 0.
======================================================================
Question 04: (10 marks)

Write a interface named IUtilities with the following information:

IUtilities Where:

1
+ checkIntegerNumber(value:String, min: int, • checkIntegerNumber(value:String,min: int,
max: int):int max: int):int – convert value to an integer
+ removeDuplicatedWords(value: String): String have 2 to 10 digits between min and max.
+ checkFormatString(value:String):int
If value is invalid then return length of the
+ sumNumbers(value:String):double
value. [2.5 marks]
• removeDuplicatedWords (value: String):
String:– convert value to title case with
duplicated words are removed and each
word seperated by a space. [2.5 marks]
• checkFormatString(value:String): String:–
check the value formatted : A.B.C with A
is 03 uppercase letters, B is 06 digits, C in
[@#$]. If value is valid then return an
integer of B, otherwise return length of the
value. [2.5 marks]
• sumNumbers(value:String):double –
extract all digits to integer then sum of
them.[2.5 marks]

Write a class named MyUtilities, which implements the interface IUtilities. The class MyUtilities
implements all methods in IProcess as below:
+checkIntegerNumber(value:String, min: int, max: int):int []
+convertString (value: String): String
+checkFormatString(value:String):int
+sumNumbers(value:String):double
Hints: you can use the isDigit() method of Character class) to check whether a character is a digit or not and
charAt() method to get a character in the string.

The program output might look something like this:

Do not format the result.

The program output might look something like this:


#Case 1:
1.Test checkIntegerNumber method
2.Test removeDuplicatedWords method
3.Test checkFormatString method
4.Test sumNumbers method
Enter Test Case No.(1 | 2):1
Enter min value:10
Enter max value:100
Enter a string:5
OUTPUT:
1
-----------------------------------------------------
#Case 2:
1.Test checkIntegerNumber method
2.Test removeDuplicatedWords method
3.Test checkFormatString method
4.Test sumNumbers method
Enter Test Case No.(1 | 2):2
Enter a string:hello world hello hello , how are you
OUTPUT:
Hello World , How Are You
-----------------------------------------------------
#Case 3:
2
1.Test checkIntegerNumber method
2.Test removeDuplicatedWords method
3.Test checkFormatString method
4.Test sumNumbers method
Enter Test Case No.(1 | 2):3
Enter a string:abc123456@
OUTPUT:
10
-----------------------------------------------------
#Case 4:
1.Test checkIntegerNumber method
2.Test removeDuplicatedWords method
3.Test checkFormatString method
4.Test sumNumbers method
Enter Test Case No.(1 | 2):3
Enter a string:ABC.123456.#
OUTPUT:
123456
-----------------------------------------------------
#Case 5:
1.Test checkIntegerNumber method
2.Test removeDuplicatedWords method
3.Test checkFormatString method
4.Test sumNumbers method
Enter Test Case No.(1 | 2):4
abc12 def8.5 kdje
OUTPUT:
20.50
-----------------------------------------------------
#Case 6:
1.Test checkIntegerNumber method
2.Test removeDuplicatedWords method
3.Test checkFormatString method
4.Test sumNumbers method
Enter Test Case No.(1 | 2):4
hello world
OUTPUT:
0.00

You might also like