Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Given classes are: 1) UnitTestMemory.java : import org.junit.*; import static or

ID: 3584206 • Letter: G

Question

Given classes are:

1) UnitTestMemory.java :

import org.junit.*;

import static org.junit.Assert.*;

import java.util.*;


public class UnitTestMemory

{

@Test

public void testInitSize()

{

// Test correct instantiation

Memory memBank = new Memory(20);

assertEquals(20, memBank.size());

memBank = new Memory(100);

assertEquals(100, memBank.size());

}

@Test

public void testSizeBoundaries()

{

// Test lower boundary

Memory memBank = new Memory(0);

assertEquals(0, memBank.size());

// Upper boundary is bounded by Integer.MAX_VALUE and

// will most likely exceed the maximum memory of the VM.

}

@Test

public void testRead()

{

// Create a new Memory object of a random size.

Random rnd = new Random();

int size = rnd.nextInt(10000);

int[] values = new int[size];

Memory memBank = new Memory(size);

// Write random values to every memory location

for (int i=0; i<values.length; i++)

{

values[i] = rnd.nextInt();

memBank.writeTo(i, values[i]);

}

// Read back the values from memory and ensure they are the

// same values we originally stored.

for (int i=0; i<values.length; i++)

{

assertEquals(values[i], memBank.readFrom(i));

}

}

// Ensure the default program is successfully loaded into

// memory.

@Test

public void testDefaultProgram()

{

Memory membank = new Memory(100);

membank.loadMemory();

assertEquals(799, membank.readFrom(0));

assertEquals(898, membank.readFrom(8));

}

}


2) MemoryInterface.java :

public interface MemoryInterface {


public void writeTo(int location, int value);

public int readFrom(int location);

public void loadMemory();

public int size();

}

3) TerminalInterface.java :

public interface TerminalInterface {


public int read();

public void print(int value);

}

4) UnitTestTerminal.java :

import org.junit.*;

import static org.junit.Assert.*;

import java.util.*;


public class UnitTestTerminal

{

@Test

public void testInput()

{

Terminal term = new Terminal();

Scanner scan = new Scanner(System.in);

int input;

System.out.println("Testing input...");

System.out.print("Enter an integer value: ");

input = scan.nextInt();

System.out.println("Enter the same integer value again:");

assertEquals(input, term.read());

System.out.println("Terminal input is working.");

}

}


Please help me with this programming. I only know that you need to create a "Memory" class that implements to MemoryInterface and a "Terminal" class. But i'm confused what to write for the methods.

P.S: I use the Eclipse to code these.

Explanation / Answer

class Memory{

diagram is not there......

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote