Software Dev. & Problem Solving II File I/O and Exceptions 2 python GCIS-124 Assignment 1.3 Java...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Software Dev. & Problem Solving II File I/O and Exceptions 2 python GCIS-124 Assignment 1.3 Java Goals of the Assignment The goal of this assignment is to read from files and to practice exception handling in Java. Please read this document in its entirety before seeking help from the course staff. 1 Background The base of a number (also called its radix) indicates the range of possible values for each digit in the number. In general, the range will always be from 0 to the base-1. For example, when using decimal (base 10) to represent numeric values each digit has a range of 10 possible values: 0 to 9 (10-1), octal (base 8) uses the range 0 to 7, and binary (base 2) uses 0 to 1. Humans are used to working with base 10 numbers, and can intuitively understand the value of a number like 5,467. If the positions of each digit are numbered from right to left starting with 0, each digit represents the base raised to the power corresponding to the digit's position and multiplied by the digit's value. In this case: 5x10 + 4x10 + 6x10 + 7x10 = 5000 + 400 + 60 + 7 = 5467 On the other hand, the same digits in Octal represent a completely different value: 5x8 + 4x8 + 6x8 + 7x80 = 2,560 +256 + 48 + 7 = 2,871 In these examples, the digit representing the largest value, i.e. the most significant digit, always comes first. This representation is referred to as big-endian notation because the "big end" comes first. It is also possible to represent the same numeric values using little-endian notation, wherein the "little end" comes first, e.g. 7645.Little-endian notation is not as intuitive for humans to understand, but nevertheless is the way that some computers store data. 1. Create a new java class named Base10Converter and define a static method named "charToInteger" that declares a parameter for a char digit and returns the equivalent integer value. For example, if the digit is '5' your function should return the integer value 5. Note that simply casting the digit to an int will not work - the integer value of a char is its ASCII value, and so the digit 5' has the value 53 when cast to an int. Write a JUnit test that includes at least two tests for the charToInteger function. 2. Define a method named arrayToInteger that declares parameters for a char array of digits, a base, and a boolean indicating whether or not the value uses big-endian encoding. Your function should convert the digits in the char array to an integer with the correct value. You do not need to handle negative numbers or bases outside of the range 2-10. Add tests to your JUnit unit test to thoroughly test your function. Use the table below for test inputs. Note that the purpose of this exercise is for you to implement the algorithm to compute the integer value from the digits in the array. If you use Java's built-in functions to convert integer values you will not receive credit for this exercise. digits {'5', '4', '6', '7'} 10 {'5', '4', '6', '7'} 10 {'5', '4', '6', '7'} 8 base '6', '7'} 8 {'5' '4' {'1', '0', '1', '1'} 2 {'1', '0', '1', '1'} 2 big-endian true false true false true false output 5467 7645 2871 4005 11 13 3. Take a moment to examine the digits_* files that have been provided to you in the data directory of your repository. The name of each file indicates its radix and whether big-endian or little-endian encoding is used. For example, the file "digits_2_big.txt" uses binary (base 2) and big-endian encoding, and the file "digits_8_little.txt" uses octal (base 8) and little-endian encoding. The first two lines inside the file indicate the base and endianness of the values inside the file. Each subsequent line in the file contains two different representations of the same integer value; the first uses the base and encoding indicated on the first two lines, and the second is a standard big-endian decimal representation. Add a main method to your Base 10 Converter class that prompts the user to enter a filename. Read each line in the file, and use your arrayToInteger function to convert the first value to base 10 and compare it to the second value for correctness. You should match the example output below as closely as possible (where "match" indicates that the value returned by your arrayToInteger method matches the decimal value in the file and "mismatch" indicates that it does not). The digits_8_little.txt file contains an intentional error so you should have exactly one mismatch. None of the other provided files contain errors. Enter a filename: data/digits_8_little.txt base: 8 endianness: little-endian 5670652: 713205 (match) 6072562: 742854 (match) 004423: 108800 (match) 6766313: 835006 (match) 3402522: 611363 (match) 3667642: 683955 (match) 146445: 182689 (match) 4010553: 970820 (mismatch 970821) 335514: 138075 (match) 221416: 202834 (match) If the file does not exist, your program should print an error message and exit without crashing. Software Dev. & Problem Solving II File I/O and Exceptions 2 python GCIS-124 Assignment 1.3 Java Goals of the Assignment The goal of this assignment is to read from files and to practice exception handling in Java. Please read this document in its entirety before seeking help from the course staff. 1 Background The base of a number (also called its radix) indicates the range of possible values for each digit in the number. In general, the range will always be from 0 to the base-1. For example, when using decimal (base 10) to represent numeric values each digit has a range of 10 possible values: 0 to 9 (10-1), octal (base 8) uses the range 0 to 7, and binary (base 2) uses 0 to 1. Humans are used to working with base 10 numbers, and can intuitively understand the value of a number like 5,467. If the positions of each digit are numbered from right to left starting with 0, each digit represents the base raised to the power corresponding to the digit's position and multiplied by the digit's value. In this case: 5x10 + 4x10 + 6x10 + 7x10 = 5000 + 400 + 60 + 7 = 5467 On the other hand, the same digits in Octal represent a completely different value: 5x8 + 4x8 + 6x8 + 7x80 = 2,560 +256 + 48 + 7 = 2,871 In these examples, the digit representing the largest value, i.e. the most significant digit, always comes first. This representation is referred to as big-endian notation because the "big end" comes first. It is also possible to represent the same numeric values using little-endian notation, wherein the "little end" comes first, e.g. 7645.Little-endian notation is not as intuitive for humans to understand, but nevertheless is the way that some computers store data. Software Dev. & Problem Solving II File I/O and Exceptions 2 python GCIS-124 Assignment 1.3 Java Goals of the Assignment The goal of this assignment is to read from files and to practice exception handling in Java. Please read this document in its entirety before seeking help from the course staff. 1 Background The base of a number (also called its radix) indicates the range of possible values for each digit in the number. In general, the range will always be from 0 to the base-1. For example, when using decimal (base 10) to represent numeric values each digit has a range of 10 possible values: 0 to 9 (10-1), octal (base 8) uses the range 0 to 7, and binary (base 2) uses 0 to 1. Humans are used to working with base 10 numbers, and can intuitively understand the value of a number like 5,467. If the positions of each digit are numbered from right to left starting with 0, each digit represents the base raised to the power corresponding to the digit's position and multiplied by the digit's value. In this case: 5x10 + 4x10 + 6x10 + 7x10 = 5000 + 400 + 60 + 7 = 5467 On the other hand, the same digits in Octal represent a completely different value: 5x8 + 4x8 + 6x8 + 7x80 = 2,560 +256 + 48 + 7 = 2,871 In these examples, the digit representing the largest value, i.e. the most significant digit, always comes first. This representation is referred to as big-endian notation because the "big end" comes first. It is also possible to represent the same numeric values using little-endian notation, wherein the "little end" comes first, e.g. 7645.Little-endian notation is not as intuitive for humans to understand, but nevertheless is the way that some computers store data. Software Dev. & Problem Solving II File I/O and Exceptions 2 python GCIS-124 Assignment 1.3 Java Goals of the Assignment The goal of this assignment is to read from files and to practice exception handling in Java. Please read this document in its entirety before seeking help from the course staff. 1 Background The base of a number (also called its radix) indicates the range of possible values for each digit in the number. In general, the range will always be from 0 to the base-1. For example, when using decimal (base 10) to represent numeric values each digit has a range of 10 possible values: 0 to 9 (10-1), octal (base 8) uses the range 0 to 7, and binary (base 2) uses 0 to 1. Humans are used to working with base 10 numbers, and can intuitively understand the value of a number like 5,467. If the positions of each digit are numbered from right to left starting with 0, each digit represents the base raised to the power corresponding to the digit's position and multiplied by the digit's value. In this case: 5x10 + 4x10 + 6x10 + 7x10 = 5000 + 400 + 60 + 7 = 5467 On the other hand, the same digits in Octal represent a completely different value: 5x8 + 4x8 + 6x8 + 7x80 = 2,560 +256 + 48 + 7 = 2,871 In these examples, the digit representing the largest value, i.e. the most significant digit, always comes first. This representation is referred to as big-endian notation because the "big end" comes first. It is also possible to represent the same numeric values using little-endian notation, wherein the "little end" comes first, e.g. 7645.Little-endian notation is not as intuitive for humans to understand, but nevertheless is the way that some computers store data. 1. Create a new java class named Base10Converter and define a static method named "charToInteger" that declares a parameter for a char digit and returns the equivalent integer value. For example, if the digit is '5' your function should return the integer value 5. Note that simply casting the digit to an int will not work - the integer value of a char is its ASCII value, and so the digit 5' has the value 53 when cast to an int. Write a JUnit test that includes at least two tests for the charToInteger function. 2. Define a method named arrayToInteger that declares parameters for a char array of digits, a base, and a boolean indicating whether or not the value uses big-endian encoding. Your function should convert the digits in the char array to an integer with the correct value. You do not need to handle negative numbers or bases outside of the range 2-10. Add tests to your JUnit unit test to thoroughly test your function. Use the table below for test inputs. Note that the purpose of this exercise is for you to implement the algorithm to compute the integer value from the digits in the array. If you use Java's built-in functions to convert integer values you will not receive credit for this exercise. digits {'5', '4', '6', '7'} 10 {'5', '4', '6', '7'} 10 {'5', '4', '6', '7'} 8 base '6', '7'} 8 {'5' '4' {'1', '0', '1', '1'} 2 {'1', '0', '1', '1'} 2 big-endian true false true false true false output 5467 7645 2871 4005 11 13 3. Take a moment to examine the digits_* files that have been provided to you in the data directory of your repository. The name of each file indicates its radix and whether big-endian or little-endian encoding is used. For example, the file "digits_2_big.txt" uses binary (base 2) and big-endian encoding, and the file "digits_8_little.txt" uses octal (base 8) and little-endian encoding. The first two lines inside the file indicate the base and endianness of the values inside the file. Each subsequent line in the file contains two different representations of the same integer value; the first uses the base and encoding indicated on the first two lines, and the second is a standard big-endian decimal representation. 1. Create a new java class named Base10Converter and define a static method named "charToInteger" that declares a parameter for a char digit and returns the equivalent integer value. For example, if the digit is '5' your function should return the integer value 5. Note that simply casting the digit to an int will not work - the integer value of a char is its ASCII value, and so the digit 5' has the value 53 when cast to an int. Write a JUnit test that includes at least two tests for the charToInteger function. 2. Define a method named arrayToInteger that declares parameters for a char array of digits, a base, and a boolean indicating whether or not the value uses big-endian encoding. Your function should convert the digits in the char array to an integer with the correct value. You do not need to handle negative numbers or bases outside of the range 2-10. Add tests to your JUnit unit test to thoroughly test your function. Use the table below for test inputs. Note that the purpose of this exercise is for you to implement the algorithm to compute the integer value from the digits in the array. If you use Java's built-in functions to convert integer values you will not receive credit for this exercise. digits {'5', '4', '6', '7'} 10 {'5', '4', '6', '7'} 10 {'5', '4', '6', '7'} 8 base '6', '7'} 8 {'5' '4' {'1', '0', '1', '1'} 2 {'1', '0', '1', '1'} 2 big-endian true false true false true false output 5467 7645 2871 4005 11 13 3. Take a moment to examine the digits_* files that have been provided to you in the data directory of your repository. The name of each file indicates its radix and whether big-endian or little-endian encoding is used. For example, the file "digits_2_big.txt" uses binary (base 2) and big-endian encoding, and the file "digits_8_little.txt" uses octal (base 8) and little-endian encoding. The first two lines inside the file indicate the base and endianness of the values inside the file. Each subsequent line in the file contains two different representations of the same integer value; the first uses the base and encoding indicated on the first two lines, and the second is a standard big-endian decimal representation. 1. Create a new java class named Base10Converter and define a static method named "charToInteger" that declares a parameter for a char digit and returns the equivalent integer value. For example, if the digit is '5' your function should return the integer value 5. Note that simply casting the digit to an int will not work - the integer value of a char is its ASCII value, and so the digit 5' has the value 53 when cast to an int. Write a JUnit test that includes at least two tests for the charToInteger function. 2. Define a method named arrayToInteger that declares parameters for a char array of digits, a base, and a boolean indicating whether or not the value uses big-endian encoding. Your function should convert the digits in the char array to an integer with the correct value. You do not need to handle negative numbers or bases outside of the range 2-10. Add tests to your JUnit unit test to thoroughly test your function. Use the table below for test inputs. Note that the purpose of this exercise is for you to implement the algorithm to compute the integer value from the digits in the array. If you use Java's built-in functions to convert integer values you will not receive credit for this exercise. digits {'5', '4', '6', '7'} 10 {'5', '4', '6', '7'} 10 {'5', '4', '6', '7'} 8 base '6', '7'} 8 {'5' '4' {'1', '0', '1', '1'} 2 {'1', '0', '1', '1'} 2 big-endian true false true false true false output 5467 7645 2871 4005 11 13 3. Take a moment to examine the digits_* files that have been provided to you in the data directory of your repository. The name of each file indicates its radix and whether big-endian or little-endian encoding is used. For example, the file "digits_2_big.txt" uses binary (base 2) and big-endian encoding, and the file "digits_8_little.txt" uses octal (base 8) and little-endian encoding. The first two lines inside the file indicate the base and endianness of the values inside the file. Each subsequent line in the file contains two different representations of the same integer value; the first uses the base and encoding indicated on the first two lines, and the second is a standard big-endian decimal representation. Add a main method to your Base 10 Converter class that prompts the user to enter a filename. Read each line in the file, and use your arrayToInteger function to convert the first value to base 10 and compare it to the second value for correctness. You should match the example output below as closely as possible (where "match" indicates that the value returned by your arrayToInteger method matches the decimal value in the file and "mismatch" indicates that it does not). The digits_8_little.txt file contains an intentional error so you should have exactly one mismatch. None of the other provided files contain errors. Enter a filename: data/digits_8_little.txt base: 8 endianness: little-endian 5670652: 713205 (match) 6072562: 742854 (match) 004423: 108800 (match) 6766313: 835006 (match) 3402522: 611363 (match) 3667642: 683955 (match) 146445: 182689 (match) 4010553: 970820 (mismatch 970821) 335514: 138075 (match) 221416: 202834 (match) If the file does not exist, your program should print an error message and exit without crashing. Add a main method to your Base 10 Converter class that prompts the user to enter a filename. Read each line in the file, and use your arrayToInteger function to convert the first value to base 10 and compare it to the second value for correctness. You should match the example output below as closely as possible (where "match" indicates that the value returned by your arrayToInteger method matches the decimal value in the file and "mismatch" indicates that it does not). The digits_8_little.txt file contains an intentional error so you should have exactly one mismatch. None of the other provided files contain errors. Enter a filename: data/digits_8_little.txt base: 8 endianness: little-endian 5670652: 713205 (match) 6072562: 742854 (match) 004423: 108800 (match) 6766313: 835006 (match) 3402522: 611363 (match) 3667642: 683955 (match) 146445: 182689 (match) 4010553: 970820 (mismatch 970821) 335514: 138075 (match) 221416: 202834 (match) If the file does not exist, your program should print an error message and exit without crashing. Add a main method to your Base 10 Converter class that prompts the user to enter a filename. Read each line in the file, and use your arrayToInteger function to convert the first value to base 10 and compare it to the second value for correctness. You should match the example output below as closely as possible (where "match" indicates that the value returned by your arrayToInteger method matches the decimal value in the file and "mismatch" indicates that it does not). The digits_8_little.txt file contains an intentional error so you should have exactly one mismatch. None of the other provided files contain errors. Enter a filename: data/digits_8_little.txt base: 8 endianness: little-endian 5670652: 713205 (match) 6072562: 742854 (match) 004423: 108800 (match) 6766313: 835006 (match) 3402522: 611363 (match) 3667642: 683955 (match) 146445: 182689 (match) 4010553: 970820 (mismatch 970821) 335514: 138075 (match) 221416: 202834 (match) If the file does not exist, your program should print an error message and exit without crashing.
Expert Answer:
Related Book For
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill
Posted Date:
Students also viewed these programming questions
-
Let A, B be sets. Define: (a) the Cartesian product (A B) (b) the set of relations R between A and B (c) the identity relation A on the set A [3 marks] Suppose S, T are relations between A and B, and...
-
Review the media landscape and system in The Bahamas. Which theories/typologies would fit the nation's media best? Explain your answer thoroughly using "Normative Theories of The Media Journalism and...
-
Ospry Company has working capital in the amount of $1,240,000. For each of the following transactions, determine whether working capital will increase, decrease, or remain the same. a. Paid accounts...
-
Hamilton Boats issued 306,000 shares of its no-par common stock to Sudoku Motors in exchange for 1,800 four-stroke outboard motors that normally sell in quantity for $3,400 each. By what amount...
-
Tools of environmental management need to be eco-efficient. What is ecoefficiency? What is an eco-efficient tool? Provide a critical analysis of the view that conventional life-cycle assessment is...
-
Following is information about Fine Furnitures direct labor hours and wages last period. Actual labor hours at the standard price per hour .... $1,680 Actual labor hours at the actual price per hour...
-
E23.1 Let C be the upper hemicircle y = 1 x oriented from (1,0) to (1,0) and let F(x, y) = (x + y, 4xy + tan(y)). F. dr. Find
-
Testing to see if there is evidence that the mean service time at Restaurant #1 is less than the mean service time at Restaurant #2. Use Figure 4.4 and assume that the sample sizes are all the same....
-
1) Let V be the set of all ordered pairs (x, y), where x, y are real numbers. Let a= (x, y) and b=(x be two elements in V. Define the addi tion as a +b = (x, y,)+(*2, y2 ) = (2x, - 3x,, y - Y2) the...
-
3. (5 points) What is the entropy of the image below, where numbers (0, 48, 85, 92, 110) denote the gray-level intensities? 110 110 110 110 110 110 110 110 85 85 85 85 85 85 85 85 0 0 92 92 92 92 0 0...
-
The line x + 3y-2=0 bisects the angle between a pair of straight lines of which one has equation x-7y+5=0. The equation of the other line is:
-
What are three ways to prevent malware and viruses on a mobile OS device? What are some ways to protect your data? Describe the four mobile operating system. How do you navigate within each? How do...
-
Racer Corp. acquired all of the common stock of Tangiers Co. in 2009. Tangiers maintained its incorporation. Which of Racers account balances would vary between the equity method and the initial...
-
Hello i need help with a previous tutors help im doing an oop assingment its run by the programming language c# i need help putting this code in private void DisplayArea(Shape shape) { ...
-
1) using ISA 5.1The figure shows a measurement and control system for the variablelevel of a storage tank.liquid storage.Design the P&ID diagram under the following conditions:? The differential...
-
3M Company reports the following financial statement amounts in its 10-K report: a. Compute the receivables, inventory, and PPE turnover ratios for both 2018 and 2017. (Receivables turnover and...
-
Steve Drake sells a rental house on January 1, 2012, and receives $130,000 cash and a note for $55,000 at 10 percent interest. The purchaser also assumes the mortgage on the property of $45,000....
-
On February 2, 2012, Alexandra purchases a personal computer for her home. The computer cost $3,000. Alexandra uses the computer 80 percent of the time in her accounting business, 10 percent of the...
-
Tom has a successful business with $100,000 of income in 2012. He purchases one new asset in 2012, a new machine which is 7-year MACRS property and costs $25,000. If you are Tom's tax advisor, how...
-
An air-breathing jet aircraft of total mass \(m\) flying with a constant speed \(v\) consumes air at the mass rate \(m_{a}^{\prime}\) and exhausts burned gas at the mass rate \(m_{g}^{\prime}\) with...
-
The end of a chain of length \(L\) and mass \(ho\) per unit length which is piled on a platform is lifted vertically with a constant velocity \(v\) by a variable force \(P\). Find \(P\) as a function...
-
A rocket of initial total mass \(m_{0}\) is fired vertically up from the north pole and accelerates until the fuel, which burns at a constant rate, is exhausted. The relative nozzle velocity of the...
Study smarter with the SolutionInn App