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
- In C# I want to map out how each sq ft on each floor will be used.•Open a file, read in the square footage of each floor in this building (10k – 50k).•Then create a jagged array that will allow me to map each square foot on each floor to a different tenant. I will be selling the space in 1,000 sq ft increments.•Open a file for the 20th floor and read in the tenants and their square foot needs. Map the tenants to the available square footage on the 20th floor.•Tell me how much square footage on the 20th floor I have left to sell.arrow_forwardArt.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_forward
- Implement 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_forwardIN C++ programming This question is inspired by the famous Uno card game. Write an activity that takes two arguments: (1) the player's current hand and (2) the current upward card on the table. Work will be back true if the player is able to make the game, or false if the player must draw on the deck. A player can make a game if: They have a card the same color as the upside card. They have the same number card as the upside card. canPlay (["yellow 3", "yellow 7", "blue 8", "red 9", "red 2"], "red 1") => trutharrow_forwardDon't reject my question under complex one Computer Science Create a Windows Form Application project. with C#, using random values in an array or loop. The application should have a button and a picture box. Each time the button is clicked, a random number 1 through 6 is generated and the corresponding die image is displayed in the picture box.arrow_forward
- Write a program in C++ to simulate a 1-dimension random walk along a circular tiled path. At each step, the walker randomly selects, with equal probability, to move to the left or right. The program displays the walker’s progress as it moves from tile to tile. The simulation ends as soon as the walker visits each tile at least once. The program displays the number of times the walker visited each tile. The program displays the number of times the walker moves.arrow_forwardPython3arrow_forwardIn Java please,arrow_forward
- Create a new C# project then write a code equivalent to solve the problem given below. Create a menu driven program that will perform the following operations specified below. The program shall request data needed and display the result accordingly. Operations: - ADD NEW DATA - INSERT DATA - UPDATE DATA - DELETE DATA - RESET - SHOW DATA - EXIT Operations: - ADD NEW DATA – request single data from the user and store to arraylist - INSERT DATA – request index location and data to be inserted - UPDATE DATA – request index location and data to be updated - DELETE DATA – request data to be deleted - RESET – clear or reset the elements of arraylist - SHOW DATA – display all the elements of arraylist in horizontal manner - EXIT – end the execution of the programarrow_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_forwardThe purpose of the program is to create a bouncing screensaver (C++). 1. Use a 3 by 3 outline of a square. For the field (screen, table) use a 2-dimensional array of 10 rows and 30 columns. The center of the square array will start at position [2][9]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