Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is a practical that im practicing through for my exam, so attached is the UML diagram and the code to it (java). i need

This is a practical that im practicing through for my exam, so attached is the UML diagram and the code to it (java). i need help explaining it. i dont understand why the one diamond is coloured and the other not , and the setMethod for Engine it includes the engines instance variables in the vehicle class

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed
Vehicle -manufacturer: String -engine: Engine -registration: Registration > Vehicle(manufacturer: String, noCylinders: int, displacement: double, registration: Registration) +setManufacturer(manufacturer:String]: void +setEngine(no Cylinders:int, displacement: double): void +setRegistration(registration: Registration): void +getManufacturer[): String +getEngine(): Engine +getRegistration(): Registration +toString(): String Engine Registration -numCylinders: int -alphaField: String -displacement: double -numericField: String -provinceCode: String > Engine [noCylinders: int, displacement: double] +setNumCylinders[noCylinders: int): void > Registration(alphaF: String, numF: String, +setDisplacement (displacement: double): void provC: String) +getNumCylinders[): int +setAlphaField[alphaF: String): void +getDisplacement(): double +setNumericField(numF: String): void +toString():String +setProvinceCode(provC: String): void +getAlphaField(): String +getNumericField[): String +getProvinceCode[): String +getRegistration(): String +toString():Stringpublic class Vehicle private String manufacturer; private Engine engine; private Registration registration; public Vehicle() public Vehicle(String make, int engCyls, double engDisplegistration reg) setManufacturer (make) ; setEngine (engCyls, engDispl setRegistration(reg) ; public void setManufacturer(String make) manufacturer = make; public void setEngine(int engCyls, double engDispl engine = new Engine(engCyls, engDispl public void setRegistration(Registration reg) registration = reg; public String getManufacturer() return manufacturer;public Engine getEngine() return engine; public Registration getRegistration( ) return registration; public String toString() return "Vehicle with registration " + getRegistration(). getRegistration() + " is a " + getManufacturer() + " with a" getEngine() ; public static void main(String args) Registration r1 = new Registration("BND", "087", "GP"); Vehicle v1 = new Vehicle("Ford", 4, 2.3, r1); System. out. print In(v1) ; System. out. print In("Assign new registration to vehicle:"); Registration r2 = new Registration("XYZ", "123", "NW") ; v1. setRegistration(r2) ; System. out. print In(v1); System. out. print In("Terminate vehicle - registrations still exist!"); v1 = null; System. out. print In("r1 = " + r1); System. out. print In("r2 = " + r2);System. out. print in( "But vehicle does not exist. ..!"); System. out. printIn( "vl = " + v1)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions