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

JavaProgramming Languages-Other

Avatar of undefined
Last Comment
zzynx

8/22/2022 - Mon
SANDY_SK

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

Sathish David Kumar N

if (int(partCost) <= 0)

you cant compare duble like that so convert to int and compare
yats

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("").
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
ASKER CERTIFIED SOLUTION
zzynx

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
zzynx

Thanx 4 axxepting