Sale!

Principles of Software Development Lab Assignment #1:

$30.00

Rate this product

ENSF 607 – Principles of Software Development
Lab Assignment #1
Exercise – 1: Drawing a Class Diagram (6 Marks)
What to do: Download files Point.java, Line.java, Polygon.java, and
Drawing.java from D2L. These files belong to a Java program that you will use in this exercise
and the following exercise (Exercise 2).
You don’t need to write any java code in this exercise, but you have to read the given files
carefully, and draw a UML class-diagram for the classes in these files, using tools such as StarUML
or Microsoft Visio (if you have already installed them on your computer), or online drawing tools
such as: https://www.draw.io or trial version of https://www.gliffy.com/ .If you are using any tool
you need to be able to save your work as .jpg file or take screenshot of your design.
Note: in this simple exercise, you don’t need to show the attributes and the operations of each
class. Just focus on the relationship among the classes.
What to Hand in: Insert your class diagram into the document and save it as a PDF file.
Exercise – 2: Running a Java Program with Multiple Files (6 Marks)
What to Do: Run the files Point.java, Line.java, Polygon.java, and
Drawing.java that you downloaded for Exercise-1, using one of the following methods:
• To run this program from command line, enter the following command:
and, then run your program using the following command:
• If you are using Eclipse or any other IDE (I advise using an IDE for this lab and all future
labs), you have to first create a Java-project and then import these files under your
project. When all the files are imported, run the project and see the program’s output in
the console window. (Note: You are also free to choose other IDEs such as NetBeans,
IntelliJ, etc.)
In Lab (52 marks)
Page 4 of 11
The lines in polygon 1 are:
Line 1: starts at (20, 30), and ends at (50, 100)
Line 2: starts at (50, 100), and ends at (105, 30)
Line 3: starts at (105, 30), and ends at (20, 30)
The perimeter of the polygon 1 is 250.18:
The lines in polygon 2 are:
Line 4: starts at (120, 130), and ends at (150, 200)
Line 5: starts at (150, 200), and ends at (200, 130)
Line 6: starts at (200, 130), and ends at (120, 130)
The perimeter of the polygon 2 is 242.18:
The lines in polygon 3 are:
Line 7: starts at (320, 330), and ends at (250, 400)
Line 8: starts at (250, 400), and ends at (400, 330)
Line 9: starts at (400, 330), and ends at (320, 330)
The perimeter of the polygon 3 is 344.52
The program is supposed to show the information about three polygons (in this example three
triangles), but it doesn’t, because the toString() methods of three of the classes in the given
files are incomplete. Your job in this exercise is to complete the missing code in the three
toString() methods. If you complete the definition of the toString() methods properly,
the program should display the following output on the console window:
What to hand in: Submit all the java files in this project. ZIP the files together and submit
Page 5 of 11
Exercise – 3 – Identifying classes and drawing class diagram (15 Marks)
In this exercise, you are going to:
Task 1: Determine what classes should be used and identify attributes and methods for each
class from the requirement description.
Task 2: Draw the class diagram using UML notations.
Requirement description – A small retail shop that sells tools requires an application to manage
inventory of different types of toolsitsells. The store owner wantsto be able to modify the store’s
inventory by adding new tools, and deleting tools. The owner also wants to be able to search the
inventory for tools by tool name, and by tool id. Currently, the information about tools available
in the shop and suppliers is stored in two text files which are given on D2L: items.txt, and
suppliers.txt.
The order and type of data given in these files are:
items.txt:
(id; description or name of tool; quantity in stock; price;
supplier id number)
Suppliers.txt:
(id; company name; address; sales contact)
The owner would also like to check the quantity of each item in stock. If the quantity of each item
in stock goes below 40 items, then the program should automatically generate an order line for
that item. The order line will have the supplier information and the required quantity for that item
(The default quantity ordered by each item = 50 – number of existing items). All items ordered
each day should be included in an order which has a randomly generated 5-digit id, and the date
that was ordered. The ordershould be written to a text file called orders.txt. A sample order
file is as follows:
Page 6 of 11
**********************************************************************
ORDER ID: 15181
Date Ordered: January 18, 2016
Item description: Nic Nacs
Amount ordered: 250
Supplier: Widgits Inc.
Item description: Twinkles Inc.
Amount ordered: 50
Supplier: Air Drills
**********************************************************************
ORDER ID: 26490
Date Ordered: January 26, 2016
Item description: Wog Wits
Amount ordered: 100
Supplier: Winork Manufacturing Inc.
**********************************************************************
What to submit: Submit a PDF file that contains your class diagram for the above problem.
Page 7 of 11
Exercise- 4: From A Model to an Implementation (25 Marks)
What to Do: In this exercise, you are going to implement a Tic-Tac-Toe game (text-based). Here
is the class diagram for this project.
Figure 1 Class diagram for Tic-Tac-Toe
Following classes are given to you. Download them from D2L:
• Class Board.java that includes most of the games logic,
• Class Game.java that is the starting point of the program,
• Interface Constants.java that contains a few constant variables
Therefore, what is missing is the definition of the two other classes: class Referee, and class
Player.
Task 1: One of your jobs in this exercise is to define and implement these classes.
Task 2: Your other job in this exercise is to add Javadoc comments to ALL classes and
interfaces in this program, using the guidelines posted on the D2L. You are strongly advised
to start with the documentation of the given classes(class Board and class Game).
Page 8 of 11
This will help you to understand how these classes work before you start writing code for
the other two classes.
In the following section, further details about responsibilities of classes Referee and Player
is given.
Class Referee: This class, in addition to its constructor, must have a method called
runTheGame that callsthe setOpponent method of class Player to set the opponents of
the X- and O- players. Then, initiates the game by displaying the board, and calling the play
method for the X-Player who is always the first player.
Class Player: Each Player object must have a name, a mark (‘X’ or ‘O’), and should
know its opponent and the board. And, in addition to its constructor and its getter and setter
functions as needed, it must have at least the following three methods:
• Method setOpponent() that connects the other player to this player.
• Method play() that calls method makeMove(), as long as methods xWin() and
oWin(), and isFull() in class Board returnsfalse (If any of these conditions change
(turnstrue), it announcesthatthe game is over and either displaysthe name of the winner
of the game or indicates that the game ended in a ‘tie’). Then, displays the board after
each move, checks for the winner and then passes the turn to the other player.
• Method makeMove() that asks the player to make a move by entering the row and
column numbers, and puts a ‘X’ or ‘O’ mark on the board, by calling method addMark in
class Board.
• You may add additional methods, if needed.
What to hand in: As part of your post-lab report (PDF format), submit the copy of your java files
with the javadoc comments, and a sample run of your program output. In addition to the
above-mentioned report you need to submit two zipped files:
• A zipped file containing the HTML files generated by javadoc tool
• A zipped file containing your actual source codes:
o Game.java
o Referee.java
o Board.java
o Player.java
Page 9 of 11
o Constant.java
What to submit: Submit all your java docs for this project.
Appendix A
The Program’s Sample Run: To give you a better idea about how the program is supposed to
work, a sample run of the program and its dialog with players is given on the next two pages.
Note: User inputs are in red.
Please enter the name of the ‘X’ player: Mike
Please enter the name of the ‘O’ player: Judy
Referee started the game…
col 0 col 1 col 2
row 0
row 1
row 2
Mike, what row should your next X be placed in? 1
Mike, what column should your next X be placed in? 1
col 0 col 1 col 2
row 0
row 1 X
row 2
Page 10 of 11
Judy, what row should your next O be placed in? 2
Judy, what column should your next O be placed in? 0
Mike, what row should your next X be placed in? 0
Mike, what column should your next X be placed in? 0
col 0 col 1 col 2
row 0 X
row 1 X
row 2 O
Judy, what row should your next O be placed in? 2
Judy, what column should your next O be placed in? 2
col 0 col 1 col 2
row 0 X
row 1 X
row 2 O O
Mike, what row should your next X be placed in? 0
Mike, what column should your next X be placed in? 1
col 0 col 1 col 2
col 0 col 1 col 2
row 0
row 1 X
row 2 O
Page 11 of 11
row 0 X X
row 1 X
row 2 O O
Judy, what row should your next O be placed in? 2
Judy, what column should your next O be placed in? 1
col 0 col 1 col 2
row 0 X X
row 1 X
row 2 O O O
THE GAME IS OVER: Judy is the winner!
Game Ended …

Scroll to Top