Link to home
Start Free TrialLog in
Avatar of professorchaos14
professorchaos14

asked on

Java boolean

I'm trying to figure out how do create a boolean that checks to see if a double is above 0 and a string contains at least one character, if not I have to return a false value. My issue at the moment is displaying whether the string has characters or not.

So far I have:

	public boolean addPartDetails(String partDescription, double partCost) 	//incomplete
	{
		boolean description = false;
		boolean wrongPrice = false;
		
		if (partCost <= 0)
		{
			wrongPrice = true;
		}
		
		if (partDescription )
		{
			
		}
	}

Open in new window

Avatar of SANDY_SK
SANDY_SK
Flag of India image

Check  this
	public boolean addPartDetails(String partDescription, double partCost) 	//incomplete
	{
		boolean description = false;
		boolean wrongPrice = false;
		
		if (partCost <= 0)
		{
			wrongPrice = true;
		}
		
		if (partDescription != null &&  !partDescription.trim().equals(""))
		{
		        description  = true	
		}
	}
                                  

Open in new window

Avatar of Sathish David  Kumar N
if (int(partCost) <= 0)

you cant compare duble like that so convert to int and compare
You can try this as well
public boolean addPartDetails(String partDescription, double partCost){
	boolean description = false;
	boolean wrongPrice = false;
	
	if (partCost <= 0.0){
		wrongPrice = true;
	}
	if (partDescription != null && partDescription.trim().length()>0){
			description  = true;
	}
}

Open in new window


use length method instead of check .equals("").
ASKER CERTIFIED SOLUTION
Avatar of zzynx
zzynx
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanx 4 axxepting