I’ve attached a document containing everything needed to complete this question, the question itself is quite wo

I’ve attached a document containing everything needed to complete this question, the question itself is quite wordy but I’m assuming it would only take 1-2 hours to throw up a program for it. the document also contains examples which should easily guide to a quick answer.The Situation I would like would be Computer – Manufacturer


TMA02
Question 2
In this question you will write two classes of your own to model a real-world scenario. The
scenario will be one you choose yourself
Two example classes are provided in project TMA02_Q2 that model a scenario involving an
artist and a painting. You should find these an important guide, although you must ensure that
your own scenario is sufficiently different from our example, and includes one method that is
distinctive and specifically relevant to your scenario. This is explained further below.
This question, as well as testing your ability to apply what you have learned from Units 1–5 and
the Unit 4 Composition Supplement, is an opportunity for you to be creative in thinking about
real-world situations that can be modelled in software.
Task
You are asked to identify two classes of real-world objects from sports, games, hobbies, the arts
or pastimes that are naturally connected by a has-a relationship (i.e. that demonstrate
composition), and to write Java classes to model the real world objects and the relationship
between the classes.
A has-a relationship is when one class has an instance variable that
references an instance of another class. If class ClassA has an
instance variable that references an object of class ClassB, we can say
that each ClassA object has-a ClassB object, hence the description of
the relationship as has-a. In this case, class ClassA is the composite
class and class ClassB is the component class.
Some people find a useful way of visualizing this is using an object
reference diagram as shown in Figure 4.
Figure 3 Object reference diagram
Examples
You have seen examples of has-a relationships that take various forms,
but the example on which this question is based is that between
Painting and Artist, as discussed in Section 1 of the Unit 4
Composition Supplement.
With the download for this TMA we have included versions of these two
classes. These are slightly different to the versions described in the Unit
4 Composition Supplement, and demonstrate the level of detail you are
expected to provide in your solution.
What you need to do
You must write both a composite and a component class yourself.
We now describe in detail what you need to do to complete this
question.
• a.You are first required to write a short description, using the provided
table, in ordinary English, of the two classes you have identified
and how they relate to each other.Please read the guidance below
before you begin. You are advised to keep your example simple,
but you should be able to identify the following features:

at least three instance variables in your composite class, one of
which references an instance of your component class

at least two instance variables in your component class

appropriate methods in each class, including at least one method
that allows the composite class to communicate with the
component class in order to compute some value, for
example to provide an attribute of the composite class.
• Your description only needs to address the following requirements.

Which is the component class, and which is composite class?

What are the instance variables of each of these classes and
what are some examples of their values?

Identify and describe a method (not toString()) that allows the
composite class to communicate with the component class in
order to compute some value. (It is not sufficient to merely
copy the value returned by the component object. It must be
used in some kind of computation.)
Briefly describe other interesting features of the classes, but keep your
description short, as suggested in the example below. You don’t have to
describe all of the features of the classes.
EXAMPLE
Requirement
Your answer
1(a) Composite class
Painting
1(b) Component class
Artist
1(c) Relationship between the
two
A Painting has-an Artist
2(a) Composite class instance
variables and examples of use
artist, of type Artist (providing the has-a relationship)
title of type String, the title of the painting, e.g. “Girl
with a Pearl Earring”
yearPainted of type String, the year the painting was
painted, e.g. “1665”
insuredValue of type int, the insured value of the
painting, e.g.50000000
2(b) Component class
instance variables and
examples of use
name of type String, the name of the artist, e.g. “Vermeer”
3 Description of method (not
toString()) that allows the
composite class to
communicate with the
component class in order to
compute some value
Painting has a method isOldMasterWork()that
returns true if its Artist was born in or before 1780, so it
4 Other interesting features of
the class
Painting provides getter and setter methods for its instance
yearOfBirth of type String, the year the artist was born,
e.g. “1632”
computes a Boolean value based on the artist’s date of birth.
variables and also computes two further attributes:
alarmRequired and oldMasterWork – there are no
accompanying instance variables of these names.
Artist provides getters and setters for
its nameand yearOfBirth instance variables. Each class
includes a toString() method to help describe objects of
the class.
Within this project you are required to write the two classes that model your two kinds of object
as agreed with your tutor. Your classes must follow the specification below. Note that in addition
to the requirements set out in part a. you are asked to give your classes some additional
behaviours.
Resumé of requirements from part a.
o
One class (the composite class) should have an instance variable that references an
instance of the other class (the component class). This represents the has-arelationship
between the classes.
o
In addition to the instance variable described above, each class should have at least two
instance variables that represent attributes. It is not advisable to have more than the
minimum number of instance variables unless you are confident of what you are doing and
can spare the extra time.
o
The composite class should have a method, other than toString() that sends its
component object a message and makes use of the message answer in a computation of
some sort.
Further requirements
o
Each class should include at least one constructor. In most cases you will need only one
per class.
o
Each class should have, where appropriate, getter and setter methods for each of its
instance variables.
o
Each class should have a method toString() that returns a description of an object of
that class as a String that would be meaningful to a human reader.
o
The toString() method in the composite class must include at least one item of
information obtained from the component object by sending it a message.
o
None of your methods should make use of dialog boxes for any purpose.
o
You should comment your code appropriately and use appropriate access modifiers. Insert
your name, TMA02 Q2 and the date in the class description.
When you create each class in BlueJ you should start by deleting the example instance variable,
the line of code in the constructor that assigns 0 to the variable, and the sample method from
each class. You should also remove the comments related to the variable and sample method.

