The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Apr 2017 |
| Last Sign in: | 103 Weeks Ago, 3 Days Ago |
| Questions Answered: | 4870 |
| Tutorials Posted: | 4863 |
MBA IT, Mater in Science and Technology
Devry
Jul-1996 - Jul-2000
Professor
Devry University
Mar-2010 - Oct-2016
how do i add? "" -------------
The class
Triangle
must include the following constructors and methods: (If your class does not contain
any of the following methods, points will be deducted).
public Triangle (int s1, int s2, int s3)
- Sets up a triangle with the speci ed side lengths.
private int largest()
- Returns the length of the longest side of the triangle. This is a helper
method.
1
private int shortest()
Returns the length of the shortest side of the triangle. This is a helper
method.
public boolean is_equilateral()
- Determines whether a triangle is equilateral. If the longest side
is equal to the shortest side, then the triangle is equilateral.
public boolean is_isosceles()
- Determines whether a triangle is isosceles. Any (and at least) two
sides must be equal.
public boolean is_scalene()
- Determines whether a triangle is scalene. No two sides are equal.
public String toString()
- Prints the sides of the triangle
----------------------------------------------- ""
so far i have
class Trian {
int side1, side2, side3;
public Trian (int s1, int s2, int s3) {
s1 = side1;
s2 = side2;
s3 = side3;
}
private int largest();
private int shortest();
}
}
/*-------------------------------------------------------------------------/*-------------------------------------------------------------------------// AUTHOR: your name// FILENAME: title of the source file// SPECIFICATION: description of the program// TIME SPENT: how long it took you to complete the assignment//----------------------------------------------------------------------*/import java.util.Scanner;public class Assignment4{//===========================================================// Create and determine properties of various triangles.//===========================================================public static void main (String[] args){Scanner console = new Scanner(System.in);int num1, num2, num3;String another;// repeat until the user enter 'n'do{// get the inputSystem.out.println("Enter the sides of the triangle: ");num1 = console.nextInt();num2 = console.nextInt();num3 = console.nextInt();// create the TriangleTriangle myTriangle = new Triangle (num1, num2, num3);// print the TriangleSystem.out.println(myTriangle.toString() + " triangle:");//check the isoscelesif (myTriangle.is_isosceles())System.out.println("\tIt is isosceles");elseSystem.out.println("\tIt is not isosceles");//check the equilateralif (myTriangle.is_equilateral())System.out.println("\tIt is equilateral");elseSystem.out.println("\tIt is not a equilateral");//check the scaleneif (myTriangle.is_scalene())System.out.println("\tIt is scalene");elseSystem.out.println("\tIt is not scalene");// find if the user want to repeatSystem.out.println();System.out.print("Check another Triangle (y/n)? ");another = console.next();} while (another.equalsIgnoreCase("y"));}// method main
CSE110 - Arizona State UniversityTopics•Conditional and Loops (Chapter 4)•Implementing classes (Chapter 5)•Understanding and accessing instance variables (Chapter 8)•Implementing methods (Chapter 6)•Object construction (Chapter 6)•Constructors (chapter 8)•Encapsulation (Chapter 8)Coding Guidelines:•Give identifiers semantic meaning and make them easy to read (examples numStudents, grossPay, etc).•Keep identifiers to a reasonably short length.•User upper case for constants. Use title case (first letter is upper case) for classes. Use lower case withuppercase word separators for all other identifiers (variables, methods, objects).•Use tabs or spaces to indent code within blocks (code surrounded by braces). This includes classes,methods, and code associated with ifs, switches and loops. Be consistent with the number of spaces ortabs that you use to indent.•Use white space to make your program more readable.Part #1: Written Exercises (0 pts)NonePart #2 - Programming (20 pts)Your assignment is to write a class definition (not a program, there is no main method) namedTriangle(saved in a fileTriangle.java). A Triangle has 3 instance variables:int side1, side2, side3;The classTrianglemust include the following constructors and methods: (If your class does not containany of the following methods, points will be deducted).•public Triangle (int s1, int s2, int s3)- Sets up a triangle with the specified side lengths.•private int largest()- Returns the length of the longest side of the triangle. This is a helpermethod.1
Attachments: