Question: Programming #1: Number Conversion and Memory Access In this programming assignment, you are going to work on an imaginary RAM(Random Access Memory), which is a

Programming #1: Number Conversion and Memory Access

In this programming assignment, you are going to work on an imaginary RAM(Random Access Memory), which is a byte array. You are given a file, memory.txt, which includes 32-byte data stored in the RAM.

You are asked to create a Java application, MemoryManager.java, which has methods to read a byte, read an integer, read a character, and read a float at a given memory address, which is passed as an array index.

For sake of simplicity, you are provided with a Junit Test file and you are asked to implement MemoryManager class so that all tests pass. Please note that you are not allowed to use number conversion methods available in the Java library or any other external libraries.

Notes:

- byte is 8-bit (each line is a byte in the memory)

- int is 4-byte

- float is 4-byte and uses IEEE 754 notation (you dont need to handle exceptional cases)

- char is 2-byte

Memory.txt:

11100000 10011000 00000000 11000111 10011000 10001000 00001000 00011010 00000000 00000000 00000000 00000000 01000001 10011000 00000000 10011000 11111010 10011000 10011000 10011000 10110100 10011000 10011000 10110011 10011000 10011001 10011000 01001011 00000000 00000000 00000100 01111100

MemoryManagerTest.java:

import static org.junit.jupiter.api.Assertions.*; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; class MemoryManagerTest { private static MemoryManager memoryManager; @BeforeAll static void init() { memoryManager = new MemoryManager("memory.txt"); } @Test void testReadByte() { int expected = -104; int actual = memoryManager.readByte(1); assertEquals(expected, actual); } @Test void testReadInt() { int expected = -1744779368; int actual = memoryManager.readInt(1); assertEquals(expected, actual); } @Test void testReadChar() { char expected = 'A'; char actual = memoryManager.readChar(11); assertEquals(expected, actual); } @Test void testReadFloat() { float expected = 0.15625f; float actual = memoryManager.readFloat(28); assertEquals(expected, actual); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!