Question

In: Computer Science

Write a simple java class that contains the following three methods: 1. isosceles -- accepts 3...

Write a simple java class that contains the following three methods:

1. isosceles -- accepts 3 integers which represent the sides of a triangle. Returns true if the triangle is isosceles and false otherwise.

2. perimeter - accepts 3 integers that represent the sides of a triangle and returns the perimeter of the triangle.

3. area -- accepts 3 integers, which represent the sides of a triangle and calculates and returns the area of the triangle. Hint: use Heron's formula. You must call the perimeter method from this method.

4. maxSide -- accepts 3 integers, which represent the sides of a triangle. Returns the maximum side.

Solutions

Expert Solution

Code:

import java.util.Scanner;
import java.lang.Math;
class triangle
{
   public boolean isosceles(int a,int b,int c)
   {
       if(a==b||b==c||c==a)
       {/*If 2 sides are equal then we return true*/
           return true;
       }
       else
       {/*Else we return false*/
           return false;
       }
   }
   public int perimeter(int a,int b,int c)
   {/*Return the perimeter which is sum of sides*/
       return a+b+c;
   }
   public double area(int a,int b,int c)
   {/*Area */
       double s=perimeter(a,b,c)/2;/*Calculating s*/
       return Math.sqrt(s*(s-a)*(s-b)*(s-c));/*Returning the area*/
   }
   public int maxSide(int a,int b,int c)
   {
       return (a>b && a>c)?a:(b>c)?b:c;/*Returning the max side*/
   }
   public static void main(String[] args)
   {
       int a,b,c;
       Scanner scnr=new Scanner(System.in);/*Scanner object*/
       System.out.print("Enter the three sides of the triangle:");
       a=scnr.nextInt();
       b=scnr.nextInt();
       c=scnr.nextInt();/*Reading the three sides of the triangle*/
       triangle tr=new triangle();/*Triangle object tr*/
       if(tr.isosceles(a,b,c))
       {/*If isosceles we print isoscles triangle*/
           System.out.println("The triangle is a isosceles triangle");
       }
       else
       {/*else we print not a isoscles triangle*/
           System.out.println("The triangle is not a isosceles triangle");
       }
       System.out.println("Area of the triangle:"+tr.area(a,b,c));/*Printing the area*/
       System.out.println("Maximum side:"+tr.maxSide(a,b,c));/*Printing the maximum side*/
   }


}

Output:

Indentation:


Related Solutions

Write a Calculate class which contains methods that accepts two integers as arguments and return the...
Write a Calculate class which contains methods that accepts two integers as arguments and return the results of Addition, Subtraction, Division and Multiplication. Call these methods though main()and print the results.
Question 3 A java source module contains the following class with the static methods main and...
Question 3 A java source module contains the following class with the static methods main and procedure1, and the instance method procedure2 (assume given the bodies of procedure1 and procedure2): public class TestQuestion3             {                         static int result, num1 = 10;                         public static void Main( String [ ] args )                         {                                     int [ ] list1 =   { 2, 4, 6, 8, 10}, list2;                                     .    .    .                         }                         static void procedure1( void )                         {                                     .   .   .                         } void procedure2( void )...
A Java question. Write the class Staff. It contains methods that manipulate an ArrayList of Strings...
A Java question. Write the class Staff. It contains methods that manipulate an ArrayList of Strings representing the names of staff members. The constructor takes an ArrayList of String names as a parameter. In addition to the constructor, you need to implement the following methods The methods 1. public boolean equals(Staff other) - Determines if the other Staff contains all the same elements in the same order as this Staff 2. public boolean sameContents(Staff other) - Determines if the other...
Write a class called VLPUtility with the following static methods: Java Language 1. concatStrings that will...
Write a class called VLPUtility with the following static methods: Java Language 1. concatStrings that will accept a variable length parameter list of Strings and concatenate them into one string with a space in between and return it. 2. Overload this method with two parameters, one is a boolean named upper and one is a variable length parameter list of Strings. If upper is true, return a combined string with spaces in upper case; otherwise, return the combined string as...
write a java code to represent a sales class as follows: 1- The Sales class contains...
write a java code to represent a sales class as follows: 1- The Sales class contains the names of sellers (strings) and the sales/seller/day (matrix of integers). Assume the number of sellers is set dynamically by the constructor and that the sellers work 6 days/week. Example: names/days 0 1 2 3 4 5 Ali 30 5 89 71 90 9 Ahmad 15 81 51 69 78 25 Omar 85 96 7 87 41 54 The class should contain the following...
Write a java program that contains 3 overloaded static methods for calculating area of a circle,...
Write a java program that contains 3 overloaded static methods for calculating area of a circle, area of a cylinder and volume of a cylinder. Also create an output method which uses JOptionPaneto display instance field(s) and the result of the computing. Then code a driver class which will run and test calling each of these overloaded methods with hard-coded data and display the data and the result of the calculation by calling output method. Thanks!!
Write a Java class called CityDistances in a class file called CityDistances.java.    1. Your methods...
Write a Java class called CityDistances in a class file called CityDistances.java.    1. Your methods will make use of two text files. a. The first text file contains the names of cities. However, the first line of the file is a number specifying how many city names are contained within the file. For example, 5 Dallas Houston Austin Nacogdoches El Paso b. The second text file contains the distances between the cities in the file described above. This file...
write program that develop a Java class Dictionary to support the following public methods of an...
write program that develop a Java class Dictionary to support the following public methods of an abstract data type: public class Dictionary { // insert a (key, value) pair into the Dictionary, key value must be unique, the value is associated with the key; only the last value inserted for a key will be kept public void insert(String key, String value); // return the value associated with the key value public String lookup(String key); // delete the (key, value) pair...
3. Write a java method that accepts a binary number and converts it to decimal then...
3. Write a java method that accepts a binary number and converts it to decimal then display the result. For Example: (110)2 = (6)10 (2 2 *1)+ (21 *1) + (20*0) = 6 Additional task: write a method that accepts a decimal and converts it to binary. i need to solve it as soon as and i will upvote you directly
Design a Geometry class with the following methods: * A static method that accepts the radius...
Design a Geometry class with the following methods: * A static method that accepts the radius of a circle and returns the area of the circle. Use the following formula: Area=?r^2 * A static method that accepts the length and width of a rectangle and returns the area of the rectangle. Use the folliwng formula: Area = Length x Width * A static method that accepts the length of a triangle's base and the triangle's hight. The method should return...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT