192 Po
192 Po
1. Create a folder to save given projects, e.g. PRO_given (1). Down load given materials to (1).
2. Steps to do question 1 (do the same for other questions): Open NetBeans, open the given Q1 project,
then complete it according to the requirements in the exam. (Do not: delete or edit given files, or create
java file with the same name as given files).
3. Before submission: Run the function "Clean and Build Project" (Shift+F11), then rename the folder
dist to RUN (or run). (If the folder RUN already exists, delete it before renaming).
4. Submission: to submit the project Q1, at first you must select Question No = 1, browse and select the
project folder (e.g. 1, Q1 or Q1X,...) then click the Submit button. Do the same for other questions. Do
not submit the un-edited given project.
5. Do not use accented Vietnamese when writing comments in programs.
6. Software tools must be used: NetBeans IDE 8.x and Java JDK 1.8.
If at least one of the above requirements is not followed, the exam will get ZERO.
Trouble shooting:
If the given project (e.g. Q1) runs with error, you need to run "Clean and Build Project" (Shift+F11). If still
error, try to rename the project, e.g. from Q1 to Q1X or Q1Y,...
If the size of the project is too large for submission, try to delete the folder "build".
Do not pay attention to real meaning of objects, variables and their values in the questions below.
Question 1: (2 marks)
Question 2: (3 marks)
Write a class named Car that holds information about a car and class named SpecCar which is
derived from Car (i.e. Car is super class and SpecCar is sub class).
Car Where:
1
-maker:String getMaker():String – return maker.
-price:int getPrice():int – return price.
+Car() setMaker(maker:String):void – update maker.
+Car(maker:String, price:int)
toString():String – return the string of format:
+getMaker():String
+getPrice():int maker, price
+setMaker(maker:String):void
+toString():String
Where:
SpecCar toString():String – return the string of
-type:int format:
maker, price, type
+SpecCar() setData():void – Add string “XZ” to
+SpecCar(maker:String, price:int, type:int) the head of maker and increase price
+toString():String by 20.
+setData():void
+getValue():int getValue():int – Return price+inc,
where if type<7 then inc=10,
otherwise inc=15.
Question 3: (3 marks)
Write a class named Car that holds information about a car.
Car Where:
-maker:String getMaker():String – return maker.
-rate:int getRate():int – return rate.
+Car () setMaker(maker:String): void – update maker.
+Car (maker:String, rate:int) setRate(rate:int): void – update rate.
+getMaker():String
+getRate():int
+setMaker(maker:String):void
+setRate(rate:int):void
The interface ICar below is already compiled and given in byte code format, thus you can use it
without creating ICar.java file.
import java.util.List;
public interface ICar {
public int f1(List<Car> t);
public void f2(List<Car> t);
public void f3(List<Car> t);
}
2
Write a class named MyCar, which implements the interface ICar. The class MyCar implements
methods f1, f2 and f3 in ICar as below (you can add other functions in MyCar class):
f1: Return the whole part of average rate of all cars (e.g. the whole part of 3.7 is 3).
f2: Find the first max and min rates in the list and swap their positions.
f3: Sort the list by maker alphabetically, in case makers are the same, sort them descendingly
by rate.
When running, the program will add some data to the list. Sample output might look something
like:
Add how many elements: 0 Add how many elements: 0
Enter TC(1-f1;2-f2;3-f3): 1 Enter TC(1-f1;2-f2;3-f3): 2
The list before running f1: The list before running f2:
(A,3) (B,7) (C,6) (D,7) (E,6) (A,6) (B,2) (C,9) (D,17) (E,8) (F,17) (G,2)
OUTPUT: OUTPUT:
5 (A,6) (D,17) (C,9) (B,2) (E,8) (F,17) (G,2)
Question 4: (2 marks)
The interface IString below is already compiled and given in byte code format, thus you can use it
without creating IString.java file.
public interface IString {
public int f1(String str);
public String f2(String str);
}
Write a class named MyString, which implements the interface IString. The class MyString
implements methods f1 and f2 in IString as below:
f1: Count and return number of prime digits in str.
f2: Reverse order of all words in str (word = a string without space).