Answered Essay: The instructions state that is it mandatory to use the provided driver to create y

****Note*****

The instructions state that is it mandatory to use the provided driver to create your class from. The driver is the code located at the end of these instructions. Please use that as the drive to create the working program.

Assignment #4

CSE110 – Arizona State University

Topics

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 with uppercase 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 or tabs that you use to indent.

Use white space to make your program more readable.

Part #1: Written Exercises (0 pts)

None

Part #2 – Programming (20 pts)

Your assignment is to write a class definition (not a program, there is no main method) named Triangle (saved in a file Triangle.java). A Triangle has 3 instance variables:

int side1, side2, side3;

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 specified side lengths.

private int largest() – Returns the length of the longest side of the triangle. This is a helper method.

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.

Save the Triangle class in a file called Triangle.java and use the following program stored in Assignment4.java which has the main method to create a new Triangle object and to test what kind of Triangle it is. A sample output is shown below.

Important

Your class should have exactly the method headers that are described or otherwise your class will not work with the test driver program (Assignment4.java) that is provided. You should never change the test driver program if the test driver is provided but instead make changes to Triangle class to make it work.

Helpful Hints

Work on it in steps – write one method, test it with a test driver and make sure it works before going on to the next method.

Always make sure your code compiles before you add another method.

Your methods should be able to be called in any order.

Triangle equal = new Triangle (6, 6, 6); //example of equilateral (and isosceles) triangle

Triangle isosceles = new Triangle (3, 7, 7); // example of isosceles triangle

Triangle scalene = new Triangle (4, 5, 6); // example of scalene triangle

Sample Outputs

Sample 1:

Enter the sides of the triangle:

3 4 5

4 5 triangle:

It is not isosceles

It is not a equilateral

It is scalene

Check another Triangle (y/n)? y Enter the sides of the triangle:

5 6

4 5 6 triangle:

It is not isosceles

It is not a equilateral

It is scalene

Check another Triangle (y/n)? y Enter the sides of the triangle:

4 4 4

4 4 4 triangle:

It is isosceles

It is equilateral

It is not scalene

Check another Triangle (y/n)? y Enter the sides of the triangle:

3 7 7

3 7 7 triangle:

It is isosceles

It is not a equilateral

It is not scalene

Check another Triangle (y/n)? n Press any key to continue . . .

****NOTE****

Here is the driver program that I was spoke about earlier at the begging of these instructions

Notes: Assignment4.java, the driver program, is completed for you. You just need to download it, save it as a .java file and in the same folder as your Tringale.java file and run it to test your Triangle class, which you must create.

/*————————————————————————-

/*————————————————————————-

// 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 input

System.out.println(“Enter the sides of the triangle: “);

num1 = console.nextInt();

num2 = console.nextInt();

num3 = console.nextInt();

// create the Triangle

Triangle myTriangle = new Triangle (num1, num2, num3);

// print the Triangle

System.out.println(myTriangle.toString() + ” triangle:”);

//check the isosceles

if (myTriangle.is_isosceles())

System.out.println(“tIt is isosceles”);

else

System.out.println(“tIt is not isosceles”);

 

//check the equilateral

if (myTriangle.is_equilateral())

System.out.println(“tIt is equilateral”);

else

System.out.println(“tIt is not a equilateral”);

 

//check the scalene

if (myTriangle.is_scalene())

System.out.println(“tIt is scalene”);

else

System.out.println(“tIt is not scalene”);

// find if the user want to repeat

System.out.println();

System.out.print(“Check another Triangle (y/n)? “);

another = console.next();

} while (another.equalsIgnoreCase(“y”));

} // method main

} // class Assignment4

Expert Answer

 

Triangle.java:

public class Triangle

{

int side1, side2, side3;

public Triangle (int s1, int s2, int s3)

{

this.side1 = s1;

this.side2 = s2;

this.side3 = s3;

}

int max = -100;

private int largest()

{

if(side1>side2)

{

max = side1;

}

else if(side2>=side1)

max = side2;

if(side3>max)

{

max = side3;

}

return max;

}

int min = 10000;

private int shortest()

{

if(side1<side2)

{

min = side1;

}

else if(side2<=side1)

min = side2;

if(side3<min)

{

min = side3;

}

return min;

}

public boolean is_equilateral()

{

/*System.out.println(max);

System.out.println(min);

if(max==min)

{

return true;

}

return false;*/

if(side1 == side2)

{

if(side2== side3)

{

return true;

}

}

return false;

}

public boolean is_isosceles()

{

if(side1 == side2)

return true;

else if(side3 == side2)

return true;

else if(side1 == side3)

return true;

return false;

}

public boolean is_scalene()

{

if(side1!=side2)

{

if(side2!=side3)

return true;

}

return false;

}

String s1=” “;

public String toString()

{

s1 += Integer.toString(side1);

s1 += ” “;

s1 += Integer.toString(side2);

s1 += ” “;

s1 += Integer.toString(side3);

return s1;

}

}

The output is attached:

Buy Essay
Calculate your paper price
Pages (550 words)
Approximate price: -

Help Me Write My Essay - Reasons:

Best Online Essay Writing Service

We strive to give our customers the best online essay writing experience. We Make sure essays are submitted on time and all the instructions are followed.

Our Writers are Experienced and Professional

Our essay writing service is founded on professional writers who are on stand by to help you any time.

Free Revision Fo all Essays

Sometimes you may require our writers to add on a point to make your essay as customised as possible, we will give you unlimited times to do this. And we will do it for free.

Timely Essay(s)

We understand the frustrations that comes with late essays and our writers are extra careful to not violate this term. Our support team is always engauging our writers to help you have your essay ahead of time.

Customised Essays &100% Confidential

Our Online writing Service has zero torelance for plagiarised papers. We have plagiarism checking tool that generate plagiarism reports just to make sure you are satisfied.

24/7 Customer Support

Our agents are ready to help you around the clock. Please feel free to reach out and enquire about anything.

Try it now!

Calculate the price of your order

Total price:
$0.00

How it works?

Follow these simple steps to get your paper done

Place your order

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.

HOW OUR ONLINE ESSAY WRITING SERVICE WORKS

Let us write that nagging essay.

STEP 1

Submit Your Essay/Homework Instructions

By clicking on the "PLACE ORDER" button, tell us your requires. Be precise for an accurate customised essay. You may also upload any reading materials where applicable.

STEP 2

Pick A & Writer

Our ordering form will provide you with a list of writers and their feedbacks. At step 2, its time select a writer. Our online agents are on stand by to help you just in case.

STEP 3

Editing (OUR PART)

At this stage, our editor will go through your essay and make sure your writer did meet all the instructions.

STEP 4

Receive your Paper

After Editing, your paper will be sent to you via email.