Question

In: Computer Science

What is the perimeter of the shape made from the file datatest4.txt whose contents are shown...

What is the perimeter of the shape made from the file datatest4.txt whose contents are shown below (just give to two decimal (places)? JAVA!

-3, 9

-8, 7

-12, 4

-6, -2

-4, -6

2, -8

6, -5

10, -3

8, 5

4, 8

Solutions

Expert Solution

OUTPUT ::

RAW CODE ::

_____________________________________________ main.java ________________________________________

import java.util.*;
import java.io.*;

class Main{
   public static double distance(int[] A, int[] B){
       int x,y;
       x = A[0] - B[0] ; y = A[1] - B[1]; // X wise distance , Y wise distance
       return Math.sqrt((x*x)+(y*y)); // Pythagerous theorem
   }
   public static void main(String[] args){
       String line; String[] val; // Declarng variables
       int[] start = new int[2];
       int[] temp = new int[2];
       int[] cur = new int[2];
       start[0] = -1 ; start[1] = -1;
       int perimeter = 0; // perimeter stars with 0
       try{
           File fl = new File("datatest4.txt");
           Scanner sc = new Scanner(fl);
           while (sc.hasNextLine()){
               line = sc.nextLine(); val = line.split(", "); // Read line by line, split the values
               cur[0] = Integer.parseInt(val[0]); // Converting Them to integers
               cur[1] = Integer.parseInt(val[1]);
               if(start[0] == -1 && start[1] == -1){ // if it start line
                   start[0] = cur[0]; start[1] = cur[1]; // Record it in start
                   temp[0] = cur[0]; temp[1] = cur[1]; // Storing past values in temp
                   continue; // For first one continue
               }
               perimeter += distance(temp, cur); // Calculate distance for current to past value
               temp[0] = cur[0]; temp[1] = cur[1]; // Storing past values in temp
           }
           perimeter += distance(cur, start); // Finally Calculate distance for end to start
           System.out.println("Perimeter is : "+perimeter); // Printing
       } catch(Exception e){
           System.out.println("Error");
       }
   }
}

__________________________________________________________________________________________________


Related Solutions

What are the dimensions of a rectangle whose perimeter is 5600 units and whose area is...
What are the dimensions of a rectangle whose perimeter is 5600 units and whose area is as large as possible?
13. Minimizing Perimeter: What is the smallest perimeter possible for a rectangle whose area is 36...
13. Minimizing Perimeter: What is the smallest perimeter possible for a rectangle whose area is 36 in2, and what are its dimensions? Also, provide the perimeter and area equations. SHOW WORK. Perimeter Equation: _________________Area Equation: ___________________ Dimensions (include units): ___________Perimeter (include units):___________ 14. Find the linearization L(x) at x = 2 of the function, f(x)=√(x^2+12). SHOW WORK. Linearization L(x): ______________________
This is all in Python. Also, the names come from a .txt file that i have...
This is all in Python. Also, the names come from a .txt file that i have created with 3 names on it(Jim,Pam,Dwight). Main Function. Write a program where the user enters a name. Using the read function, check to see if the name is in the text document. If it is, respond back to the user the name is found within the list. Read Function. The read function should return the contents of the text document as a list. EXAMPLE...
(PYTHON) Write a program that does the following: reads each line from a txt file and...
(PYTHON) Write a program that does the following: reads each line from a txt file and convert it to lowercase counts the number of instances of: the characters 'a', 'e','i','o' and 'u' in the file creates a new file of file type .vowel_profile print outs lines in the file indicating the frequencies of each of these vowels Example input/output files: paragraph_from_wikipedia.txt (sample input) link: https://cs.nyu.edu/courses/fall19/CSCI-UA.0002-007/paragraph_from_wikipedia.txt paragraph_from_wikipedia.vowel_profile (sample output) link: https://cs.nyu.edu/courses/fall19/CSCI-UA.0002-007/paragraph_from_wikipedia.vowel_profile Please help!
1.   Bubble Sort Implement a bubble sort program that will read from a file “pp2.txt” from...
1.   Bubble Sort Implement a bubble sort program that will read from a file “pp2.txt” from the current directory a list of intergers (10 numbers to be exact), and the sort them, and print them to the screen. You can use redirection to read data from a given file through standard input, as opposed to reading the data from the file with the read API (similar to Lab #1). You can assume the input data will only have 10 numbers...
#Java I am reading from the txt file and I put everytihng inside of the String[],...
#Java I am reading from the txt file and I put everytihng inside of the String[], like that: String[] values = str.split(", "); But, now I have to retrieve the data from it one by one. How can I do it? Here is the txt file: OneTime, finish the project, 2020-10-15 Monthly, wash the car, 2020-11-10 Thanks!
In python Complete the function get_Astring(filename) to read the file contents from filename (note that the...
In python Complete the function get_Astring(filename) to read the file contents from filename (note that the test will use the file data.txt and data2.txt provided in the second and third tabs), strip off the newline character at the end of each line and return the contents as a single string.
A class Names reads the following names from the .txt file Name.txt Jason Butler Paul Cunningham...
A class Names reads the following names from the .txt file Name.txt Jason Butler Paul Cunningham Logan Bryant Cody paul Robert Vernon Ehlers III Quincy James Ellefson Currionte Evans Gavin Scott French Zach Tyler Goss Noah Cosby Jeremy Whittle Ryan brown Jonah Dalton Null Cameron jones Xavier Rhodes Malcom Wesley Jamarcus johnson Bernard smith Joseph Nettles Danny Willaims James wellington William bolar Make a search directory using dynamic allocation where the user would search the any number of letters of...
C++ Question: we need to read speech from .txt file. Steve Jobs delivered a touching and...
C++ Question: we need to read speech from .txt file. Steve Jobs delivered a touching and inspiring speech at Stanford's 2005 commencement. The transcript of this speech is attached at the end of this homework description. In this homework, you are going to write a program to find out all the unique tokens (or words) used in this speech and their corresponding frequencies, where the frequency of a word w is the total number of times that w appears in...
1. If we use the command: FSUTIL FILE CREATENEW file1.txt, what other parameter must we include?...
1. If we use the command: FSUTIL FILE CREATENEW file1.txt, what other parameter must we include? File System File Attributes File Size We can use the SC utility tool to manage services, and the following are all options for SC, except: LIST CREATE QUERY STOP /Length When we use DIR without any switches, we will see the following information, except: Group of answer choices Last Modified Time File/Directory Name Ownership File Size While we can use the % for variables...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT