Here is my code so far (implements a similar algorithom for Wozmon in java)
import java.util.ArrayList;
import java.util.Scanner;
public class rom {
static ArrayList<Integer> address = new ArrayList<Integer>();
static ArrayList<Integer> old = new ArrayList<Integer>();
static int Address;
@SuppressWarnings("resource")
public static String writeRom(int addr, boolean flag) throws WozmonError {
if (flag == false) {
Scanner data = new Scanner(System.in);
System.out.println("Give data in integer");
int Data = data.nextInt();
old.add(Data);
address.add(addr);
Address = address.indexOf(addr);
return "Address: " + Address + address.toString() + " Data: " + old.get(Address).toString() + old.toString();
} else {
return "Address: " + Address + address.toString() + " Data: " + old.get(Address).toString() + old.toString();
}
}
public static void readRom(int addr /* 0000-65,535 */) throws WozmonError {
if (addr > 65535) {
throw new WozmonError("Wozmon could not find address: " + addr);
} else {
System.out.println(writeRom(addr, true));
// System.out.println("$"+addr+":"+writeRom(addr,true));
}
}
}
When I use the ‘writeRom’ function twice for the same address value, it gives the final output of . Is there a way to edit the writeRom function so that it does not allow duplicate values for the address array (the old array can have duplicates)
5