Lab 3
Lab 3
Learning Outcomes:
Upon successful completion of this workshop, you will have demonstrated the abilities
to:
Requirements:
Part 1: [2 points]
To complete this task you should read and study the lecture Encapsulation
-Create a new project named “CarManager”. It contains the file Car.java and
Tester.java.
-In the file Car.java, you implement the Car class base on the class diagram as below:
Car
-Colour: String
-EnginePower:int
-Convertible: boolean
-ParkingBrake: boolean
//constructors
+Car()
+Car(String Colour, int EnginePower, boolean Convertible,
boolean ParkingBrake )
//getters
+getColour():String
+getEnginePower():int
+getConvertible(): boolean
+getParkingBrake(): boolean
//setters
+setColour(String colour):void
+setEnginePower(int EnginePower):void
+setConvertible(boolean Convertible): void
+setParkingBrake(boolean ParkingBrake): void
//other logic methods
+pressStartButton():void
+pressAcceleratorButton():void
+output(): void
Default constructor: to assign all fields to empty values
Constructor with parameters: to assign all fields to input parameters
Getters: to return the value of a field
Setters: to change the value of a field
The method pressStartButton(): print out the message “You have pressed
the start button”
1
The method pressAcceleratorButton(): print out the message “You have
pressed the Accelerator button”
The method output(): print out values of all fields
Part 2: Find classes [3 points] and use UML to draw class structure (optional)
Problem: Mr. Hung is the owner of the shop that sells guitars. He wants you to build him a shop
management app. This app is used for keeping track of guitars. Each guitar contains
serialNumber, price, builder, model, back Wood, top Wood. The guitar can create a melodious
sound. The shop will keep guitars in the inventory. The owner can add a new guitar to it, he
search also the guitar by the serialNumber.
Requirement: Write your paper down classes in the problem and use UML draw class structure.
Guideline:
2
Using UML to draw a class diagram
public Guitar( String serialNumber, int price, String builder, String model,
String backWood, String topWood) {…}: to assign all fields by input
parameters
public void createSound(){…}: in the method, invoke all getters and use
System.out to print out values after getting.
- In the project, create a new file named “Tester.java. Create the method main in here,
you type:
3
Part 4: Draw the memory map when the program runs [1 point]
Explain step by step what happened when the program runs and answer some questions.