c.In the OUWorkspace write code to test the following methods from the composite class:
o
toString()
o
the method satisfying the third requirement in part a., that sends a message to the
component object and uses the returned value in a computation of some sort. You will
need at least two calls to this method in order to demonstrate its correctness. You will
also need to change the values of at least one of the instance variables in the
component object between the two calls.
If we were testing the Painting and Artist example, tests might follow this plan:
Create an Artist object artist1 with attribute values “Titian” and 1488.
Create a Painting object painting1 with artist1 as its composite object, and
attribute values “The Pastoral Concert”, 1509 and 100000000.
Execute the line:
painting1.toString();
The expected result would be:
The Pastoral Concert, painted by Titian in 1509, insured
for 100000000
Execute the line:
painting1.isOldMasterWork();
The expected answer is:
true
Now change the year of birth of the Artist object to 1900 by executing the line:
artist1.setYearOfBirth(1900);
And again, execute:
painting1.toString();
The expected result now would be:
The Pastoral Concert, painted by Titian in 1900, insured
for 100000000
Execute the line:
painting1.isOldMasterWork();
The expected answer is:
false
Copy and paste your test statements and the output from the display pane into
your Solution Document.
(6 marks)
Resources – painting example code
/**
*
* Objects of the Painting class model real-world paintings that have attributes
* representing title, year painted, insured value and whether or not an alarm
* is required.
*
* Painting is an example of a composite class.
*
* An object of the Painting class has-an object of the Artist class,
* which represents the artist who painted that painting.
*
* The value of alarmRequired is computed and true is returned
* if insuredValue is equal to or greater than 1000. This is an example
* of state-dependent behaviour.
* alarmRequired is not represented by an instance variable.
*
* @author M250 Module Team
* @version 2.1 April 2016
*/
public class Painting
{
//instance variables
private String title; // a painting has-a title, e.g. “Girl with a Pearl Earring”
private String yearPainted; // a painting has-a year painted, e.g. “1909”
private int insuredValue; // the insured value, e.g. 1000
private Artist artist; // a painting has-an artist of type Artist
/**
* Constructor for objects of class Painting
* allowing specification of all the required attributes.
* (We don’t check that all the data has been specified
* correctly however. E.g. theArtist could be null.)
*/
public Painting(String aTitle, String aYear, int aValue, Artist theArtist)
{
this.title = aTitle;
this.yearPainted = aYear;
this.insuredValue = aValue;
this.artist = theArtist;
}
/**
* Constructor for objects of class Painting,
* where we only know the painting title.
* (We might not know the other attribute values.)
* This is the minimum information required to construct
* a Painting object. In this case we chose to make
* the Artist object ’empty’.
*/
public Painting(String aTitle)
{
this.title = aTitle;
this.yearPainted = null; //null indicates an unknown year
this.insuredValue = 0; //defaults to 0 value
this.artist = new Artist();
}
//Setter methods are provided for all the instance variable
//so that these data can be altered in future if necessary,
//e.g. if the attribution of the artist changes.
/**
* Setter for a painting’s artist’s name.
* The name is an attribute of the component Artist object,
* not the Painting per se. So we have to forward the message
* to the component object.
*/
public void setArtistName(String aName)
{
this.artist.setName(aName);
}
//Here is an alternative example of a setter method for artist name
//that is more robust. This method first checks to see if there
//is an artist component that can be sent a message. If there isn’t
//one, it creates one.
//
public void setArtistName(String aName)
//
{
//
//this message needs to be forwarded to the component Artist object
//
//but the artist object might not exist yet, so we could check
//
if(this.artist == null) //Has the artist component been created?
//
{
//
//No, so we need to create a new Artist object and make
//the instance variable of the composite object to reference it
//
this.artist = new Artist(aName);
//
}
//
else
//
{
//
//We already have an artist object, so we just need to set
//
//its name by ‘forwarding’ the message to the artist component
//
this.artist.setName(aName);
//
}
//
}
/**
* Composition Supplement Exercise 3(b)
* Add getter and setter methods for the artist’s yearOfBirth,
* following the pattern set by setArtistName() above.
*/
/**
* Setter for a painting’s insured value.
*/
public void setInsuredValue(int aValue)
{
this.insuredValue = aValue;
}
/**
* Setter for a painting’s year painted.
*/
public void setYearPainted(String aYear)
{
this.yearPainted = aYear;
}
/**
* Getter for a painting’s title.
*/
public String getTitle()
{
return this.title;
}
/**
* Getter for a painting’s insured value.
*/
public int getInsuredValue()
{
return this.insuredValue;
}
/**
* Getter for a painting’s alarm requirement.
* This method displays state-dependent behaviour:
* The value returned depends on part of the state of the receiver.
* If the receiver’s insuredValue is greater than or equal to 1000 true is returned.
* Otherwise false is returned
*/
public boolean isAlarmRequired()
{
return this.getInsuredValue() >= 1000;
}
/**
* Getter for a painting’s year painted.
* This method returns “Unknown” if the year
* is not known (i.e. it has not been set).
*/
public String getYearPainted()
{
if (this.yearPainted == null)
{
return “Unknown”;
}
return this.yearPainted;
}
/**
* Getter for a painting’s artist’s name.
* This method returns “Unattributed” if the artist’s name
* is not known (i.e. it has not been set) and otherwise
* returns the artist’s name. Similar code could have
* been provided in the Artist class itself.
*/
public String getArtistName()
{
//The artist’s name is part of the component Artist object.
//Does the component object exist?
if (this.artist == null || this.artist.getName() == null)
{
//no artist or no artist name was set up
return ” Unattributed”;
}
//The artist component has been set up,
//so we can forward this message to the component object
return this.artist.getName();
}
/**
* This method returns true if the artist was born in or before
* 1780, and otherwise returns false.
*/public boolean isOldMasterWork()
{
return(Integer.parseInt(this.artist.getYearOfBirth()) < 1780); } /** * Returns a string describing this object. */ public String toString() { return "Title: " + this.title + "(" + this.yearPainted + ")" + "Artist " + this.getArtistName() + ". Alarm required: " + this.isAlarmRequired(); } } ARTIST EXAMPLE CODE /** * Artist represents an artist such as Van Gogh. * To keep things simple we just have a name and a year of birth. * In the context of the Painting example, this is a component class. * @author M250 Module Team * @version 2.1 April 2016 * */ public class Artist { // instance variables private String name; // an artist has-a name, e.g. "Vermeer" private String yearOfBirth; // an artist has-a year of birth, e.g. "1903" /** * zero-argument constructor: if we don’t know the artist’s attributes. */ public Artist() { this.name = null; //indicates artist name is unknown this.yearOfBirth = null; //indicates year of birth is unknown } /** * A constructor for objects of class Artist if we know their name * but not their year of birth. */ public Artist(String aName) { this.name = aName; this.yearOfBirth = null; //indicates year of birth is unknown } /** * A constructor for objects of class Artist * if we know their name and their year of birth. */ public Artist(String aName, String aYear) { this.name = aName; this.yearOfBirth = aYear; } /** * Setter for an artist's name. */ public void setName(String aName) { this.name = aName; } /** * Setter for an artist's year of birth. */ public void setYearOfBirth(String aYear) { this.yearOfBirth = aYear; } /** * Getter for an artist's name. It could * return a string such as "unattributed" * if the artist's name is not known, * but we have chosen to keep it simple here. */ public String getName() { return this.name; } /** * Getter for an artist's year of birth. * Keeping it simple, as in getName(). */ public String getYearOfBirth() { return this.yearOfBirth; } /** * Returns a description of this object as a string. */ public String toString() { return this.name + "(Born " + this.yearOfBirth + ")"; } /** * Composition Supplement Exercise 3(a) * Modify the toString() method above so that it * returns a useful message even if name and year of birth are null. */ } Purchase answer to see full attachment