Workshop 3
Workshop 3
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 named Shape and a class named Circle extended from Shape (i.e. Shape is a super
class and Circle is a sub class) with the following information (use Math.PI for calculation):
Shape Where:
-perimeter: double Shape () - default constructor: set the
1
-area: double perimeter is 0 and the area is 0
+Shape() getArea (): double – return area.
+getPerimeter ():double getPerimeter (): double – return perimeter.
+setPerimeter(value :double):void setPerimeter(value : double):void – set
value to perimeter .
+getArea ():double
setArea(value: double):void – set value to
+setArea(value: double):void
area
Where:
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 103.67,855.30
Question 2: (3 marks)
Write a class Car and a class SpecCar extending from Car (i.e. Car is a super class and SpecCar is
a sub class) with the following information:
Car Where:
-name:String Car () - default constructor
-price: double Car(name:String, price:double) - constructor, which
sets values to name, price
+Car()
getName():String – return name with upper case.
+Car(name:String, price:double)
getPrice():double – return price.
+getName():String
toString():String – return the string of format:
+getPrice():double
name,price
+toString():String
Where:
2
SpecCar SpecCar() - default constructor
-warranty:int SpecCar(name:String, price:double
warranty:int) - constructor, which sets
values to name, price, warranty
+SpecCar()
toString():String – return the string of
+SpecCar(name:String, price:double
format: name , price , warranty
warranty:int)
getWarranty():int – Check if name is
+toString():String
“audi” then return warranty + 5, otherwise
+setWarranty(int value):void return warranty + 2.
+getWarranty ():int setWarranty (int value):void – update
warranty
The program output might look something like this (using SpecCar class):
Enter name:audi Enter name: bmw Enter name: AUDI Enter name: honda
Enter price:10.5 Enter price: 20 Enter price: 30.6 Enter price: 10.9
Enter warranty:3 Enter warranty: 4 Enter warranty: 5 Enter warranty: 3
1. Test toString() 1. Test toString() 1. Test toString() 1. Test toString()
2. Test getName() 2. Test getName() 2. Test getName() 2. Test getName()
3. Test getWarranty 3. Test getWarranty () 3. Test getWarranty 3. Test getWarranty
() Enter TC (1,2,3): 2 () ()
Enter TC (1,2,3): 1 OUTPUT: Enter TC (1,2,3): 3 Enter TC (1,2,3): 3
OUTPUT: BMW OUTPUT: OUTPUT:
AUDI , 10.50 , 3 10 5
Question 3: (4 marks)
Define a Student class and a StudentInIT class extending from Student (i.e. Student is
an abstract class and it is superclass, StudentInIT is a subclass) with the following
information:
Student Where:
-rollNumber:String Student (): Default constructor
-name:String Student(rollNumber:String, name:String,
phone:String): Constructor, which sets
-phone:String
values to basic, specialized and internship
+Student() subjects of the Student
+Student(rollNumber:String, getRollNumber() – getName() – getPhone()
name:String, phone:String) are the getters of the student class.
+getRollNumber():String setRollNumber() – setName() – setPhone()
+setRollNumber(rollNumber:String):voi – are the setters of the student class.
d toString(): String – return Student
+getName():String information with format: role, name, phone
+setName(name:String):void mediumScore():double – an abstract
method.
+getPhone():String
classification():String – an abstract method.
+setPhone(name:String):void
+toString(): String
+mediumScore():double
+classification():String
Where:
3
StudentInIT StudentInIT() - default constructor to set all of
the edges to 0
-basic, specialized, internship :int
StudentInIT(rollNumber:String, name:String,
phone:String, basic:int, specialized:int,
+ StudentInIT()
internship:int) - constructor, which sets
+ StudentInIT(rollNumber:String, values to basic, specialized and internship
name:String, phone:String, basic:int, subjects of the StudentInIT.
specialized:int, internship:int)
Setters for subjects are needed to set values in
+getBasic():int range 0…10. In case the value is out of range,
+setBasic(b:int):void print out “Incorrect”.
+getSpecialized():int mediumScore():double – Returns the
+setSpecialized(s:int):void calculated average of 3 subjects.
+getInternship():int classification():String – Returns a string value,
+setInternship(i:int):void evaluated against the following conventionally
calculated average
+mediumScore():double
o 0…<5 : Weak student
+classification():String
o 5…<7 : Average academic
o 7…<8.5: Good academic
o 8.5…10: Excellent Student
4
3. Test setBasic() 3. Test setBasic()
4. Test setSpecialized() 4. Test setSpecialized()
5. Test setInternship() 5. Test setInternship()
Enter TC:3 6. Test Student
Enter Basic score:10 information
OUTPUT: Enter TC:6
10.0 OUTPUT:
123,pro,099