Sie sind auf Seite 1von 7

M257 Page 1 2014/2015 Fall

Faculty of Computer Studies


Course Code: M257
Course Title: Putting Java to Work
Tutor Marked Assignment Fall 14-15
Cut-off Date 25/11/2014 Total Marks:100 converted to
be out of 20
Contents:
TMA Instructions 2
Part 1 3
Part 2 4
Part 3 5
Part 4 6
Part 5 7
Part 6 7
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 Page 2 2014/2015 Fall

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 programs in NetBeans IDE.
2- You must create ONE project for all TMA Parts in one package, the default location for
NetBeans projects under Windows 7 are: Documents/NetBeansProjects.
3- You are required to create a Word file named M257_TMA_Fall14-15_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.
Add two snap-shots for the output for 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 all your answers to all questions according to the guidelines on the cover
page of the TMA.

M257 Page 3 2014/2015 Fall

Part 1 [15 marks]
This assignment is an exercise in fundamental Java concepts such as: general classes, different
types of methods, and basic control structure. This question includes sub- parts, each of which is
simple if done according to the specifications given in the exercise.
You are required to review M257 Unit 2 to be able to solve Part 1.
Write a Java program according to the following specifications:

1) Write a static method displayMenu(), it does not return any result. It displays the
following lines on the screen.
1) Convert Celsius to Fahrenheit
2) Convert Fahrenheit to Celsius
3) Exit

Enter your choice:

2) Write a static method CtoF( double). It has one argument which is a double value
of the temperature in Celsius. The method converts this temperature and returns
the new value of the temperature in Fahrenheit.

3) Write a static method FtoC( double). It has one argument which is a double value
of the temperature in Fahrenheit. The method converts this temperature and returns
the new value of the temperature in Celsius.

4) The program should display the menu and ask the user to enter his choices to
convert, and then the program should ask the user to enter the temperature and
finally display the value of the temperature after the conversion.

5) The program should keep asking the user to enter his/her choice and it should stop
once the user enters 3 to exit.

6) You are required to search on the e-library to find the formulas that you have to use
to convert Celsius to Fahrenheit and vies versa.


M257 Page 4 2014/2015 Fall

Part 2 [18 marks]
This assignment is an exercise in fundamental Java concepts such as: classes, constructors, methods, basic
control structure, and Arrays. This question includes four sub- parts, each of which is simple if done
according to the specifications given in the exercise.
You are required to review M257 Units 1&3 to be able to solve Part 2.
Write the following Java programs according to their specifications:
(a) Develop a public class Item to the following specifications: (6 marks)
1) The class has two private instance variables: integer id and String name.
2) The class has a two-argument constructor to set its instance variables to given values.
3) The class has a zero-argument constructor to initialize the values of its instance variable.
It should invoke its two-argument constructor.
4) The class has the getter and setter methods of it instance variables.
5) The class overrides the objects toString() method in order to return a string representation
of a item instance object similar to format given below:
ID= , Name =

(b) Develop a public class StationaryItem to the following specifications: (6 marks)
1) The class inherits the Item class.
2) The class has one private instance variable: double size.
3) The class has a one copy instance variable for all instance objects countS, it keeps the
current number of StationaryItem that be created. You need to decide the correct place to be
able to increment this instance variable once an instance object is created.
4) The class has a multi-argument constructor to set its instance variables to given values.
This constructor should invoke the super-class constructor.
5) The class has a zero-argument constructor to initialize the values of its instance variable.
It should invoke its multi-argument constructor.
6) The class has setter and getter methods for the instance variable size.
7) The class overrides the objects toString() method in order to return a string representation
of a StationaryItem instance objects. It should invoke super class toString() method to get
the first part of the returned value to be similar to format given below:
ID= , Name = , Size=

(c) Develop a public class LabItem to the following specifications: (6 marks)
1) The class inherits the Item class.
2) The class has one private instance variable: String type.
3) The class has a one copy instance variable for all instance objects countL, it keeps the
current number of LabItem that be created. You need to decide the correct place to be able
to increment this instance variable once an instance object is created.
4) The class has a multi-argument constructor to set its instance variables to given values.
This constructor should invoke the super-class constructor.
5) The class has a zero-argument constructor to initialize the values of its instance variable. It
should invoke its multi-argument constructor.
6) The class has setter and getter methods for the instance variable type.
7) The class overrides the objects toString() method in order to return a string representation
of a LabItem instance objects. It should invoke super class toString() method to get the first
part of the returned value to be similar to format given below:
ID= , Name = , Type=
M257 Page 5 2014/2015 Fall

