
Java only
Design, implement and test a Java class that processes a series of triangles. For this assignment, triangle data will be read from an input file and the program’s output will be written to another file. The output file will also include a summary of the data processed. You must use at least one dialog box in this program.
The data for each triangle will be on a separate line of the input file, with the input data echoed and the results referred to by the line number (see example).
On initialization, the program will prompt the user for both an input and an output file. If a non-existent input file is specified, the appropriate exception must be handled, resulting in an error message. For the exception case, re-prompt the user for the correct input file. Once the I/O file is specified, the program will read in and process all the entries in the file. The output of the program will be written to the specified output file and echoed to the console.
The program will evaluate each line and determine the validity of the triangle. If valid, the program will output a summary line for the triangle calculation. If invalid, the program will output a description of the error found in the entry. Your program must be robust and handle situations where all the triangle inputs are not proper and/or present.
- Pathname of the input file
- Number of lines processed
- Number of valid triangles
- Number of invalid triangles
- Multiple methods
- Exception handing
- File I/O
- Dialog box
file input:
# 3 4 5
# 5 5 5
# 5 5 7 XXX
# -3 10 10 15
# 0 0 0
# 3 4.1 5
# 3 x 4
# 5 4 3 6 YYY ZZZ
# 1 1 10
# 15 16 22
# 3 4
output:
1: 3, 4, 5: The triangle is a right triangle,
The area of this triangle is 6.00
2: 5, 5, 5: The triangle is equilateral,
The area of this triangle is 10.83
3: 5, 5, 7: The triangle is isosceles,
The area of this triangle is 12.50
Item discarded: XXX
Error - At least one of your sides is an invalid integer value
Item discarded: 15
Error - At least one of your sides is an invalid integer value
Error - At least one of your sides is not an integer
Error - At least one of your sides is not an integer
Error - Sides not in ascending order
Item discarded: 6
Item discarded: YYY
Item discarded: ZZZ
Error - Sides do not form a valid triangle
4: 15, 16, 22: This triangle is not distinctive,
The area of this triangle is 120.00
EOF found
File Path: E:\Java\Assign-05\pa5-test-01.txt
--------------- Summary Report ---------------
Total entries processed=10
Number of valid entries=4
Number of invalid entries=6
Percentage of valid entries=40.00%
This is what I have-------
import java.util.InputMismatchException;
import java.util.*;
import java.io.*;
public class practice
{
public static void main(){
boolean valid = true;
int side1 = 0;
int side2 = 0;
int side3 = 0;
String side4 = "";
int count = 1;
try
{
File myfile = new File("triangles.txt");
Scanner fileReader = new Scanner(myfile);
PrintWriter writer = new PrintWriter("output.txt");
while(fileReader.hasNextInt()) {
side1 = fileReader.nextInt();
side2 = fileReader.nextInt();
side3 = fileReader.nextInt();
side4 = fileReader.nextLine();
if (side1 <= 0 || side2 <= 0 || side3 <=0){
writer.println("Error - At least one of your sides is an invalid integer value");
}
if (side1 > side2 || side2 > side3){
writer.println("Error - Sides not in ascending order");
}
if(side1==side2 && side2==side3){
writer.println(count + ": "+ side1 + " " + side2 + " "+ side3 +" The triangle is equalateral");
writer.printf("The area of this triangle is %.2f\n", calculateArea(side1, side2, side3));
}
else if((side1==side2 && side2 != side3 && side1!=side3) || (side2==side3 && side2!=side1 && side3!=side1) || (side3==side1 && side3!=side2 && side1!=side2 )) {
writer.println(count + ": "+ side1 + " " + side2 + " "+ side3 +" The triangle is isoceles");
writer.printf("The area of this triangle is %.2f\n", calculateArea(side1, side2, side3));
}
else if ((Math.pow(side1, 2) + Math.pow(side2, 2)) == (Math.pow(side3, 2)) || (Math.pow(side3, 2) + Math.pow(side2, 2)) == (Math.pow(side1, 2))){
writer.println(count + ": " + side1 + " " + side2 + " "+ side3 +" This triangle is a right triangle");
writer.printf("The area of this triangle is %.2f\n", calculateArea(side1, side2, side3));
}
else if ((side1 != side2) && (side1 != side3) && (side2!=side3) && (side1!=side3)){
writer.println(count + ": " + side1 + " " + side2 + " "+ side3 +" This triangle is scalene");
writer.printf("The area of this triangle is %.2f\n", calculateArea(side1, side2, side3));
}
else if(side4 == null){
continue;
}
else if(side4 != null){
writer.println("Item discarded: " + side4);
}
count++;
}
writer.close();
}
catch(Exception e)
{
e.printStackTrace();
System.exit(-1);
}
}
private static double calculateArea(int a,int b,int c)
{
double area = ((a+b+c)/ 2.0);
double area1 = Math.sqrt(area*((area-a)*(area-b)*(area-c)));
double area2 = Math.round(area1*100.0)/100.0;
return area2;
}
}
What am I missing?

Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 1 images

