[Solved]-Two Given Author Filename Assignment8java Specification Lab Letter Name Ta Closed Lab Cse Q37294514

These two are given
/*————————————————————————-// AUTHOR:// FILENAME: Assignment8.java// SPECIFICATION:// YOUR Lab Letter and Name of the TA for your Closed lab// FOR: CSE 110- homework #8 days and time of your class// TIME SPENT: how long it took you to complete the assignment//———————————————————————-*/import java.io.*;import java.util.*;public class Assignment8{ public static void main (String[] args) throws IOException { Scanner keyboard = new Scanner(System.in); int count=0, side1=0, side2=0, side3=0; System.out.println(“Please enter the filename: “); String fileName = keyboard.nextLine(); FileReader fr = new FileReader(fileName); BufferedReader inFile = new BufferedReader(fr); String line = inFile.readLine(); int size = Integer.parseInt(line); TriangleCollection triangles = new TriangleCollection(size); Triangle aTriangle; for(int i=0; i<size; i++) { line = inFile.readLine(); side1 = Integer.parseInt(line); System.out.println(“Side1: ” + side1); line = inFile.readLine(); side2 = Integer.parseInt(line); System.out.println(“Side1: ” + side2); line = inFile.readLine(); side3 = Integer.parseInt(line); System.out.println(“Side1: ” + side3); aTriangle = new Triangle(side1, side2, side3); if(aTriangle.isValid()) triangles.addToCollection(aTriangle); } inFile.close(); // Accept user option System.out.println(“Please enter a command or type “?” to see the menu:”); String command = keyboard.next(); while (command.charAt(0) != ‘q’) { switch (command.charAt(0)) { case ‘d’: // Display information for all the Triangles (one at a time) System.out.println(triangles.toString()); break; case ‘s’: // Sort all Triangles by perimeter triangles.sort(); System.out.println(triangles.toString()); break; case ‘f’: // Find a Triangle System.out.println(“Enter side one?”); int s1 = keyboard.nextInt(); System.out.println(“Enter side two?”); int s2 = keyboard.nextInt(); System.out.println(“Enter side three?”); int s3 = keyboard.nextInt(); // Call the method to search for a given Triangle // Method returns index in the array were Triangle is found Triangle key = new Triangle(s1, s2, s3); int index = triangles.search(key); // index = -1 implies Triangle was not found in the array if (index == -1) System.out.println(“Triangle doesn’t exist”); else System.out.println(triangles.getCollection(index).toString()); break; case ‘r’: // Remove a Triangle from the array System.out.println(“Enter side one? “); s1=keyboard.nextInt(); System.out.println(“Enter side two?”); s2 = keyboard.nextInt(); System.out.println(“Enter side two?”); s3 = keyboard.nextInt(); Triangle tobeRemoved= new Triangle(s1,s2,s3); // Call the method to remove a given Triangle from array collection boolean flag = triangles.remove(tobeRemoved); if (!flag) System.out.println(“Triangle not found “); else { System.out.println(“Triangle found and removed”); // Decrement number of Triangles in the array by 1 } break; case ‘?’: // Help menu System.out.println(“s: Sort Triangles by perimeters “); System.out.println(“f: Find a Triangle “); System.out.println(“r: Remove a Triangle “); System.out.println(“?: Help menu “); System.out.println(“q: Stop the program “); break; case ‘q’:// Stop the program break; default: System.out.println(“Illegal cammand “); } // End of switch //Prompt user to enter next choice. System.out.println(); System.out.println(“Please enter a command or type “?” to see the menu:”); command = keyboard.next(); } //End of while } // End of main }// End of class//————————————————————————-// FILENAME: solution to Assignment 5// DESCRIPTION: This class represents a Triangle// AUTHOR: F. Navabi// FOR: CSE 110 Assignment 4// DUE DATE:// Constructors://// public Triangle (int s1, int s2, int s3) {//// Methods://// private int largest ()// private int shortest ()// public boolean is_right ()// public boolean is_equilateral ()// public boolean is_isosceles ()// public boolean is_scalene ()////——————————————————————-public class Triangle { private int side1, side2, side3; //=========================================================== // Sets up a triangle with the specified side lengths. //=========================================================== public Triangle (int s1, int s2, int s3) { side1 = s1; side2 = s2; side3 = s3; } //=========================================================== // Returns the length of the longest side of the triangle. //=========================================================== private int largest () { int max = side1; if (side2 > max) max = side2; if (side3 > max) max = side3; return max; } // method largest //=========================================================== // Returns the length of the shortest side of the triangle. //=========================================================== private int shortest () { int min = side1; if (side2 < min) min = side2; if (side3 < min) min = side3; return min; } // method shortest //=========================================================== // Determines whether the triangle is a right triangle. //=========================================================== public boolean is_right () { if (side1*side1 + side2*side2 == side3*side3) return true; else if (side1*side1 + side3*side3 == side2*side2) return true; else if (side2*side2 + side3*side3 == side1*side1) return true; else return false; } //=========================================================== // Determines whether a triangle is equilateral. If the // longest side is equal to the shortest side, then the // triangle is equilateral. //=========================================================== public boolean is_equilateral () { int longest_side, shortest_side; longest_side = largest(); shortest_side = shortest(); return (shortest_side == longest_side); } // method is_equilateral //=========================================================== // Determines whether a triangle is isosceles. Any (and // at least) two sides must be equal. //=========================================================== public boolean is_isosceles () { boolean answer; if (side1 == side2) answer = true; else if (side1 == side3) answer = true; else if (side2 == side3) answer = true; else answer = false; return answer; } // is_isosceles //=========================================================== // Determines whether a triangle is scalene. //=========================================================== public boolean is_scalene() { boolean answer; if (side1 == side2) answer = false; else if (side1 == side3) answer = false; else if (side2 == side3) answer = false; else answer = true; return answer; } // method is_scalene //=========================================================== // Prints the sides of the triangle. //=========================================================== public String toString() { return (side1 + ” ” + side2 + ” ” + side3) ; } // method toString //=========================================================== // Determines whether the triangle is valid //=========================================================== public boolean isValid() { // check condition if ((side1 + side2 <= side3) || (side1 + side3<= side2) || (side2 + side3 <= side1)) return false; else return true; } //accessor methods for all three sides public int getSide1() { return side1;} public int getSide2() { return side2;} public int getSide3() { return side3; } //=========================================================== // Determines the perimeter of the triangle //=========================================================== public int findPerimeter() { return side1 + side2 + side3; }} // class TriangleThe class TriangleCollection must include the following constructor and methods. (If your class does not contain any of the following methods, points will be deducted. You can add more methods if you need to ublic TriangleCollection (int t constructs an empty TriangleCollection object with an array apacity specified by the integer parameter “arraySize” arraySize) ublic Triangle getCollection (int It returns the Triangle stored in specified index It returns the index of the Triangle specified by the parameter. If index) rivate int indexOf (Triangle c) he Triangle is not found, it returns 1. It is a helper method he method checks if the Triangle specified by the parameter xists in the array. Two Triangles are the same if all three sides re equal. For example side one of the first triangle is equal to ublic void ddToCollection (Triangle c) side one of the second triangle and etc. If not the same, the riangle is added to the array at the smallest available index. If he Triangle already exists in the array, the Triangle will not be dded he method checks if the Triangle specified by the parameter xists in the collection and if it does, it moves the index stored in ublic boolean remove (Triangle e last index (count-1) to where triangleToRemove was found triangleToRemove) nd changes he content at the last index to null and returns true. Otherwise it returns false method which sorts the array of Triangles based on the erimeter ublic void sort ) ublic int search (Triangle c) ublic String toString ) method that calls the indexOf and returns the index of the riangle, it should return -1 if the triangle doesn’t exist It returns all the Triangles in the collection as a String using the ormat below 13 45 Save the TriangleCollection class in a file called TriangleCollection.java and use the following program Assignment8java, which has the main method to test your class. You do not need to modify the test driver. Please study the code before writing your class TriangleCollection. Here is the description for each option ‘d’: prints all Triangles (calls the toString method) s’: prints Triangles sorted by perimeter : gets a Triangles’ sides from the user and prints the information relating to this Triangle r’: removes a Triangle from the collection, if it doesn’t exist it prints a message “: displays the help menu q’: quits Show transcribed image text The class TriangleCollection must include the following constructor and methods. (If your class does not contain any of the following methods, points will be deducted. You can add more methods if you need to ublic TriangleCollection (int t constructs an empty TriangleCollection object with an array apacity specified by the integer parameter “arraySize” arraySize) ublic Triangle getCollection (int It returns the Triangle stored in specified index It returns the index of the Triangle specified by the parameter. If index) rivate int indexOf (Triangle c) he Triangle is not found, it returns 1. It is a helper method he method checks if the Triangle specified by the parameter xists in the array. Two Triangles are the same if all three sides re equal. For example side one of the first triangle is equal to ublic void ddToCollection (Triangle c) side one of the second triangle and etc. If not the same, the riangle is added to the array at the smallest available index. If he Triangle already exists in the array, the Triangle will not be dded he method checks if the Triangle specified by the parameter xists in the collection and if it does, it moves the index stored in ublic boolean remove (Triangle e last index (count-1) to where triangleToRemove was found triangleToRemove) nd changes he content at the last index to null and returns true. Otherwise it returns false method which sorts the array of Triangles based on the erimeter ublic void sort ) ublic int search (Triangle c) ublic String toString ) method that calls the indexOf and returns the index of the riangle, it should return -1 if the triangle doesn’t exist It returns all the Triangles in the collection as a String using the ormat below 13 45 Save the TriangleCollection class in a file called TriangleCollection.java and use the following program Assignment8java, which has the main method to test your class. You do not need to modify the test driver. Please study the code before writing your class TriangleCollection. Here is the description for each option ‘d’: prints all Triangles (calls the toString method) s’: prints Triangles sorted by perimeter : gets a Triangles’ sides from the user and prints the information relating to this Triangle r’: removes a Triangle from the collection, if it doesn’t exist it prints a message “: displays the help menu q’: quits
Expert Answer
Answer to These two are given /*————————————————————————- // AUTHOR: // FILENAME: … . . .
OR