Part 3 [22 marks]
This assignment is an exercise in fundamental Java concepts such as: classes, constructors, methods, basic
control structure, and Arrays. This question includes four sub- parts, each of which is simple if done
according to the specifications given in the exercise.
You are required to review M257 Units 1, 3&5 to be able to solve Part 3.
(a) Develop a public class ItemHashMap to the following specifications: (12 marks)
1) The class has one private instance variable HashMap <Integer, Item>, which will represent
the collection of items from class Item.
2) The class has a one copy instance variable for all instance objects counter, it keeps the
current number of ItemHashMap that be created. You need to decide the correct place to be
able to increment this instance variable once an instance object is add into the array.
3) The class has a zero-argument constructor that creates and initializes the HashMap
<Integer, Item> instance object.
4) The class has a public method void addStationaryItem (StationaryItem sti) which is used
to add an instance object of StationaryItem in the collection.
5) The class has a public method void addLabItem (LabItem labi) which is used to add an
instance object of LabItem in the collection.
6) The class has a public String displayItemsInArray() which returns either a string
representation of the HashMap of items and all its different types of items or a string
message that NO items are available.

(b) Develop a public class TestItemHashMap to the following specifications: (10 marks)
1) The class has a static method displayMenu(). It has no arguments and it does not return any
value. It display the following lines on the screen
=====================
1- Add Stationary Item
2- Add Lab Item
3- Display all items
4- Exit
Enter your choice:
2) The class has a static main method.
3) The class has a public instance object of ItemHashMap class.
4) The class will keep asking the user to add Stationary Items or add Lab Items or display all
items in the ItemHashMap instance object. It should stop when the user choose 4 to exit.
5) At the end, the class should print the number of items in the ItemHashMap instance object
and the number of Stationary Items or add Lab Items as well.

M257 Page 6 2014/2015 Fall

Part 4 [10 marks]
You are required to review M257 Units 1, 3&5 to be able to solve this Part.
Question 1: it depends on Part 3 (4 marks)
1.1- Suppose we modified the class Item and become an abstract class, write the header of the
class.

1.2- After the above modification, is it legal to write the following statements in the
TestItemHashMap class? Explain your answer.
Item item1;
Item item2= new Item ();


Question 2: it depends on Part 3 (4 marks)
2.1- Suppose we modified the class Item and implement a Powerful interface. Write the header
of the class.

2.2- What if any the modifications are needed, if the following methods are added to the
Powerful interface? Explain your answer.
void getReadytoShip();
void received();

(2 marks) will be given for the 2 snap-shots.
M257 Page 7 2014/2015 Fall

Part 5 [25 marks]
This assignment is an exercise in fundamental Java concepts such as: classes, constructors, methods,
building GUI interfaces, writing event driven programs, along with using flow control structures, This
question includes one part, which is simple if done according to the specifications given in the exercise.
You are required to review M257 Units 6&7 to be able to solve Part 5.

Develop a public class ConverterGUI to the following specifications:
You are required to build a GUI interface ConverterGUI to be able to input the
temperature in Fahrenheit or Celsius and convert it vies versa.
The GUI interface should appear as in Figure 1 below, according to the following
specifications:
Set its size to 400x200.
Set its title to Converter.
The frame use setDefaultCloseOperation() method to close the widow and
terminate the program when the user click on close button
The frame has Border Layout. It consists of three main Panels, North, Centre, and
South.
It includes 2 labels (Fahrenheit & Celsius ), 2 text-fields to input the temperature
It includes 3 buttons:
Convert Fahrenheit to Celsius button: it takes the value of the temperature
in the text-field of Fahrenheit and convert it to Celsius and display the value
in Celsius text-field.
Convert Celsius to Fahrenheit button: it takes the value of the temperature in
the text-field of Celsius and convert it Fahrenheit to and display the value in
Fahrenheit text-field.
Clear button: it clears the values in the 2 text-fields.

Part 6 [10 marks]
You are required to review M257 Units 1, 3, 4 &5 to be able to solve this Part.
Question 1: it depends on Part 5 (8 marks)

1.1- Suppose that the user entered M in any of the text fields, what will happen? Explain the
problem.

1.2- How do you deal with this problem? Explain your answer

1.3- you are required to modify your codes in Part 5 to avoid this problem
(2 marks) will be given for the 2 snap-shots.
End of Assessment

Das könnte Ihnen auch gefallen