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
-
1. What is the required monthly mortgage payment 2. What are the initial cash outflows of the buy decision 3. What is the present value of all cash outflows of the buy decision from month 0 to month...
-
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...
-
The United Nations Peacekeeping Mission Abstract To maintain peace as well as security, United Nations is mandated which tries to attain this mandate by way of diverse means such as the deployment of...
-
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...
-
True or false: If true, explain why. If false, give an explicit counterexample. (a) If det 0 then A-l exists. (b) det(2A) = 2 det A. (c) det(A -(- B) = det A + det B. (d) (e) (f) det[(A + B)(A - B)]...
-
Question 7 2 pts Determine whether each of the following transaction is an operating, investing, financing, or noncash investing / financing activity. If the activity is not represented anywhere on...
-
Which of the following management theorists conducted the famous experiment at the Hawthorne Electric Plant in which employee productivity increased regardless of the type of intervention implemented...
-
Shattered Glass, Inc., is an all-equity firm. The cost of the companys equity is currently 11 percent, and the risk-free rate is 3.5 percent. The company is currently considering a project that will...
-
How has your selected organization's leadership team adapted? How can you tell?
-
Values for the NASDAQ composite index during the 1,500 days preceding March 10, 2006, can be downloaded from the authors web site. Calculate the one-day 99% VaR and the one-day 99% ES on March 10,...
-
Page 1 of 3 UNIVERSITY OF BRISTOL COURSEWORK ASSESSMENT FOR DEGREES IN THE BUSINESS SCHOOL ??????? April 2023 ??????? UNIT CODE: EFIM20040 UNIT NAME: Financial Data DEADLINE: 27 April 2023 before...
-
Algebraic equations such as Bernoulli's relation, Eq. (1) of Example 1.3, are dimensionally consistent, but what about differential equations? Consider, for example, the boundary-layer x-momentum...
-
Initially at rest, an egg is released from the top of a tall building. After a brief delay, a second egg is hurled down from the same height at a rate of 6.15 m/s. If both eggs splat on the ground at...
-
How do transformational and transactional leadership styles impact organizational culture, and what are the downstream effects on employee motivation and productivity ?
-
A B F G H b) Simulate the topological sort algorithm for the graph on the right. Show the linear order. C D E 3a) Describe a topological sort of a directed acyclic graph. H
-
Brower corporation owns a manufacturing plant in the country of Oust. On December 31, 20X1, the plant had a book value of $5,000,000 and an estimated fair value of $8,000,000. Oust's government has...
-
How many times does the following code iterate through the while loop? int total = 20; int index = 1; while (index < total) { } if ((total > 9) || (index / total == 5)) { total -= index; } total -=...
-
Which task is performed by a book-keeper? A. Analysing the trading results B. Entering transactions in the ledger C. Preparing year-end financial statements D. Providing information for...
-
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...
-
The price elasticity of demand is defined as the percentage change in _________ divided by the percentage change in _________.
-
The price elasticity of demand measures the responsiveness of quantity _________ to a change in price.
-
Describe and explain how demand and supply determine prices and the quantities that are bought and sold.
Study smarter with the SolutionInn App