Description
1. (14 points) Write a Java program that performs calculations related to triangles. A tringle is defined by
the (x, y) coordinates of its three corners. The program should prompt a user for the corner point
coordinates. Then, the program performs the computations of the following properties of a given
triangle:
The lengths of all sides
The perimeter
The area
Finally, the program should produce all values of a triangle’s properties rounded to two decimal
places and display them nicely on the screen.
Use the following formula for calculating the side length between two vertices A(x1, y1) and
B(x2, y2):
𝑨𝑩 = √(𝒙𝟐 − 𝒙𝟏
)
𝟐 + (𝒚𝟐 − 𝒚𝟏
)
𝟐
Let X, Y and Z be the lengths of the sides of a triangle, the triangle’s perimeter P is calculated
as:
𝑷 = 𝑿 + 𝒀 + 𝒁
One method for finding the area of a triangle is the Heron’s formula given by:
𝑨𝒓𝒆𝒂 = √𝑯(𝑯 − 𝑿)(𝑯 − 𝒀)(𝑯 − 𝒁) , where 𝑯 = 𝑷/𝟐
2. (6 points) Write a Java program that reads an 8-bit binary number from the keyboard as a string and
then converts it into decimal. For example, if the input is “01001101”, the output should be “77”. (Hint:
Break the string into substrings and then convert each substring to a value for a single bit (i.e., 0 or 1).
If the bits from right to left are b0, b1, …, b7; the decimal equivalent value is b0 + 2b1 + 4b2 + 8b3 +
16b4 + 32b5 +64b6 + 128b7.)
Report and Program Submission Guidelines
It is expected that your report to be well written and organized. The report reflects your understanding of
the assignment and its solution. So, you must assume that your marks assigned to the report part is related
to how is the report is written and presented. All reports must be submitted in PDF format. Each assignment
should contain the following:
1. Report
1.1. Title page with your name, assignment number and the day you are actually submitting this report
(Not the assignment due date).
1.2. A brief description of your solution of each problem of the assignment, you can also explain your
solution using a pseudocode. Number your descriptions according to the problem numbers.
1.3. A comprehensive set of snapshots showing the inputs submitted, outputs obtained in the case of a
successful output or a failure, including required output formatting, prompts, and messages.
2. Submission Procedure:
2.1. Java source filesthat contain yoursolutions. They must be a “*.java” files. Source programsshould
contain meaningful comments and variable names.
2.2. Please zip both the PDF document with the source codes and submit one zipped file. Please name
your zipped file as “HWx_firstname_lastname.zzz”. Where, “firstname” and “lastname” refer to
your first and last names, “x” refers to the homework number (e.g., 1, 2, etc), “zzz” refers to the
file name extension for the software used for archiving.
2.3. Submissions after the due date are accepted with a penalty of 25% per day (weekend days
are counted as one-day delay).
Grading Table
Problem Item Points
Problem 1
Report (Description of solution) 1
Output snapshots 1
Java Source
Code
Implementation
Style (indentation, comments, and
meaningful variable names)
2
Correct calculation 6
Input/Output & formatting 4
Problem 2
Report (Description of solution, and pseudocode) 1
Output snapshots 1
Java Source
Code
Implementation
Style (indentation, comments, and
meaningful variable names)
1
Correct calculation 2
Input/Output 1
Total 20