Final ASM
Final ASM
Duration: 85’
======================================================================
Software Requirements
• Netbean 8.2 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, or 3) that
contains folders (created Step 03 ) as the below figure:
======================================================================
❖ Question 1: (2 marks)
Read PE instructions at the bottom of the exam paper.
Do not pay attention to the real meaning of objects, variables, and their values in the questions below.
Write a class Phone (in the default package of the NetBean) with the following information:
1
Phone Where:
- int id • Phone () - default constructor
- String name • Phone(id:int, name:String, unitPrice:double,
- double unitPrice quantity:int, status: boolean) - parameterized
- int quantity constructor, which sets values to id, name,
- boolean: status unitPrice, quantity, and status
+Phone ()
• getName ():String – return phone name with
+Phone
(id:int,name:String,unitPrice:double,quantity:int, uppercase
status: boolean) • subTotal():double – return subtotal [subtotal
+getName(): String = quantity * unitPrice]. If the phone name
+subTotal():double started with “S” or “s” then discount 10% on
+toString():String the subTotal. The subTotal value is formatted
with two place decimals.
• Override toString() method to return a string
that contains all the information of the
phone: id, name, unitPrice, quantity,
subTotal, status. If status is true then print
“Available” otherwise “Unavailable” and the
unitPrice is formatted with two place
decimals
-----------------------------------------------oOo-------------------------------------------
❖ Question 2: (3 marks)
Write a class Shape and a class Circle extending from Shape (i.e. Shape is a super class and Circle is a sub
class) with the following information:
2
Shape Where:
#perimeter: double • Shape () - default constructor
#area: double • getArea ():double – return area.
+Shape() • getPerimeter ():double – return perimeter.
+getArea ():double
+getPerimeter ():double
Where:
Circle • Circle() - default constructor
-radius: double • Circle(value: double) - constructor, which sets
value to radius. If value is less than 0 then set
+Circle() radius = 0.5
+Circle(value: double) • toString():String – return the string of format :
+toString():String perimeter and area (the perimeter and area
+calculateArea(): void are formatted with two decimal places).
+calculatePerimeter(): void calculateArea():void – calculate the area of
the circle then store into area variable (area =
Math.PI * radius * radius )
calculatePerimeter ():void – calculate the
perimeter of the circle then store into
perimeter variable (perimeter = 2 * Math.PI
* radius)
The program output might look something like this (using Circle class):
Enter radius:1.5 Enter radius:1.5 Enter radius:16.5
1.Test calculatePerimeter() 1.Test calculatePerimeter() 1.Test calculatePerimeter()
2.Test calculateArea() 2.Test calculateArea() 2.Test calculateArea()
3.Test toString() 3.Test toString() 3.Test toString()
Enter TC(1/2/3):1 Enter TC(1/2/3):2 Enter TC(1/2/3):3
OUTPUT: OUTPUT: OUTPUT:
9.42 7.07 855.30,103.67
-----------------------------------------------oOo-------------------------------------------
Question 03 (2 marks)
Write a class named Employee with the following information:
Employee Where:
• Employee () - default constructor
-id: int
-salary: double • Employee(int id, double salary) - constructor, which
sets values to id, and salary
+ Employee ()
+ Employee(int id, double salary) • Write setters and getters for fields, except id with
+ toString(): String getter only
• toString(): String – return the string of format:
id, and salary (the salary is formatted with two
decimal places )
The interface IEmployee below is already given in Java code format, thus you can use it without creating an
IEmployee .java file
<<interface>>
IEmployee
3
+getEmployeeSalaryById(int id):double
+getEmployeeWithMaxSalary ():
Employee
Write a class EmployeeList which extends from ArrayList (ArrayList is a collection) and implements the
IEmployee interface with the following information :
EmployeeList
Where:
+getEmployeeSalaryById (int id): double
+getEmployeeWithMaxSalary (): Employee • getEmployeeSalaryById(int id): double – Find
the employee by id. If found then return the
employee salary, otherwise return the id
• getEmployeeWithMaxSalary(): Employee –
return the employee with the highest salary.
Suppose in the list there is only one employee
with the highest salary.
The program output might look something like this (using EmployeeList class):
The employees have been added: The employees have been added: The employees have been added:
1 , 10.00 1 , 10.00 1 , 10.00
2 , 30.00 2 , 30.00 2 , 30.00
3 , 50.00 3 , 50.00 3 , 50.00
4 , 20.00 4 , 20.00 4 , 20.00
5 , 40.00 5 , 40.00 5 , 40.00
****Add a new employee***** ****Add a new employee***** ****Add a new employee*****
Enter id:6 Enter id:6 Enter id:6
Enter salary:60 Enter salary:60 Enter salary:100
1.Test getEmployeeNameById 1.Test getEmployeeNameById 1.Test getEmployeeNameById
2.Test getEmployeeWithMaxSalary 2.Test getEmployeeWithMaxSalary 2.Test getEmployeeWithMaxSalary
Enter TC(1/2):1 Enter TC(1/2):1 Enter TC(1/2):2
Enter id:6 Enter id:10 OUTPUT:
OUTPUT: OUTPUT: 6 , 100.00
60.00 10.00
-----------------------------------------------oOo-------------------------------------------
The interface IUtilities below is already given in Java code format, thus you can use it without creating an
IUtilities .java file.
<<interface>>
IUtilities
+ sumNumber(number: int): int
+ replaceString(sentence: String, s1:String, s2:String):
String
4
Write a class named MyUtilities, which implements the interface IUtilities. The class MyUtilities
implements all methods in IUtilities as below:
+ sumNumber (number: int): int – return the sum of all divisors from 1 to number/2
+ replaceString (sentence: String, String, str: String): int – return a new string after replacing the
words equal to the string s1 in the string sentence with the string s2. Suppose that the sentence
consists of words separated by a space, string comparisons are not case-sensitive
+
Hints: You can refer to the methods: split() and join() of the String class