程序代写 SOFT2201/COMP9201 Week 3 Tutorial

SOFT2201/COMP9201 Week 3 Tutorial
UML and Implementation

Copyright By PowCoder代写 加微信 powcoder

Unified Modelling Language is a visual language that allows software designers to visualise data and
functionality of their system and how they interact with each other. There are several different UML
diagram types including class diagram, interaction diagram and use case diagram.

Question 1: Heirarchy and Properties

You have been provided an example UML class model, this is a simple class hierarchy, outlining
shared properties and functionality between the base class and sub-types.

Figure 1: UML Class diagram

Discuss and answer the followings:

• What kind of class is Canine? What keyword should we use if we want to represent this kind
of class in UML?

• What is the parent class of Wolf?

• What properties are shared between DomesticDog and Wolf?

• What methods are shared between DomesticDog and Wolf?

SOFT2201/COMP9201 UML and Implementation

• Outline the access level associated with each field

• Does either sub-type of Canine override one of its methods?

Question 2: Associations

-model: St ring

-capacity: int

-engineOn: boolean-terminalid: St ring
-plane: Aeroplane -passengers: List

+assignPlane(plane:Aeroplane): void -rego: St ring

+addPassenger(passenger:Passenger): void
+takeoff(): void

+removePassenger(): Passenger

-hangarid: St ring

-dockedPlanes: List
-capacity: int

+dockPlane(plane:Aeroplane): void

+unloadPlane(registrationNo:String): Aeroplane

-ticketld: St ring

-customer: Customer -name: St ring

-terminal: Terminal -tickets: List

-time: int +addTicket(ticket:Ticket): void

Analyse the UML diagram and identify and answer the following:

• Outline all the associations within the UML Diagram

• How many Aeroplanes can a Hangar contain? Annotate the multiplicity of the association

• How many Tickets can a Customer hold? Annotate the multiplicity of the association

• Identify any association relationships where an object cannot exist without at least one other
type (Composition)

Question 3: Critiquing a model and Refactoring the design

You will be asked through the semester to identify software design issues and refactor them. Not only
will this improve your ability to debug problems but will help understand and identify issues within a
code base.

Common issues that arise from improper modelling:

Software Design and Construction 1 Page 2 of 5

SOFT2201/COMP9201 UML and Implementation

• Weak base classes

• Improper parent or interface type associated

• Repetitive logic and data

• Class dependent on other classes

• Classes performing more functionality than it should be

• Misassigned responsibility to an object

Given the following class diagram, discuss with your class and identify issues with the design.

Question 4: Extract Pokemon

You have been given a file that stores pokemon data called pokedex.json. Use the simple-json
library as a way to read the pokedex.json file and output the contents.

You can add the dependency to your project by adding the following to the dependecies section in
your gradle.build file.

implementation ’com.googlecode.json-simple:json-simple:1.1.1’

The element within pokedex.json file is in the following layout:

“kanto_no” : index,
“type_1” : first_type,
“type_2” : second_type,
“pokemon” : name

Software Design and Construction 1 Page 3 of 5

SOFT2201/COMP9201 UML and Implementation

Import the following types into your project and attempt to parse the pokedex.json file.

import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;

JSON-Simple provides some examples in its wiki, you can access this here.

Read the contents of the file into a String object and utilise the .parse method to interpret the
data into a JSONArray. You may need to apply a cast on the return result.

Command-query Separation

Command-query separation principle within imperative and object-oriented programming asks the
programmer to design their methods to only perform a command or a query. A command mutates
and operates on the data provided or the instance itself. A query will not mutate data but provide an
answer when invoked.

Question 5: Refactor the code

Identify methods which violate command-query separation and refactor the code, this may require
breaking the code up into different functions.

public class Product {

private String name;
private int qty;
private int max;
private double price;

* Constructs the product, providing name and quantity

* @param name

* @param qty

public Product(String name, int qty, int max, double price) {

this.name = name;
this.qty = qty;
this.max = max;
this.price = price;

public Object process(String request, double value) {
if(request.equals(“getqty”) {

return new Integer(qty);

Software Design and Construction 1 Page 4 of 5

https://code.google.com/archive/p/json-simple/wikis

SOFT2201/COMP9201 UML and Implementation

} else if(request.equals(“updateqty”)) {
qty += (int) value;
return null;

} else if(request.equals(“getprice”)) {
return new Double(price);

} else if(request.equals(“updateprice”)) {
price += price;
return null;

return null;

* Returns the name of the product

* @return name

public String getName() {

return name;

* Passes the order

* @param o

public void order(Order o, int qty) {

o.addProduct(this, qty);

• What kind of issues does the method process create?

• Is it the responsibility of the Product class to perform this kind of logic?

• Refactor the code and separate any logic that does not belong in the Product class

Software Design and Construction 1 Page 5 of 5

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com