473,473 Members | 2,008 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

null if evaluation

hello,
i'm working on a project searching through a list of arrays based on
user input. the problem is that if a user does not define a certain
variable, my if statement will not evaluate. i need a way to tell the
if statement to skip over a certain evaluation if the value is null.

if ((House[i][1] == beds) && (House[i][2] == baths)) {
statments
}

if someone doesn't define # of beds, how do i skip that evaluation?
thanks!

bryce
Jul 17 '05 #1
2 4253
It sounds like you're running into problems because you're not using
good OO design. Instead of using a two dimensional array, you should
use an array of House objects:

public class House {
private int numberBeds;
private int numberBaths;

public House(int numberBeds, int numberBaths) {
this.numberBeds = numberBeds;
this.numberBaths = numberBaths;
}
public int getNumberBeds() { return numberBeds; }
public int getNumberBaths() { return numberBaths; }
}

Then, you wouldn't have to worry about the second dimension of your
array being defined or not:

//Assume houseArray is of type House
if ( houseArray[i].getNumberBeds == beds &&
houseArray[i].getNumberBaths == baths ) {
//Do stuff here.
}

Hope this helps.

//Nathan

ho***********@hotmail.com (Bryce Maschino) wrote in message news:<3b*************************@posting.google.c om>...
hello,
i'm working on a project searching through a list of arrays based on
user input. the problem is that if a user does not define a certain
variable, my if statement will not evaluate. i need a way to tell the
if statement to skip over a certain evaluation if the value is null.

if ((House[i][1] == beds) && (House[i][2] == baths)) {
statments
}

if someone doesn't define # of beds, how do i skip that evaluation?
thanks!

bryce

Jul 17 '05 #2
Bryce,

I agree Nathan, but maybe you can not do it now (a good OO design
must be done at beginning). So, you can "to fix" your code, trying it:

if ( (House[i][1] != null) && (House[i][1] == beds) && (House[i][2] ==
baths)) {
statments
}
It works because shortcut conditional (it means the expression will
not be checked until end. The JVM verifies the conditions, one by one
(left to right), until the expression becomes false (with AND
operator) or true (with OR operator).
The same thing if you wanna check baths.
But, remember what Nathan told about OO design...
na*****@hotmail.com (Nathan Zumwalt) wrote in message news:<52**************************@posting.google. com>...
It sounds like you're running into problems because you're not using
good OO design. Instead of using a two dimensional array, you should
use an array of House objects:

public class House {
private int numberBeds;
private int numberBaths;

public House(int numberBeds, int numberBaths) {
this.numberBeds = numberBeds;
this.numberBaths = numberBaths;
}
public int getNumberBeds() { return numberBeds; }
public int getNumberBaths() { return numberBaths; }
}

Then, you wouldn't have to worry about the second dimension of your
array being defined or not:

//Assume houseArray is of type House
if ( houseArray[i].getNumberBeds == beds &&
houseArray[i].getNumberBaths == baths ) {
//Do stuff here.
}

Hope this helps.

//Nathan

ho***********@hotmail.com (Bryce Maschino) wrote in message news:<3b*************************@posting.google.c om>...
hello,
i'm working on a project searching through a list of arrays based on
user input. the problem is that if a user does not define a certain
variable, my if statement will not evaluate. i need a way to tell the
if statement to skip over a certain evaluation if the value is null.

if ((House[i][1] == beds) && (House[i][2] == baths)) {
statments
}

if someone doesn't define # of beds, how do i skip that evaluation?
thanks!

bryce

Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: TJS | last post by:
how to check for null attribute in form input field using IE this does not work in IE var curr_id = tablecells.getAttribute('name'); if (curr_id != null){ .... }
9
by: ken | last post by:
Hi, I was wondering when you have an empty cell, its value is null in the debugger. So when you have an expression like this: "if len(mycell) < 1 then", or if you have "if mycell = null then" I...
18
by: Serve La | last post by:
C programmers get accused of writing platform dependant code when they write int *x = 0; They have to write int *x = NULL; because some platforms don't represent NULL as all bits zero. C++...
2
by: Marshall Belew | last post by:
My stack trace contains: System.NullReferenceException: Object reference not set to an instance of an object. but the line of code it refers to looks like this: if (null == unit || !...
5
by: Brian Keating | last post by:
Hi there, Just wondering what is the correct way of implementing the comparison operator in c# operator== My problem is when one or more of the objects is null, I've cast to object to try...
1
by: A_StClaire_ | last post by:
hi, I have a singleton class called 'Evaluation' which is a utility class used to determine the strength of a poker hand. two members of 'Evaluation' are highCard and lowCard, two objects of...
69
by: fieldfallow | last post by:
Hello all, Before stating my question, I should mention that I'm fairly new to C. Now, I attempted a small demo that prints out the values of C's numeric types, both uninitialised and after...
2
by: krismath | last post by:
I am unable to have the "null" value working for the validation of the text field. The code is able to validate if the sid value is having one,two,three spaces....but not more..it is sloppy...
54
by: Rasjid | last post by:
Hello, I have just joined and this is my first post. I have never been able to resolve the issue of order of evaluation in C/C++ and the related issue of precedence of operators, use of...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
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...
1
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...
0
agi2029
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,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.