JAC 444 Workshop 3 solution




5/5 - (3 votes)

The following workshop lets you practice basic java coding techniques, creating classes, methods,
using arrays, inheritance, polymorphism, Exceptional Handling.
Task – 1:
Design an abstract class named GeometricObject that contains:
• A private String data field named color (default value “white”)
• A private Boolean data field named filled.
• A no-arg constructor.
• A protected overloaded constructor GeometricObject(String color, boolean filled).
• The accessor and mutator methods for color and filled.
• An abstract method getArea()
• An abstract method getPerimeter()
Design another class named Triangle that contains:
❖ Triangle class must inherit the GeometricObject class.
❖ Three double data fields named side1, side2, and side3 with default values 1.0 to
denote three sides of the triangle.
❖ A no-arg constructor that creates a default triangle.
❖ A constructor that creates a triangle with the specified side1, side2, and side3.
❖ The accessor methods for all three data fields.
❖ A method named getArea() that returns the area of this triangle.
❖ A method named getPerimeter() that returns the perimeter of this triangle.
❖ A method named toString() that returns a string description for the triangle.
❖ The formulate to compute the area of the triangle is as follows:
JAC – 444 Semester ——
➢ Write a test program that prompts the user to enter three sides of the triangle, a
color, and a Boolean value to indicate whether the triangle is filled.
➢ The program should create a Triangle object with the given sides and set the color
and filled properties using the input.
➢ The program should display the area, perimeter, color, and true or false to indicate
whether it is filled or not.
Task – 2
Triangle class in Task – 1 (above), defines a triangle with three sides. In a triangle, the
sum of any two sides is greater than the other side. The Triangle class must obey/ follow to this
Design a TriangleException class, and modify the constructor of the Triangle class to
throw a TriangleException object if triangle is created with sides that violates the rule, as
/**Construct a triangle with the specified sides */
public Triangle(double s1, double s2, double s3)
throws TriangleException{
Hint: For not having any confusion you can copy your Triangle class from the Task – 1 and
rename it in Task – 2.
Write a test program that will create two Triangle class objects one with legal sides and
the other will Illegal side.
Note: Students are encouraged to design their own outputs for the both the tasks.
Continue to the next page…
JAC – 444 Semester ——
Workshop Header
Workshop #
Course: – Semester
Last Name:
First Name:

This assignment represents my own work in accordance with Seneca Academic Policy.
Code Submission Criteria:
Please note that you should have:
• Appropriate indentation.
• Proper file structure
• Follow java naming convention
• Document all the classes properly
• Do Not have any debug/ useless code and/ or files in the assignment
• Do not have everything in the main method.
• Have a separate TestClass with the main method in it.
• Check your inputs if the user is not entering garbage inputs.
• Use exceptional handling or other methods to let the user know if the inputs are
Deliverables and Important Notes:
All these deliverables are supposed to be uploaded on the blackboard once done.
• You are supposed to create video/ record voice/ detailed document of your running
solution. (50%)
o Screen Video captured file should state your last name and id, like
Ali_123456.mp4 (or whatever the extension of the file is)
o Record voice clip should also include a separate word file with the screen shots
of your program’s output, state your last name and id, like Ali_123456.mp3 (or
whatever the extension of the file is)
JAC – 444 Semester ——
o Detailed document should include screen shots of your output, have your name
and id on the top of the file and save the file with your last name and id, like
Ali_123456.docx (or whatever the extension of the file is)
• A word/ text file which will reflect on learning of your concepts in this workshop. Also
include the instructions on how to run your code. (30%)
o Should state your Full name and Id on the top of the file and save the file with
your last name and id, like Ali_123456.txt
• Submission of working code. (20%)
o Make sure your follow the “Code Submission Criteria” mentioned above.
o You should zip your whole working project to a file named after your Last Name
followed by the first 3 digits of your student ID. For example, Ali123.zip.
• Your marks will be deducted according to what is missing from the above-mentioned
submission details.
• Late submissions would result in additional 10% penalties for each day or part of it.
• Remember that you are encouraged to talk to each other, to the instructor, or to
anyone else about any of the assignments, but the final solution may not be copied from
any source.