hi
i have a 2 dimensional array where im trying to create an object (territory) in an if statement when the array is searched and when a certain number is found eg [0][0] a territory is created and placed there?
so far i have writen a few lines but im stumped on creating the object? any help would be create thanks
private Territory[][] createTerritories()
{
final int _ = -1;
final int[][] map = { { _, _, _, _, _, _, _, _, _, _, _, _, _, _ },
{ _, _, _, _, 0, 0, _, _, _, _, 2, _, _, _ },
{ 0, 0, 0, 0, 0, 0, _, 2, 2, 2, 2, 2, 2, 2 },
{ _, 0, 0, 0, _, _, _, 2, 2, 2, 2, 2, _, _ },
{ _, _, 0, 0, _, _, 2, _, 2, 2, 2, 2, _, _ },
{ _, _, 0, _, _, _, 3, 3, 2, 2, 2, _, _, _ },
{ _, _, _, 1, 1, _, 3, 3, 3, _, _, 4, _, _ },
{ _, _, _, 1, 1, _, _, 3, 3, _, _, 4, 4, _ },
{ _, _, _, 1, 1, _, _, 3, _, _, _, 4, 4, _ },
{ _, _, _, _, 1, _, _, _, _, _, _, _, _, _ } };
Territory[][] territories = new Territory[TERRITORY_ROWS][TERRITORY_COLS];
for (int row = 0; row < TERRITORY_ROWS; row++)
{
for (int col = 0; col < TERRITORY_COLS; col++)
{
if (int[row][col] map = 0;)
????
1 1527
hi
i have a 2 dimensional array where im trying to create an object (territory) in an if statement when the array is searched and when a certain number is found eg [0][0] a territory is created and placed there?
so far i have writen a few lines but im stumped on creating the object? any help would be create thanks
private Territory[][] createTerritories()
{
final int _ = -1;
final int[][] map = { { _, _, _, _, _, _, _, _, _, _, _, _, _, _ },
{ _, _, _, _, 0, 0, _, _, _, _, 2, _, _, _ },
{ 0, 0, 0, 0, 0, 0, _, 2, 2, 2, 2, 2, 2, 2 },
{ _, 0, 0, 0, _, _, _, 2, 2, 2, 2, 2, _, _ },
{ _, _, 0, 0, _, _, 2, _, 2, 2, 2, 2, _, _ },
{ _, _, 0, _, _, _, 3, 3, 2, 2, 2, _, _, _ },
{ _, _, _, 1, 1, _, 3, 3, 3, _, _, 4, _, _ },
{ _, _, _, 1, 1, _, _, 3, 3, _, _, 4, 4, _ },
{ _, _, _, 1, 1, _, _, 3, _, _, _, 4, 4, _ },
{ _, _, _, _, 1, _, _, _, _, _, _, _, _, _ } };
Territory[][] territories = new Territory[TERRITORY_ROWS][TERRITORY_COLS];
for (int row = 0; row < TERRITORY_ROWS; row++)
{
for (int col = 0; col < TERRITORY_COLS; col++)
{
if (int[row][col] map = 0;)
????
The syntax of that last if statment doesn't make any sense. Better use a switch
statement here like this: -
switch (map[row][col]) {
-
case 0: territories[row][col]= ...; break;
-
case 1: territories[row][col]= ...; break;
-
...
-
}
-
kind regards,
Jos
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Sree |
last post by:
If class B derives from class A and we create an array of class B like
B *arrayOfB = new B; and
// Instance of A
A firstInstanceOfA;
How can we store firstInstanceOfA in arrayOfB ? I tried the...
|
by: Brett Kelly |
last post by:
Sorry, for the somewhat confusing subject, but my problem is equally
odd (imo).
So, I have an assembly that contains an abstract class (File) and 5
other classes that all subclass it (Exe, Dll,...
|
by: Dan A |
last post by:
I have a SOAP written in Java, and being served by Apache Axis - using the
wrapped mode. I then used VS 2003 to generate C# client stubs.
I have many complex types that are returned - and these...
|
by: ryoung |
last post by:
I receive the following error when I attempt to assign values to a web
service array.
Exception Details: System.NullReferenceException: Object reference not
set to an instance of an object.
...
|
by: AZRebelCowgirl73 |
last post by:
here is the instructiions I am to use
Ask the user to input the number of effective cars in the shop (this number should be between 1 and 100, inclusively). In a loop, controlled by the inputted...
|
by: sammyboy78 |
last post by:
I'm trying to display my array of objects in a GUI. How do I get JLabel to refer to the data in my objects? I've read my textbook and some tutorials online I just cannot get this. Plus all the...
|
by: getmeidea |
last post by:
Hi,
I am using JDK 1.5.
I have a program like this. Here i am directly assigning value to one object.
It does'nt give me any compile time or run time error. In java we dont have access to any...
|
by: miken32 |
last post by:
In PHP, if a function returns an array it's fairly common to capture
its return values like this:
<?php
list($foo, $bar, $baz) = some_function_that_return_an_array();
?>
In Javascript, would...
|
by: stevedub |
last post by:
I am having some trouble configuring my array to read from a sequential file, and then calling on that to fill an array of interests. I think I have the class set up to read the file, but when I run...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |