{"id":770,"date":"2017-05-05T08:42:38","date_gmt":"2017-05-05T08:42:38","guid":{"rendered":"http:\/\/www.testingdocs.com\/questions\/?p=770"},"modified":"2024-12-14T04:32:38","modified_gmt":"2024-12-14T04:32:38","slug":"write-a-program-to-determine-the-triangle-type-the-numbers-would-form","status":"publish","type":"post","link":"https:\/\/www.testingdocs.com\/questions\/write-a-program-to-determine-the-triangle-type-the-numbers-would-form\/","title":{"rendered":"Program to find the Triangle Type with the numbers?"},"content":{"rendered":"<h2>Program to find the Triangle Type with the numbers?<\/h2>\n<p>Given three numbers a,b,c. Write a class and a driver program to determine the Triangle Type the numbers would form.<\/p>\n<p>Let us write a program to determine the type of Triangle given the sides. We know that, if all the sides are equal the triangle is called the Equilateral triangle.\u00a0 If any two sides are equal the triangle is called Isosceles Triangle etc.<\/p>\n<h3>Tools Used<\/h3>\n<p>Tools and the Environment used to develop the program are as follows.<\/p>\n<ul>\n<li>JDK<\/li>\n<li>BlueJ IDE<\/li>\n<li>Windows 10<\/li>\n<\/ul>\n<h3><strong>Triangle Class<\/strong><\/h3>\n<p>In this tutorial, We will use BlueJ Editor to code the Triangle class. The Main class is the driver. It instantiates the Triangle class. The Triangle class determines the triangle type and prints the result on the console.<\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-758 size-full\" title=\"Triangle Type\" src=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Main-Triangle-Class.png\" alt=\"Triangle Type\" width=\"1295\" height=\"620\" srcset=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Main-Triangle-Class.png 1295w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Main-Triangle-Class-300x144.png 300w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Main-Triangle-Class-768x368.png 768w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Main-Triangle-Class-1024x490.png 1024w\" sizes=\"auto, (max-width: 1295px) 100vw, 1295px\" \/><\/p>\n<p>&nbsp;<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">public class Triangle {\r\n\r\nprivate int a;\r\n private int b;\r\n private int c;\r\n\r\n\/\/ Constructor \r\n \/\/ example : Triangle triangle = new Triangle(6,5,7);\r\n public Triangle(int s1, int s2, int s3) {\r\n this.a = s1;\r\n this.b = s2;\r\n this.c = s3;\r\n }\r\n \r\n \r\n public String findTriangleType() {\r\n String triangleType=\"\"; \r\n \/\/ sides should be positive \r\n if (a &lt;= 0 || b &lt;= 0 || c &lt;= 0) {\r\n System.out.println(\"At least one side is negative\\n\"); \r\n }\r\n \r\n \/\/ Check for side length\r\n if ((a + b &lt;= c) || (a + c &lt;= b) || (b + c &lt;= a)) {\r\n System.out.println(\"Please check. Given sides do not form a triangle\\n\");\r\n } \r\n  \r\n if ((a == b) &amp;&amp; (b == c)) {\r\n triangleType = \"Equilateral Triangle\";\r\n } else if (( a == b) || (b == c) || (a == c)) {\r\n triangleType = \"Isosceles Triangle\";\r\n } else {\r\n triangleType = \"Scalene Triangle\";\r\n } \r\n \r\n return triangleType; \r\n }\r\n\r\n}<\/pre>\n<p>&nbsp;<\/p>\n<h3>Main Class<\/h3>\n<p>This is driver class with the main method.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">public class Main {\r\n\r\npublic static void main(String[] args) {\r\n Triangle triangle = new Triangle(6, 8, 8);\r\n System.out.println(\"Given Triangle type:\"+ triangle.findTriangleType());\r\n }\r\n\r\n}<\/pre>\n<p>&nbsp;<\/p>\n<p>Compile and run the program. Using BlueJ IDE, you can even inspect the object and execute the methods on the objects interactively.<\/p>\n<h3>Inspecting the Triangle class\/object.<\/h3>\n<p>Once you have written the class, you can choose Inspect menu option to inspect the class. Right click on the Triangle class &gt;&gt; Inspect option.<\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-664 size-full\" title=\"Triangle Type\" src=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Inspecting-Triangle-class.png\" alt=\"Triangle Type\" width=\"1288\" height=\"730\" srcset=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Inspecting-Triangle-class.png 1288w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Inspecting-Triangle-class-300x170.png 300w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Inspecting-Triangle-class-768x435.png 768w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Inspecting-Triangle-class-1024x580.png 1024w\" sizes=\"auto, (max-width: 1288px) 100vw, 1288px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>Java Tutorial on this website:<\/p>\n<p><strong><a href=\"https:\/\/www.testingdocs.com\/java-tutorial\/\">https:\/\/www.testingdocs.com\/java-tutorial\/<\/a><\/strong><\/p>\n<p>For more information on Java, visit the official website :<\/p>\n<p><strong>https:\/\/www.oracle.com\/in\/java\/<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Program to find the Triangle Type with the numbers? Given three numbers a,b,c. Write a class and a driver program to determine the Triangle Type the numbers would form. Let us write a program to determine the type of Triangle given the sides. We know that, if all the sides are equal the triangle is [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[],"class_list":["post-770","post","type-post","status-publish","format-standard","hentry","category-java-programs","has-post-title","has-post-date","has-post-category","has-post-tag","has-post-comment","has-post-author",""],"_links":{"self":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts\/770","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/comments?post=770"}],"version-history":[{"count":8,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts\/770\/revisions"}],"predecessor-version":[{"id":26418,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts\/770\/revisions\/26418"}],"wp:attachment":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/media?parent=770"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/categories?post=770"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/tags?post=770"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}