e Code: M257
Course Title: Putting Java to Work
Tutor Marked Assignment – Spring 16-17
Cut-off Date: 2nd May 2017 Total Marks:100 converted to
be out of 20
Contents: Page Number
TMA Instructions 2
Part 1 3
Part 2 6
Part 3 10
Plagiarism Warning:
As per AOU rules and regulations, all students are required to submit their
own TMA work and avoid plagiarism. The AOU has implemented
sophisticated techniques for plagiarism detection. You must provide all
references in case you use and quote another person's work in your TMA.
You will be penalized for any act of plagiarism as per the AOU's rules and
regulations.
Declaration of No Plagiarism by Student (to be signed and submitted
by student with TMA work):
I hereby declare that this submitted TMA work is a result of my own efforts
and I have not plagiarized any other person's work. I have provided all
references of information that I have used and quoted in my TMA work.
Name of Student:
Signature:
Date:
M257/TMA Page 2 2016/2017 Spring
TMA Instructions
This TMA assesses your work on Units 1-7 of M257. The marks allocated to
each part of a question are indicated in the margin. The total marks for each
question are shown at the beginning of each question.
For TMA questions that require coding, a number of marks may be awarded
for the style of your Java code. This means that we expect you to be
consistent and to follow good practice in the naming of identifiers and
layout.
In this TMA, you should do the following:
1- You should develop the required classes on NetBeans IDE.
2- You are required to create a Word file named
M257_TMA_Spring16_ID_Name. Then you are required to do the following:
• Copy and paste the codes of each part and the answers of the
theoretical questions, and add snap-shots for the output as it is
specified under each part.
The TMA for the course has been uploaded to the LMS. You should start
working on it right away. Please note the following when working on the
TMA:
• No group work is allowed for the TMA. Each student must submit
his/her own solution individually.
• Copying the answers from any source other than your own work will
be considered as plagiarism.
• Use your own words to answer essay questions.
• Read carefully the second page of the TMA for important
instructions.
After you finish solving the TMA, You have 2 submission links:
1- The Regular Submission Link: you need to submit to the regular
submission link a compressed file (e.g. zip file) which includes the
following: your NetBeans project folder (in Windows 7, you can find
this under Documents/NetBeansProjects),
2- The Turnitin submission Link: You need to submit a document
Word file including your answers to all questions according to the
guidelines on the cover page of the TMA.
Your TMA will not be marked if all the required files are not submitted on the
2 submissions’ links.
M257/TMA Page 3 2016/2017 Spring
Part 1 [80 Marks]
Part 1.1 [2 marks]
In this part you are required to:
1) Review Chapters 1, 2, 3, 4, 5 from M257 Material
2) Specify the version of JDK and IDE that you will use to solve this TMA and
create the TMA project. You are required to write the version of JDK and IDE
that he/she used.
3) You are required to create a project with name M257_TMA_Spring16_ID,
while you are required to write your student ID instead of ID in this package.
4) You are required to create a package with name Part1_ID, while you are
required to write your student ID instead of ID in this package.
Part 1.2 [10 marks]
Develop a public class MyDate to the following specifications:
• The class 3 private integer instance variables day, month, year
• The class has a multi-argument constructor that sets the value of its
instance variables to given values.
• The class has a zero-argument constructor that sets the value of its
instance variables to their default values. It should invoke its multi -
argument constructor in the same class.
• The class has the setter method setMyDate for its instance variables.
• The class has the getter method getMyDate for its instance variables in
order to return a string representation of the MyDate instance variables.
Part 1.3 [15 marks]
Develop a public class TicketID to the following specifications:
• The class has 2 private string instance variables flightNo, bookingRef.
• The class has 1 private instance variable of the class MyDate.
• The class has a multi-argument constructor that sets the value of its
instance variables to given values. It should create the object of MyDate
and set the values of day, month, and year using appropriate method.
• The class has a zero-argument constructor that sets the value of its
instance variables to their default values. It should invoke its multi -
argument constructor in the same class.
• The class has the setter method setTicketID for its instance variables.
• The class has the getter method getTicketID for its instance variables in
order to return a string representation of the TicketID instance variables.
Part 1.4 [15 marks]
Develop a public class Ticket to the following specifications:
• The class has 1 private instance variable of the class TicketID.
• The class has more 5 private fields of the tickets from your choice as
instance variables and you are required to declare their types according on
their data type contents.
• The class has a multi-argument constructor that sets the value of its
instance variables to given values. It should create the object of MyDate
and set the values of day, month, and year using appropriate method.
• The class has to override the Object’s toString() method in order to return
a string representation of the Ticket instance variables.
M257/TMA Page 4 2016/2017 Spring
Part 1.5 [20 marks]
Develop a public class Journey to the following specifications:
• The class has a private instance variable HashMap , which
represents a collection of Tickets of class Ticket.
• The class has a counter as a class variable that keeps the current number
of objects that will be added to the collection. You need to decide the correct
place to be able to increment it once an instance object is added into the
collection.
• The class has a zero-argument constructor that creates and initializes the
HashMap , instance object.
• The class has a public method void addTicket (Object) which adds an
instance object of ticket of TicketID class into the collection.
• The class has the method displayAll (). It returns either a string
representation of the HashMap collection with all its different types of tickets
or a string message that “NO tickets are available”.
• The class has a method void saveIntoFile(String). It saves the contents
of the HashMap collection of tickets into a file. The file name is the argument
of the method.
Part 1.6 [18 marks]
Develop a public class TestTicket to the following specifications: [15 marks]
1) You are required to declare and create as an instance object of class
Journey.
2) You are required to fill the above collection with 5 tickets.
3) You are required to print the tickets in the collection on the screen.
4) You are required to save the content of collection in a file.
Provide 1 screen shoot for the output of the class on screen [1.5 mark]
Provide 1 screen shoot for the output of the class on file [1.5 mark]
The output could be as:
0 Ticket Info: Flight No: SV 124 Booking Ref.: 123 NES Date: 29 : 1 : 2017
Passenger Name: Nesreen Seat NO: 51C
1 Ticket Info: Flight No: SV 124 Booking Ref.: 123AML Date: 29 : 1 : 2017
Passenger Name: Amal Seat NO: 31C
2 Ticket Info: Flight No: SV 124 Booking Ref.: 123JOD Date: 29 : 1 : 2017
Passenger Name: Joud Seat NO: 41C }
M257/TMA Page 5 2016/2017 Spring
Part 2 [20 marks]
Part 2.1 [1 mark]
1) Review Chapters 5, 6, 7 from M257 Material
2) You are required to create a package with name Part2_ID, while you are
required to write your student ID instead of ID in this package.
Part 2.2 [19 marks]
You are required to create a class with name TicketFrame.
You are required to copy and paste the codes in the attached file with the TMA on
this class.
You are required to check Figure 1 and to complete the missing sections in the
code as follows:
Section_1: you are required to declare and create as an instance object of class
Journey in Part1.
Section_2: you are required to create all the fields (JLabel & JTextField) of the
Journey and add them to panel1. These fields should match the instance objects
of class Journey in Part1.
Section_3: you are required to create the four buttons and add them to panel2.
Section_4: you are required to create the text area component and add them to
panel3.
Section_5: you are required to add the three panels into the container
Section_6: you are required to register the buttons with the listener event object.
Section_7: you are required to add the code of the listener event object as
follows:
• In Clear button: you are required to clear the contents of fields of the
Journey on the frame.
• In Add button: you are required to collect the contents of fields of the
Journey and then add them to the Journey instance object by using an
appropriate method.
• In Display button: you are required to display the contents of the Journey
instance object by using an appropriate method on the text area.
• In Save in File button: you are required to save the contents of the
Journey instance object in a file by using an appropriate method.
Provide 1 screen shoot for the output of the class [1 mark]
Figure 1
“End of the Questions”