- Art.java In this part you will create a program Art.java that produces a recursive drawing of the design attached in the picture. Requirements Art.java must take one (1) integer command-line argument n that controls the depth of recursion. Your drawing must stay within the drawing window when n is between 1 and 7. (The autograder will not test values of n outside of this range.) You may not change the size of the drawing window (but you may change the scale). Do not add sound. Your drawing can be a geometric pattern, a random construction, or anything else that takes advantage of recursive functions. Optionally, you may use the Transform2D library you implemented in Part 1. You may also define additional geometric transforms in Art.java, such as sheer, reflect across the x- or y- axis, or rotate about an arbitrary point (as opposed to the origin). Your program must be organized into at least three separate functions, including main(). All functions except main() must be private. call…arrow_forwardA palindrome is a word that is spelled the same way both forwards and backwards. For example, the word, 'racecar' is a palindrome. Using character arrays, write a c++ program that prompts the user to enter a word from the keyboard and informs the user whether the word is a palindrome or not.arrow_forwardImplement in C Programming 9.10.1: LAB: Movie show time display Write a program that reads movie data from a CSV (comma separated values) file and output the data in a formatted table. The program first reads the name of the CSV file from the user. The program then reads the CSV file and outputs the contents according to the following requirements: Each row contains the title, rating, and all showtimes of a unique movie. A space is placed before and after each vertical separator ('|') in each row. Column 1 displays the movie titles and is left justified with a minimum of 44 characters. If the movie title has more than 44 characters, output the first 44 characters only. Column 2 displays the movie ratings and is right justified with a minimum of 5 characters. Column 3 displays all the showtimes of the same movie, separated by a space. Each row of the CSV file contains the showtime, title, and rating of a movie. Assume data of the same movie are grouped in consecutive rows. Hints: Use…arrow_forward
- Python3arrow_forwardIn Java please,arrow_forwardWrite a C# program that creates an integer array of size 10 and fills the array with numbers set by the programmer (not entered by the user). Then, the program will create two arrays, one of them contains only the odd values of the original array, and the other contains the even values. Note that the size of the newly created arrays should be equal to the number of elements in the array. For example, if the original array contains three odd values, the size of the array that contains the odd values should be equal to three.arrow_forward
- Write a python application to simulate an Online Book Shop. Notes: Option 1 and Option 2 must display the list of books to the user. The Main function accounts for invalid options. Program displays error message for invalid user option, invalid ISBN number or any invalid title.The programmer can create the book title, price, and ISBN information for the books. Each item consists only one string of comma-separated data: book ISBN number, title, and price. A customer can purchase some books either by ISBN number and/or by title. If the user input an invalid number or book title, the program should display an error message. The user can stop shopping with “checkout” option , which triggers the checkout() function that computes the total cost of the books in the cart. A customer will be provided the following menu option while shopping at the book shop: Option 1. Purchase by ISBN: User can purchase a book by its ISBN number. ISBN stands for International Standard Book Number. This is a…arrow_forwardJAVA PROGRAM Homework #2. Chapter 7. PC #13. Name Search (page 492) Read these instructions for additional requirements carefully. Write a program that reads the contents of the two files into two separate arrays. The user should be able to enter a name the application will display messages indicating whether the names were among the most popular. 1. GirlNames.txt and BoyNames.txt contain a list of the 200 most popular names given to girls/boys born in the United States for the years 2000 through 2009. 2. Your application should use an array to hold the names. 3. The program should continue interacting with the user indefinitely unless the user chooses to quit by entering "QUIT" (should be case insensitive). 4. The user should enter a single name and the program will search the name in both lists. The user SHOULD NOT specify whether the search is for girls name or boys name. The program is responsible for finding either or both and telling the user where it found it. 5.…arrow_forwardComputer Science Part C: Interactive Driver Program Write an interactive driver program that creates a Course object (you can decide the name and roster/waitlist sizes). Then, use a loop to interactively allow the user to add students, drop students, or view the course. Display the result (success/failure) of each add/drop.arrow_forward
- Writ a program with c++ language to do the following tasks : The user can input one original image and target scales . According to the user’s requirement, this image can resized to the target scale. The program can show the original image and the resized image. *The core function should be Bilinear_interpolation(original image, target height, target width) The output of this function is the resized image and then the user can save it. *You can use image processing libraries to assist your codes, such as Opencv. The functions included in the libraries which are off‐the‐shelf can be used to read images, operate images and save images.arrow_forwardCreate a program in C Language that calculates a student's overall grade based on their assignments, quizzes, and exams. Create three separate arrays of `double` which will store 5 assignments, 3 quizzes, and 2 exams, respectively. The program should prompt the user to enter the grades for each group on one line (see example). The program should then compute the average of each individual group and then weight that group based on the value given for the corresponding weight. In the example run below, the average assignment score is first calculated and then multiplied by the given assignment weight. The final grade is calculated as the sum of all weighted groups and should be printed to 2 decimal places. Submit your code as grades.c Other Requirements Do not hard code any values. Use preprocessor directives or `const` globals for array sizes. Your code must use consistent formatting and spacing. Points will be taken off for inconsistent or sloppy code. Example Run Enter 5 assignment…arrow_forwardFor C++: Design an application that has an array of at least 20 integers. It should call a module that uses the sequential search algorithm to locate one of the values. The module should keep a count of the number of comparisons it makes until it finds the value. Then the program should call another module that uses the binary search algorithm to locate the same value. It should also keep a count of the number of comparisons it makes. Display these values on the screen.arrow_forward
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY





