I've got the following possible addresses as string (not sorted):
"road 21"
"road 1"
"road 186"
"road +21 / 23"
"road +21 / 19"
"another road 21"
"another road 1"
and I want to be able to sort them as (so not on the default String sorting way):
another road 1
another road 21
road 1
road 21
road +21 / 19
road +21 / 23
road 186
How should I do this? I probably have to use a custom comparator, but how should I split the String?
I implemented this in Java and I know it looks weird at first.
If you have any questions feel free to ask me
public class SpecialComparator implements Comparator<String> {
#Override
public int compare(String arg0, String arg1) {
// TODO Auto-generated method stub
String []words1=arg0.split(" ");
String [] words2 = arg1.split(" ");
int i = 0;
if (words1[i].hashCode()>words2[i].hashCode()){
return 1;
}
else if (words1[i].hashCode()<words2[i].hashCode()){
return -1;
}
else if (words1[i].hashCode()==words2[i].hashCode())
return compare(arg0.substring(i+1, arg0.length()), arg1.substring(i+1,arg1.length()));
else if (i == Math.min(words1.length,words2.length)-1 && Math.min(words1.length,words2.length) == words1.length){
return -1;
}
else if (i == Math.min(words1.length,words2.length)-1 && Math.min(words1.length,words2.length) == words2.length){
return 1;
}
else if (i == Math.min(words1.length,words2.length)-1 && words1.length == words2.length){
return 0;
}
else{
return 0;
}
}
public static void main (String[] args){
ArrayList<String> input = new ArrayList<String>();
SpecialComparator a = new SpecialComparator();
input.add("road 21");
input.add("road 1");
input.add("road 186");
input.add("road +21 / 23");
input.add("road +21 / 19");
input.add("another road 21");
input.add("another road 1");
Collections.sort(input,a);
for (String ans : input){
System.out.println(ans);
}
}
}
Your format seems to be :
{name}
{number}
optional slash character
Optional second {number}.
Hence, I would create an object representing this format with those attributes:
public class MyInput {
private String name;
private Integer firstNumber;
private Integer secondNumber;
}
Then parse your input file to create a List<MyInput>.
Finally, you create a custom Comparator can call Collections.sort(yourList, yourCustomComparator)
This issue seems to crop up alot. I have been using Martin Pools NaturalOrderCompartor. You can easily port it into your code.
https://github.com/paour/natorder/blob/master/NaturalOrderComparator.java
it is little bit nasty, but this is my solution for your problem
List<String> list = Arrays.asList("road 21", "road 1", "road 186",
"road +21 / 23", "road +21 / 19", "another road 21",
"another road 1");
Collections.sort(list, new Comparator<String>() {
Integer toNumber(String string) {
try {
return Integer.parseInt(string);
} catch (NumberFormatException e) {
return null;
}
}
#Override
public int compare(String o1, String o2) {
String[] left = o1.split("\\s+");
String[] right = o2.split("\\s+");
for (int i = 0; i < Math.min(left.length, right.length); i++) {
String ls = left[i];
String rs = right[i];
Integer li = toNumber(ls);
Integer ri = toNumber(rs);
if (li != null && ri != null
&& li.intValue() != ri.intValue()) {
return li.intValue() - ri.intValue();
} else if (li != null && ri == null) {
return 1;
} else if (li == null && ri != null) {
return -1;
} else if (li == null && ri == null){
int compared = ls.compareToIgnoreCase(rs);
if (compared != 0) {
return compared;
}
}
}
return left.length - right.length;
}
});
but if you are ok with changing your structure, then go with solution proposed by Arnaud Denoyelle
You can also try following comparator :
class MyComparator implements Comparator<String> {
#Override
public int compare(String o1, String o2) {
o1 = o1.replace("+", "");
o2 = o2.replace("+", "");
String[] a1 = o1.split(" ");
String[] a2 = o2.split(" ");
int length = (a1.length > a2.length) ? a2.length : a1.length;
for (int i = 0; i < length; i++) {
if (!a1[i].equalsIgnoreCase(a2[i])) {
if (!isIntegerRegex(a1[i]) || !isIntegerRegex(a2[i])) {
return o1.compareTo(o2);
}
int f = Integer.parseInt(a1[i]);
int s = Integer.parseInt(a2[i]);
return f - s;
}
}
return a1.length - a2.length;
}
public boolean isIntegerRegex(String str) {
return str.matches("^[0-9]+$");
}
}
And call it:
public String[] sortStrings(String[] input) {
Arrays.sort(input, new MyComparator());
return input;
}
Related
I'm trying to convert multiple strings into one simple dialogue from a NPC. Basically what I'm trying to do is make a list of all the skills a player has 200M experience in and output it into a NPC dialogue.
OLD
if (componentId == OPTION_4) {
sendNPCDialogue(npcId, 9827, "You can prestige: "+maxedSkills()+"");
}
private String maxedSkills() {
return ""+attackMax()+""+strengthMax()+""+defenceMax()+"";
}
public String attackMax() {
if (player.getSkills().getXp(Skills.ATTACK) == 200000000)
return "Attack, ";
else
return "";
}
public String strengthMax() {
if (player.getSkills().getXp(Skills.STRENGTH) == 200000000)
return "Strength, ";
else
return "";
}
public String defenceMax() {
if (player.getSkills().getXp(Skills.DEFENCE) == 200000000)
return "Defence, ";
else
return "";
}
With that code I have it working, but that is a lot of code to add due to there being 25 different skills. How would I create a way to make all of the skills be referenced into one? Here are all of the skill names:
public static final String[] SKILL_NAME = { "Attack", "Defence", "Strength", "Constitution", "Ranged", "Prayer",
"Magic", "Cooking", "Woodcutting", "Fletching", "Fishing", "Firemaking", "Crafting", "Smithing", "Mining",
"Herblore", "Agility", "Thieving", "Slayer", "Farming", "Runecrafting", "Hunter", "Construction",
"Summoning", "Dungeoneering" };
New and working (for attack/strength/defence):
public static final int[] SKILL_TYPE = {Skills.ATTACK, Skills.STRENGTH, Skills.DEFENCE};
public String maxedSkills() {
StringBuffer sb = new StringBuffer();
for(int i = 0; i < SKILL_TYPE.length; i++) {
if (player.getSkills().getXp(i) == 200000000) {
if(sb.length()>0) sb.append(", ");
sb.append(Skills.SKILL_NAME[i]);
}
}
if(sb.length()>0) sb.append(".");
return sb.toString();
}
Simplest way would be to have a parameteried method that takes the Skill type as input. Here is how it would look like:
public String skillMax(Skills skill) {
if (player.getSkills().getXp(skill) == 200000000)
return skill.getName() + ", ";
else
return "";
}
The next thing to do is to provide a name to the skill in Skills enum. Something like this should work:
public enum Skills {
DEFENSE("Defense"), ...;
private String name;
Skills(String name) { this.name = name; }
String getName() { return this.name; }
}
Use a StringBuffer (thread safe) or a StringBuilder and do something like this.
....
public static final Skills[] SKILL_TYPE = {Skills.Attack, Skills.Defence, ...};
public String getBigString() {
StringBuffer sb = new StringBuffer();
int nSkills = 0, lSkill = 0;
for( int i = 0; i < SKILL_TYPE.length; i++ )
{
if( player.getSkills().getXp(SKILL_TYPE[i]) == K_SOMELEVEL ) {
if(nSkills > 0) sb.append(", ");
lSkill = sb.length(); // track position of last skill in string
nSkills += 1;
sb.append(SKILL_NAME[i]);
}
}
if( nSkills > 0 )
{
if( nSkills > 1 ) sb.insert( lSkill, "and ");
sb.append(".");
}
return sb.toString();
}
I have a string of: "9AM-5PM"
I would like to subtract these two numbers and find the difference in hours.
int intervalHours(String input) {
String[] ts = input.split("-"); // {"9AM", "5PM"}
return toHours(ts[1]) - toHours(ts[0]);
}
int toHours(String t) {
int h = Integer.parseInt(t.substring(0, t.length() - 2));
if (t.endsWith("PM"))
return h == 12 ? 12 : (h + 12);
else
return h == 12 ? 0 : h;
}
// ...
System.out.println(intervalHours("9AM-5PM"));
public void time()
{
String t="12AM-5PM";``
StringTokenizer st=new StringTokenizer(t,"-");
String initialTime=st.nextToken();
String finalTime=st.nextToken();
int t1=0;
int t2=0;
if(initialTime.contains("AM"))
{
t1=Integer.valueOf(initialTime.replace("AM",""));
}
else
{
t1=Integer.valueOf(initialTime.replace("PM",""))+12;
}
if(finalTime.contains("AM"))
{
t2=Integer.valueOf(finalTime.replace("AM",""));
}
else
{
t2=Integer.valueOf(finalTime.replace("PM",""))+12;
}
System.out.println(t2-t1);
}
This question already has answers here:
Comparing version number strings (major, minor, revision, beta)
(3 answers)
Closed 7 years ago.
For one of my projects i would like to get a version from a string which has multiple decimals, is it possible to convert it into a multi decimal point double or is it not possible. I would like to use this to see if it is more than the previous one, which would also have multiple decimals.
What I am using at the moment is
if (!vers.equalsIgnoreCase(plugin.getDescription().getVersion())) { // Do stuff
But I would like to make it so I can do
if (vers > plugin.getDescription().getVersion()) { // do stuff
vers is equal to 1.0.1, and the plugin.getDescription().getVersion() is equal to 1.0.2
thanks!
You could implement this way, if you assume all the portions are numbers.
public static int compareVersions(String vers1, String vers2) {
String[] v1 = vers1.split("\\.");
String[] v2 = vers2.split("\\.");
for (int i = 0; i < v1.length && i < v2.length; i++) {
int i1 = Integer.parseInt(v1[i]);
int i2 = Integer.parseInt(v2[i]);
int cmp = Integer.compare(i1, i2);
if (cmp != 0)
return cmp;
}
return Integer.compare(v1.length, v2.length);
}
and
System.out.println(compareVersions("1.0.1", "1.0.2"));
System.out.println(compareVersions("1.0.1", "1.0"));
System.out.println(compareVersions("1.0.2", "1.0.10"));
prints
-1
1
-1
A more complex version supports letters inside versions
public static int compareVersions(String vers1, String vers2) {
String[] v1 = vers1.split("\\.");
String[] v2 = vers2.split("\\.");
for (int i = 0; i < v1.length && i < v2.length; i++) {
String [] w1 = v1[i].split("(?<=\\D)(?=\\d)|(?<=\\d)(?=\\D)");
String [] w2 = v2[i].split("(?<=\\D)(?=\\d)|(?<=\\d)(?=\\D)");
for(int j=0;j<w1.length&&j<w2.length;j++) {
try {
int i1 = Integer.parseInt(w1[j]);
int i2 = 0;
try {
i2 = Integer.parseInt(w2[j]);
} catch (NumberFormatException e) {
return -1;
}
int cmp = Integer.compare(i1, i2);
if (cmp != 0)
return cmp;
} catch (NumberFormatException e) {
try {
Integer.parseInt(w2[j]);
return +1;
} catch (NumberFormatException e1) {
int cmp = w1[j].compareTo(w2[j]);
if (cmp != 0)
return cmp;
}
}
}
int cmp = Integer.compare(w1.length, w2.length);
if (cmp != 0)
return cmp;
}
return Integer.compare(v1.length, v2.length);
}
and
System.out.println(compareVersions("1.0.2", "1.0.2a"));
System.out.println(compareVersions("1.0.2b", "1.0.2a"));
System.out.println(compareVersions("1.8.0_66", "1.8.0_65"));
System.out.println(compareVersions("1.7.0_79", "1.8.0_65"));
prints
-1
1
1
-1
It seems that you would like to compare versions. Or to take decisions based on some string represented version. If the plugin.getDescription().getVersion() is a String, then you should be able to use a simple String comparison to establish the order between versions. Something like this should work:
String pluginVersion=plugin.getDescription().getVersion();
if (ensureValidVersion(pluginVersion)
&& compareVersions(vers,pluginVersion)>0) {
// do staff is vers is greater then plugin version
}
ensureValidVersion method will validate if you have a valid version number representation. And compareVersions will do a comparison for each version subcomponent.
Assuming you have a version number of the following form: x.y.z
You can use a similiar approach as suggested by Viacheslav Vedenin:
String versionNumber = "1.3.45";
String[] singleParts = versionNumbers.split(".");
int[] versionParts = new int[singleParts.length];
for(int i=0; i<singleParts.length; i++) {
versionParts[i] = Integer.parseInt(singleParts[i]);
}
Now you have an array of the single parts of your version number. To compare it to a previous one you could do as follow:
public static boolean isGreater(int[] firstVersion, int[] secondVersion) {
if(secondVersion.length > firstVersion.length) {
return false;
}else {
if(firstVersion.length > secondVersion.length) {
return true;
}else {
for(int k=0; k< firstVersion.length; k++) {
int v1 = firstVersion[k];
int v2 = secondVersion[k];
if(v1 < v2) {
return true;
}
}
return false;
}
}
}
If you want to compare versions using the equality/inequality operators (==, <, >, <=, and >=), you have two options.
Use a language like C++ that supports operator overloading
Set a limit on the length for each string in major.minor.build and convert each version to an integer before comparing them. For example, if the limit on each of them is 3 (i.e. the longest version you can have is abc.def.ghi), then you can just use build + minor * 10^3 + major * 10^6.
Alternatively, you can just implement Comparable<Version> and have a nice OOP solution.
public class Example {
static class Version implements Comparable<Version> {
private int major;
private int minor;
private int build;
public Version(String s) {
final String[] split = s.split("\\.");
major = Integer.parseInt(split[0]);
minor = Integer.parseInt(split[1]);
build = Integer.parseInt(split[2]);
}
public int getMajor() {
return major;
}
public int getMinor() {
return minor;
}
public int getBuild() {
return build;
}
#Override
public int compareTo(Version v) {
if (getMajor() < v.getMajor()) {
return -1;
} else if (getMajor() > v.getMajor()) {
return 1;
} else {
if (getMinor() < v.getMinor()) {
return -1;
} else if (getMinor() > v.getMinor()) {
return 1;
} else {
if (getBuild() < v.getBuild()) {
return -1;
} else if (getBuild() > v.getBuild()) {
return 1;
} else {
return 0;
}
}
}
}
}
public static void main(String[] args) {
String s1 = "1.0.1";
String s2 = "1.0.2";
compare(s1, s2);
compare(s1, s1);
compare(s2, s2);
compare(s2, s1);
}
private static void compare(String s1, String s2) {
Version v1 = new Version(s1);
Version v2 = new Version(s2);
final int compareTo = v1.compareTo(v2);
if (compareTo == -1) {
System.out.println(s1 + " was released before " + s2);
} else if (compareTo == 0) {
System.out.println(s1 + " is the same as " + s2);
} else {
System.out.println(s1 + " was released after " + s2);
}
}
}
Output:
1.0.1 was released before 1.0.2
1.0.1 is the same as 1.0.1
1.0.2 is the same as 1.0.2
1.0.2 was released after 1.0.1
String[] numbers = version.split(".");
String[] numbers2 = version2.split(".");
int index = numbers.length-1;
while(numbers[index] != "."){
index--;
}
String lastnumber = version.substring(index+1, numbers.length];
index = numbers2.length-1;
while(numbers2[index] != "."){
index--;
}
String lastnumber2 = version.substring(index+1, numbers2.length];
if(lastnumber > lastnumber2){
//later version
}else{
//use the same thing to check the other numbers
}
This portion of my program seems to be giving me a problem:
public static double[] getBonusAmt(boolean[] bonusEligibility, int[] numYrsFlown, double[] bonusAmt) {
bonusAmt = new double[bonusEligibility.length];
double bonus = 0;
for (boolean b : bonusEligibility) {
for (int i : numYrsFlown) {
if (i >= 9 && b == true) {
bonus = 2410.00;
}
else if (i < 9 && i >= 6 && b == true) {
bonus = 1206.00;
}
else if (i < 6 && i >= 2 && b == true) {
bonus = 515.00;
}
else if (i < 2 && b == true) {
bonus = 0.00;
}
}
}
return bonusAmt;
}
Input/Output:
Name: [joe, james]
Years flown: [2, 2]
Miles flown: [45, 43]
Average miles between pilots: 44
Bonus eligibility: [true, false]
Bonus amount: [0.00, 0.00]
Joe should be earning a bonus because his miles flown is greater than the average, but his amount is zero. The expected bonus amount for Joe should be 515.00 because one, he is eligible for a bonus and two, has only flown for 2 years.
Can anyone see why the bonus amount is always zero even if I enter another person that has flown more than the average?
Your method assigns values to the bonus variable but returns a bonusAmt variable, which is never assigned, so its values remain 0.0.
Your nested loops don't make much sense. It looks like you need a single regular for loop, assuming that the i'th index of bonusEligibility array corresponds with the i'th index of the numYrsFlown array.
public static double[] getBonusAmt(boolean[] bonusEligibility, int[] numYrsFlown) {
double[] bonusAmt = new double[bonusEligibility.length];
for (int i = 0; i < bonusEligibility.length; i++) {
if (numYrsFlown[i] >= 9 && bonusEligibility[i]) {
bonus = 2410.00;
}
else if (numYrsFlown[i] < 9 && numYrsFlown[i] >= 6 && bonusEligibility[i]) {
bonusAmt[i] = 1206.00;
}
else if (numYrsFlown[i] < 6 && numYrsFlown[i] >= 2 && bonusEligibility[i]) {
bonusAmt[i] = 515.00;
}
else if (numYrsFlown[i] < 2 && bonusEligibility[i]) {
bonusAmt[i] = 0.00;
}
}
return bonusAmt;
}
BTW, there's no point in passing the bonusAmt array as an argument to the method, since the method assigns to it a reference to a new array.
You forgot to set bonusAmt to the selected bonus value.
Here is a more object oriented way to do what you want. No need to accept this answer as Eran's solution explains your error perfectly ... This is just another way of doing it ...
public class MainApp {
public static void main(String[] args) {
AirMilesCustomer[] customers = new AirMilesCustomer[] {
new AirMilesCustomer("John", true, 2),
new AirMilesCustomer("Jane", true, 5),
new AirMilesCustomer("Sally", true, 7),
new AirMilesCustomer("Bill", false, 10),
new AirMilesCustomer("Stacy", true, 15)
};
for(AirMilesCustomer customer : customers) {
System.out.println(customer);
}
}
}
class AirMilesCustomer {
private String _name;
private boolean _bonusEligibility;
private int _numYrsFlown;
public AirMilesCustomer(String name, boolean bonusEligibility, int numYrsFlown) {
_name = name;
_bonusEligibility = bonusEligibility;
_numYrsFlown = numYrsFlown;
}
public String getName() {
return _name;
}
public boolean isBonusEligibility() {
return _bonusEligibility;
}
public int getNumYrsFlown() {
return _numYrsFlown;
}
public double getBonusAmount() {
double bonus = 0.00;
if (_numYrsFlown >= 9 && _bonusEligibility) {
bonus = 2410.00;
}
else if (_numYrsFlown < 9 && _numYrsFlown >= 6 && _bonusEligibility) {
bonus = 1206.00;
}
else if (_numYrsFlown < 6 && _numYrsFlown >= 2 && _bonusEligibility) {
bonus = 515.00;
}
else if (_numYrsFlown < 2 && _bonusEligibility) {
bonus = 0.00;
}
return bonus;
}
public String toString() {
return "[" + _name + "][" + _numYrsFlown + "][" + _bonusEligibility + "][" + getBonusAmount() + "]";
}
}
I'm trying to make a 2d array of an object in java. This object in java has several private variables and methods in it, but won't work. Can someone tell me why and is there a way I can fix this?
This is the exeception I keep getting for each line of code where I try to initialize and iterate through my 2d object.
"Exception in thread "main" java.lang.NullPointerException
at wumpusworld.WumpusWorldGame.main(WumpusWorldGame.java:50)
Java Result: 1"
Here is my main class:
public class WumpusWorldGame {
class Agent {
private boolean safe;
private boolean stench;
private boolean breeze;
public Agent() {
safe = false;
stench = false;
breeze = false;
}
}
/**
* #param args
* the command line arguments
* #throws java.lang.Exception
*/
public static void main(String [] args) {
// WumpusFrame blah =new WumpusFrame();
// blah.setVisible(true);
Scanner input = new Scanner(System.in);
int agentpts = 0;
System.out.println("Welcome to Wumpus World!\n ******************************************** \n");
//ArrayList<ArrayList<WumpusWorld>> woah = new ArrayList<ArrayList<WumpusWorld>>();
for (int i = 0 ; i < 5 ; i++) {
WumpusWorldObject [] [] woah = new WumpusWorldObject [5] [5];
System.out.println( "*********************************\n Please enter the exact coordinates of the wumpus (r and c).");
int wumpusR = input.nextInt();
int wumpusC = input.nextInt();
woah[wumpusR][wumpusC].setPoints(-3000);
woah[wumpusR][wumpusC].setWumpus();
if ((wumpusR <= 5 || wumpusC <= 5) && (wumpusR >= 0 || wumpusC >= 0)) {
woah[wumpusR][wumpusC].setStench();
}
if (wumpusC != 0) {
woah[wumpusR][wumpusC - 1].getStench();
}
if (wumpusR != 0) {
woah[wumpusR - 1][wumpusC].setStench();
}
if (wumpusC != 4) {
woah[wumpusR][wumpusC + 1].setStench();
}
if (wumpusR != 4) {
woah[wumpusR + 1][wumpusC].setStench();
}
System.out.println( "**************************************\n Please enter the exact coordinates of the Gold(r and c).");
int goldR = input.nextInt();
int goldC = input.nextInt();
woah[goldR][goldC].setGold();
System.out.println("***************************************\n How many pits would you like in your wumpus world?");
int numPits = input.nextInt();
for (int k = 0 ; k < numPits ; k++) {
System.out.println("Enter the row location of the pit");
int r = input.nextInt();
System.out.println("Enter the column location of the pit");
int c = input.nextInt();
woah[r][c].setPit();
if ((r <= 4 || c <= 4) && (r >= 0 || c >= 0)) {
woah[r][c].setBreeze();
}
if (c != 0) {
woah[r][c - 1].setBreeze();
}
if (r != 0) {
woah[r - 1][c].setBreeze();
}
if (c != 4) {
woah[r][c + 1].setBreeze();
}
if (r != 4) {
woah[r + 1][c].setBreeze();
}
}
for (int x = 0 ; x < 4 ; x++) {
int j = 0;
while (j < 4) {
agentpts = agentpts + woah[x][j].getPoints();
Agent [] [] k = new Agent [4] [4];
if (woah[x][j].getWumpus() == true) {
agentpts = agentpts + woah[x][j].getPoints();
System.out.println("You just got ate by the wumpus!!! THE HORROR!! Your score is " + agentpts);
}
if (woah[x][j].getStench() == true) {
k[x][j].stench = true;
System.out.println("You smell something funny... smells like old person.");
}
if (woah[x][j].getBreeze() == true) {
k[x][j].breeze = true;
System.out.println("You hear a breeze. yeah");
}
if (woah[x][j].getPit() == true) {
agentpts = agentpts + woah[x][j].getPoints();
System.out.println("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAH! you dumb bith, your dead now.");
}
// if breeze or stench, if breeze and stench, if nothing, etc then move.
k[x][j].safe = true;
// if(k[i][j].isSafe()!=true){
// } else { }
}
}
}
}
}
Here is my class object that I'm trying to implement:
package wumpusworld;
/**
*
* #author Jacob
*/
public class WumpusWorldObject {
private boolean stench;
private boolean breeze;
private boolean pit;
private boolean wumpus;
private boolean gold;
private int points;
private boolean safe;
public WumpusWorldObject(){
}
public boolean getPit() {
return pit;
}
public void setPit() {
this.pit = true;
}
public boolean getWumpus() {
return wumpus;
}
public void setWumpus() {
this.wumpus = true;
}
public int getPoints() {
return points;
}
public void setPoints(int points) {
this.points = points;
}
public boolean getStench() {
return stench;
}
public void setStench() {
this.stench = true;
}
public boolean getBreeze() {
return breeze;
}
public void setBreeze() {
this.breeze = true;
}
public boolean getSafe() {
return safe;
}
public void setSafe() {
this.safe = true;
}
public void setGold(){
this.gold=true;
}
}
Creating array doesn't mean it will be automatically filled with new instances of your class. There are many reasons for that, like
which constructor should be used
what data should be passed to this constructor.
This kind of decisions shouldn't be made by compiler, but by programmer, so you need to invoke constructor explicitly.
After creating array iterate over it and fill it with new instances of your class.
for (int i=0; i<yourArray.length; i++)
for (int j=0; j<yourArray[i].length; j++)
yourArray[i][j] = new ...//here you should use constructor
AClass[][] obj = new AClass[50][50];
is not enough, you have to create instances of them like
obj[i][j] = new AClass(...);
In your code the line
woah[wumpusR][wumpusC].setPoints(-3000);
must be after
woah[wumpusR][wumpusC] = new WumpusWorldObject();
.