Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
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.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started