Workshop 6
Workshop 6
Duration: 90’
======================================================================
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: (3 marks)
- Write a class Profession (in the default package of the NetBean) with the following information:
Profession Where:
- name : String Profession(): Default constructor. You should initialize
the variables: name of “Nguyen Van A”, age of 20, and
- age : int
major in "student.".
- major : String
1
+ Profession () Profession (name: String, age: int, major: String): to
+ Profession (name: String, age: int, initialize all local variables by given parameters from
major: String) this constructor.
+ getName():String getName():String - return name value
+ setName(value: String) : void setName(value: String): void; if the value is empty,
then the set name’s value is (no name); otherwise, set
+ toString():String
the value to name.
toString(): String; return a string with the format
name-age-major
- The Main class is provided for you in binary form. You only test your
program by running the binary file. There are several test cases for you,
as follows:
1.Test default Constructor 1.Test default Constructor
2.Test other Constructor 2.Test other Constructor
3.Test Getter or Setter 3.Test Getter or Setter
Enter your choice(1-3):1 Enter your choice(1-3):2
Enter name:Messi
OUTPUT: Enter age:25
Nguyen Van A-20-Student Enter major:Football
OUTPUT:
Messi-25-Football
1.Test default Constructor 1.Test default Constructor
2.Test other Constructor 2.Test other Constructor
3.Test Getter or Setter 3.Test Getter or Setter
Enter your choice(1-3):3 Enter your choice(1-3):3
Enter name: Enter name:Messi
OUTPUT: OUTPUT:
(no name)-20-Student Messi-20-Student
Question 2: (3 marks)
- Define Vehicle class and Truck class extending from Vehicle (i.e. Vehicle is an abstract class and
it is superclass; you do not need to write it yourself; Truck is a subclass) with the following information:
Vehicle Where:
- make:String Vehicle(make: String, model: String, year: int,
fuelType: String, fuelEfficiency: double): Constructor
- model:String
with make, model, year, fuelType and fuelEfficiency.
- year:int
getMake():String – return make.
- fuelType: String
getModel(): String - return model.
- fuelEfficiency: double
getYear(): int – return year.
+ Vehicle(make: String, model: String, getFuelType(): String – return fuelType
year: int, fuelType: String, fuelEfficiency:
getFuelEfficiency(): double – return fuelEfficiency
double)
calculateFuelEfficiency():double – abstract methods
+ getMake():String
calculateDistanceTraveled():double – abstract
+ getModel(): String
methods
+ getYear(): int
getMaxSpeed():double – abstract methods
+ getFuelType(): String
+ getFuelEfficiency(): double
+ calculateFuelEfficiency():double
2
+ calculateDistanceTraveled():double
+ getMaxSpeed():double
OUTPUT: OUTPUT:
8.08 65.51
Enter make:Tatra
Enter model:Tatra 810 4x4
Enter year:2020
Enter fuel Type:GASOLINE
Enter fuel Efficiency:8.112
Enter cargo Capacity:4.5
1.Test calculateFuelEfficiency
2.Test calculateDistanceTraveled
3.Test getMaxSpeed
Enter your choice(1-3):3
OUTPUT:
80.00
Question 3: (4 marks)
- Define a Motorbike class(in the default package) with the following information:
3
Motorbike Where:
-licencePlate:String Default contructor: set all fields are empty
-owner:String strings except the value field. The other
contructor sets all fields by the given
-brand:String
parameters
-value:long
getLicencePlate():String – return
+Motorbike() licencePlate.
+Motorbike(licencePlate:String, owner:String, getOwner():String – return owner.
brand:String, value:long)
getBrand():String – return brand.
+getLicencePlate():String
+getOwner():String
getOwner():String – return owner.
+getBrand():String getValue():long – return value.
+getValue():long setLicencePlate (licencePlate:String): void –
+setLicencePlate(licencePlate:String):void update licencePlate.
+setOwner(owner:String):void setOwner(owner:String): void – update
owner.
+setBrand(brand:String):void
+setValue(value:long):void setBrand(brand:String): void – update brand.
setValue(value:long): void – update value.
- Create a MotoList class (in the default package) extending from HashMap<Key, Value> class in
java collection. (in which: Key: will be used to store licence plate and Values store Motorbike
objects).
MotoList Where:
+addElement(Motorbike m):void addElement(Motorbike m):void – add one
+listByDistrict(String distCode):void Motorbike object in the values list.
+totalValue():long listByDistrict(String distCode):void –
print all of Motorbike objects by district
code (the third character at the licencePlate
is code of district. i.e. “51X1-12345” -> X
is Thu duc district). Format string of a
Motorbike object like this: (“%s - %s - %s\
n”, licencePlate, owner, value)
totalValue():long – return a total of values
in the list object.
- The Main class is provided for you in binary form. You only test your
program by running the binary file. There are several test cases for you,
as follows:
The Motorbikes have been added: The Motorbikes have been added: The Motorbikes have been added:
51X1-12345 - Quang - Honda - 5000 51X1-12345 - Quang - Honda - 5000 51X1-12345 - Quang - Honda - 5000
51M5-33121 - Thao - Suzuki - 7200 51M5-33121 - Thao - Suzuki - 7200 51M5-33121 - Thao - Suzuki - 7200
51X3-22156 - Linh - Honda - 4600 51X3-22156 - Linh - Honda - 4600 51X3-22156 - Linh - Honda - 4600
53F3-78002 - Thai - Honda - 6500 53F3-78002 - Thai - Honda - 6500 53F3-78002 - Thai - Honda - 6500
Added a new Motorbike: Added a new Motorbike: Added a new Motorbike:
Enter licencePlate:51P5-77156 Enter licencePlate:51P5-77156 Enter licencePlate:51P5-77156
Enter owner:Huong Enter owner:Huong Enter owner:Huong
Enter brand:Yamaha Enter brand:Yamaha Enter brand:Yamaha
Enter value:3700 Enter value:3700 Enter value:3700
1- List all moto by district 1- List all moto by district 1- List all moto by district
2- Total value of moto in list 2- Total value of moto in list 2- Total value of moto in list
Select a function from the menu:1 Select a function from the menu:1 Select a function from the menu:2
Enter your code: (F;M;P;X;Z):f Enter your code: (F;M;P;X;Z):F OUTPUT:
Registration in District 3 Registration in District 3 27000
4
OUTPUT: OUTPUT:
53F3-78002 - Thai - 6500 53F3-78002 - Thai - 6500